-
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
6 changed files
with
83 additions
and
63 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 | ||
# 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) | ||
# | ||
# @exapmle 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') | ||
# validate_domain_name('www.example.2com') | ||
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.', | ||
].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, | ||
'2com.', | ||
'com2.', | ||
'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
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((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)*[[:alpha:]]+\.|\.)\z/] |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# @summary Validate a Fully Qualified Domain Name | ||
type Stdlib::Fqdn = Pattern[/\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/] | ||
type Stdlib::Fqdn = Pattern[/\A((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)*[[:alpha:]]+)\z/] |