Skip to content

Commit

Permalink
Merge pull request #220 from b4ldr/morden_api
Browse files Browse the repository at this point in the history
validate_unbond_addr: replace functionality with a custom type
  • Loading branch information
zachfi committed Jan 22, 2020
2 parents ef982ce + 9909d91 commit 5868593
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 188 deletions.
11 changes: 0 additions & 11 deletions lib/puppet/parser/functions/validate_unbound_addr.rb

This file was deleted.

51 changes: 0 additions & 51 deletions lib/puppet_x/unbound/validate_addrs.rb

This file was deleted.

14 changes: 4 additions & 10 deletions manifests/stub.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,12 @@
# (optional) Name of the unbound config file
#
define unbound::stub (
$address,
$insecure = false,
$type = 'transparent',
$config_file = $unbound::config_file,
Variant[Array[Unbound::Address], Unbound::Address] $address,
Variant[Boolean, Enum['true', 'false']] $insecure = false,
Unbound::Local_zone_type $type = 'transparent',
Unix::Path $config_file = $unbound::config_file,
) {

if ! $address {
fail('unbound::stub: address(es) must be specified.')
}

validate_unbound_addr($address)

concat::fragment { "unbound-stub-${name}":
order => '15',
target => $config_file,
Expand Down
46 changes: 46 additions & 0 deletions spec/type_aliases/unbound_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'spec_helper'

if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
describe 'Unbound::Address' do
describe 'accepts ipv4 and ipv6 addresses' do
[
'224.0.0.0',
'255.255.255.255',
'0.0.0.0',
'192.88.99.0',
'2001:0db8:85a3:0000:0000:8a2e:0370:7334',
'fa76:8765:34ac:0823:ab76:eee9:0987:1111',
'127.0.0.1',
'8.8.4.4',
'10.1.240.4@5353',
'52.10.10.141',
'FEDC:BA98:7654:3210:FEDC:BA98:7654:3210',
'FF01:0:0:0:0:0:0:101',
'FF01::101',
'FF01:0:0:0:0:0:0:101@5353',
'FF01::101@5353',
'::',
'12AB::CD30:192.168.0.1'
].each do |value|
describe value.inspect do
it { is_expected.to allow_value(value) }
end
end
end

describe 'rejects other values' do
[
'nope',
'77',
'4.4.4',
'2001:0db8:85a3:000000:0000:8a2e:0370:7334',
'4.4.4.4:5353',
'4.4.4@4'
].each do |value|
describe value.inspect do
it { is_expected.not_to allow_value(value) }
end
end
end
end
end
116 changes: 0 additions & 116 deletions spec/unit/unbound/validate_addrs_spec.rb

This file was deleted.

23 changes: 23 additions & 0 deletions types/address.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns copied from Stdlib::IP
type Unbound::Address = Variant[
Stdlib::IP::Address::Nosubnet,
Pattern[
/\A([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}@\d{1,5}\z/,
/\A[[:xdigit:]]{1,4}(:[[:xdigit:]]{1,4}){7}(\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9]))?@\d{1,5}\z/,
/\A([[:xdigit:]]{1,4}:){6}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}(\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9]))?@\d{1,5}\z/,
/\A([[:xdigit:]]{1,4}:){5}:([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}(\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9]))?@\d{1,5}\z/,
/\A([[:xdigit:]]{1,4}:){4}(:[[:xdigit:]]{1,4}){0,1}:([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}(\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9]))?@\d{1,5}\z/,
/\A([[:xdigit:]]{1,4}:){3}(:[[:xdigit:]]{1,4}){0,2}:([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}(\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9]))?@\d{1,5}\z/,
/\A([[:xdigit:]]{1,4}:){2}(:[[:xdigit:]]{1,4}){0,3}:([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}(\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9]))?@\d{1,5}\z/,
/\A([[:xdigit:]]{1,4}:){1}(:[[:xdigit:]]{1,4}){0,4}:([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}(\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9]))?@\d{1,5}\z/,
/\A:(:[[:xdigit:]]{1,4}){0,5}:([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}(\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9]))?@\d{1,5}\z/,
/\A:(:|(:[[:xdigit:]]{1,4}){1,7})(\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9]))?@\d{1,5}\z/,
/\A([[:xdigit:]]{1,4}:){1}(:|(:[[:xdigit:]]{1,4}){1,6})(\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9]))?@\d{1,5}\z/,
/\A([[:xdigit:]]{1,4}:){2}(:|(:[[:xdigit:]]{1,4}){1,5})(\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9]))?@\d{1,5}\z/,
/\A([[:xdigit:]]{1,4}:){3}(:|(:[[:xdigit:]]{1,4}){1,4})(\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9]))?@\d{1,5}\z/,
/\A([[:xdigit:]]{1,4}:){4}(:|(:[[:xdigit:]]{1,4}){1,3})(\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9]))?@\d{1,5}\z/,
/\A([[:xdigit:]]{1,4}:){5}(:|(:[[:xdigit:]]{1,4}){1,2})(\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9]))?@\d{1,5}\z/,
/\A([[:xdigit:]]{1,4}:){6}(:|(:[[:xdigit:]]{1,4}){1,1})(\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9]))?@\d{1,5}\z/,
/\A([[:xdigit:]]{1,4}:){7}:(\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9]))?@\d{1,5}\z/,
],
]

0 comments on commit 5868593

Please sign in to comment.