Skip to content

Commit

Permalink
add Stdlib::Fqdn and Stdlib::Host
Browse files Browse the repository at this point in the history
  • Loading branch information
b4ldr committed Nov 13, 2017
1 parent cb80a76 commit 84dde24
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 0 deletions.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,58 @@ Unacceptable input example:
/usr2/username/bin:/usr/local/bin:/usr/bin:.
```

#### `Stdlib::Fqdn`

Matches paths on fully quallified domain name

Acceptable input example:

```shell
localhost
example.com
www.example.com
```

Unacceptable input example:

```shell
'www www.example.com'
2001:DB8::1
```

#### `Stdlib::host`

Matches a valid host which could be a valid ipv4, ipv6 or fqdn

Acceptable input example:

```shell
localhost
example.com
www.example.com
2001:0db8::1
192.0.2.1
```

Unacceptable input example:

```shell
'www www.example.com'
2001:0d8
%.example.com
[email protected]
```

### Facts

#### `package_provider`
Expand Down
37 changes: 37 additions & 0 deletions spec/aliases/fqdn_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'spec_helper'

if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
describe 'test::fqdn', type: :class do
describe 'valid handling' do
%w(
example
example.com
www.example.com
).each do |value|
describe value.inspect do
let(:params) { { value: value } }
it { is_expected.to compile }
end
end
end

describe 'invalid path handling' do
context 'garbage inputs' do
[
[nil],
[nil, nil],
{ 'foo' => 'bar' },
{},
'',
'2001:DB8::1',
'www www.example.com'
].each do |value|
describe value.inspect do
let(:params) { { value: value } }
it { is_expected.to compile.and_raise_error(%r{parameter 'value' expects a match for Stdlib::Fqdn}) }
end
end
end
end
end
end
46 changes: 46 additions & 0 deletions spec/aliases/host_spec.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 'test::host', type: :class do
describe 'valid handling' do
%w(
example
example.com
www.example.com
2001:0db8:85a3:0000:0000:8a2e:0370:7334
fa76:8765:34ac:0823:ab76:eee9:0987:1111
2001:0db8::1
224.0.0.0
255.255.255.255
0.0.0.0
192.88.99.0
).each do |value|
describe value.inspect do
let(:params) { { value: value } }
it { is_expected.to compile }
end
end
end

describe 'invalid handling' do
context 'garbage inputs' do
[
[nil],
[nil, nil],
{ 'foo' => 'bar' },
{},
'',
'www www.example.com',
'[email protected]',
'%.example.com',
'2001:0d8'
].each do |value|
describe value.inspect do
let(:params) { { value: value } }
it { is_expected.to compile.and_raise_error(%r{parameter 'value' expects a Stdlib::Host}) }
end
end
end
end
end
end
6 changes: 6 additions & 0 deletions spec/fixtures/test/manifests/fqdn.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Class to test the Stdlib::Fqdn type alias
class test::fqdn (
Stdlib::Fqdn $value,
) {
notice('Success')
}
6 changes: 6 additions & 0 deletions spec/fixtures/test/manifests/host.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Class to test the Stdlib::Host type alias
class test::host (
Stdlib::Host $value,
) {
notice('Success')
}
1 change: 1 addition & 0 deletions types/fqdn.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Stdlib::Fqdn = Pattern[/^(([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])$/]
1 change: 1 addition & 0 deletions types/host.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Stdlib::Host = Variant[Stdlib::Fqdn, Stdlib::Compat::Ip_address]

0 comments on commit 84dde24

Please sign in to comment.