Skip to content

Commit

Permalink
split_txt: add method to split txt records as per RFC 4408
Browse files Browse the repository at this point in the history
  • Loading branch information
b4ldr committed Jan 28, 2025
1 parent 1a22de1 commit 8383c92
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
### Functions

* [`unbound::print_config`](#unbound--print_config): Print a configuration value if it is defined and the version is supported
* [`unbound::split_txt`](#unbound--split_txt): function to split TXT records. Long TXT records must be broken into strings of 255 characters as per RFC 4408

### Data types

Expand Down Expand Up @@ -2567,6 +2568,24 @@ Data type: `Optional[String[1]]`

the version when the config item was introduced

### <a name="unbound--split_txt"></a>`unbound::split_txt`

Type: Puppet Language

function to split TXT records. Long TXT records must be broken into strings of 255 characters as per RFC 4408

#### `unbound::split_txt(String[1] $data)`

The unbound::split_txt function.

Returns: `String[1]` A string of 255 character strings

##### `data`

Data type: `String[1]`

A TXT record to split

## Data types

### <a name="Unbound--Access_control"></a>`Unbound::Access_control`
Expand Down
8 changes: 8 additions & 0 deletions functions/split_txt.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# @summary function to split TXT records. Long TXT records must be broken into strings of 255 characters as per RFC 4408
# @param data A TXT record to split
# @return A string of 255 character strings
function unbound::split_txt(
String[1] $data
) >> String[1] {
$data.slice(255).map |$slice| { "\"${slice.join}\"" }.join
}
9 changes: 9 additions & 0 deletions spec/functions/split_txt_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require 'spec_helper'
input = "Long TXT Record #{'X' * 255}"
output = "\"Long TXT Record #{'X' * 239}\"\"#{'X' * 16}\""

describe 'unbound::split_txt' do
it { is_expected.to run.with_params(input).and_return(output) }
end

0 comments on commit 8383c92

Please sign in to comment.