-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite validate_domain_name() as a Puppet 4.x function
The 3.x function rely on is_domain_name() which is deprecated. Rewrite it using the more modern puppet 4.x function to rely on data types for better parameters validation. While here, adjust the Stdlib::Fqdn data type to ensure the last component (TLD) is non-numeric as [suggested by @ekohl](#1282 (comment)), and add a Stdlib::Dns_zone data type that is basically the same but with a trailing dot.
- Loading branch information
Showing
7 changed files
with
101 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
# @summary | ||
# Validate that all values passed are syntactically correct domain names. | ||
# Fail compilation if any value fails this check. | ||
Puppet::Functions.create_function(:validate_domain_name) do | ||
# @param values A domain name or an array of domain names to check | ||
# | ||
# @return [Undef] | ||
# passes when the given values are syntactically correct domain names or raise an error when they are not and fails compilation | ||
# | ||
# @example Passing examples | ||
# $my_domain_name = 'server.domain.tld' | ||
# validate_domain_name($my_domain_name) | ||
# validate_domain_name('domain.tld', 'puppet.com', $my_domain_name) | ||
# validate_domain_name('www.example.2com') | ||
# | ||
# @example Failing examples (causing compilation to abort) | ||
# validate_domain_name(1) | ||
# validate_domain_name(true) | ||
# validate_domain_name('invalid domain') | ||
# validate_domain_name('-foo.example.com') | ||
dispatch :validate_domain_name do | ||
repeated_param 'Variant[Stdlib::Fqdn, Stdlib::Dns::Zone]', :values | ||
end | ||
|
||
def validate_domain_name(*_values); end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'Stdlib::Dns::Zone' do | ||
describe 'accepts dns zones' do | ||
[ | ||
'.', | ||
'com.', | ||
'example.com.', | ||
'10.10.10.10.10.', | ||
'xn--5ea.pf.', | ||
].each do |value| | ||
describe value.inspect do | ||
it { is_expected.to allow_value(value) } | ||
end | ||
end | ||
end | ||
|
||
describe 'rejects other values' do | ||
[ | ||
true, | ||
false, | ||
'', | ||
'iAmAString', | ||
{}, | ||
{ 'key' => 'value' }, | ||
{ 1 => 2 }, | ||
:undef, | ||
3, | ||
'www..com.', | ||
'127.0.0.1', | ||
].each do |value| | ||
describe value.inspect do | ||
it { is_expected.not_to allow_value(value) } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# @summary Validate a DNS zone name | ||
type Stdlib::Dns::Zone = Pattern[/\A((([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)+|\.)\z/] |