-
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
migrate away from erb #357
base: master
Are you sure you want to change the base?
Changes from all commits
f973fec
3f09439
541b602
c2a89ff
c270c7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# @summary Remove blank lines from a string | ||
# @param content The content to remove blank lines from | ||
# @return The content with blank lines removed | ||
function unbound::clean_blank_lines ( | ||
String[1] $content, | ||
) >> String[1] { | ||
return $content.split("\n").filter |$x| { !$x.empty }.join("\n") | ||
} |
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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,15 +26,34 @@ | |
# @param template_name Use a custom template. | ||
# | ||
define unbound::localzone ( | ||
Unbound::Local_zone_type $type, | ||
String $zone = $name, | ||
$config_file = $unbound::config_file, | ||
Array[Unbound::Resource_record_type] $local_data = [], | ||
String $template_name = 'unbound/local_zone.erb' | ||
Unbound::Local_zone_type $type, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer the older style, with just a single whitespace. That makes the diff easier to read and makes git reverts / cherry-picks easier. But there's no consent in our style guide yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hear you but the rest of this module uses this style and I prefer consistency. But consistency across viz would be great so let's try and get something in the style guide and then we can creat a puppet lint check and fix to get everything fixed? |
||
String $zone = $name, | ||
Stdlib::Absolutepath $config_file = $unbound::config_file, | ||
String $template_name = 'unbound/local_zone.erb', | ||
Array[Unbound::Resource_record_type] $local_data = [], | ||
) { | ||
# Loop through the local_data hash and create ablock of local-data strings with the correctly formated | ||
# local-data lines which are ued in the final content block below. | ||
# local-data: 'api.test.com 15 300 IN A 192.0.2.1 | ||
$records = $local_data.map |$record| { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's a lot going on here. Can you please add some comments about what's happening? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair comment will do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated let me know what's missing? |
||
$data = $record['data'] | ||
$_data = $record['type'] ? { | ||
'TXT' => $data.unbound::split_txt(), | ||
default => $data, | ||
} | ||
$record_txt = "${record['name']} ${record['ttl']} ${record['class']} ${record['type']} ${_data}".regsubst( | ||
/\s+/, ' ', 'G' | ||
) # Remove multiple spaces | ||
" local-data: '${record_txt}'" | ||
}.join("\n") | ||
$content = @("CONTENT") | ||
server: | ||
local-zone: "${zone}" ${type} | ||
${records} | ||
| CONTENT | ||
concat::fragment { "unbound-localzone-${name}": | ||
order => '06', | ||
target => $config_file, | ||
content => template($template_name), | ||
content => $content, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
input = <<-TEXT | ||
string_name: "string_value" | ||
|
||
int_name: 42 | ||
|
||
true_name: yes | ||
TEXT | ||
output = <<-TEXT | ||
string_name: "string_value" | ||
int_name: 42 | ||
true_name: yes | ||
TEXT | ||
|
||
describe 'unbound::clean_blank_lines' do | ||
it { is_expected.to run.with_params(input).and_return(output) } | ||
end |
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 |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is generic enough that it could also be part of extlib?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
voxpupuli/puppet-extlib#239