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 30, 2017
1 parent e5dff2f commit 127b2f9
Show file tree
Hide file tree
Showing 5 changed files with 133 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
35 changes: 35 additions & 0 deletions spec/type_aliases/fqdn_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'

if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
describe 'Stdlib::Fqdn' do
describe 'valid handling' do
%w[
example
example.com
www.example.com
].each do |value|
describe value.inspect do
it { is_expected.to allow_value(value) }
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
it { is_expected.not_to allow_value(value) }
end
end
end
end
end
end
44 changes: 44 additions & 0 deletions spec/type_aliases/host_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'spec_helper'

if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
describe 'Stdlib::Host' 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
it { is_expected.to allow_value(value) }
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
it { is_expected.not_to allow_value(value) }
end
end
end
end
end
end
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 127b2f9

Please sign in to comment.