Skip to content

Commit 84dde24

Browse files
committed
add Stdlib::Fqdn and Stdlib::Host
1 parent cb80a76 commit 84dde24

File tree

7 files changed

+149
-0
lines changed

7 files changed

+149
-0
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,58 @@ Unacceptable input example:
413413
/usr2/username/bin:/usr/local/bin:/usr/bin:.
414414
```
415415

416+
#### `Stdlib::Fqdn`
417+
418+
Matches paths on fully quallified domain name
419+
420+
Acceptable input example:
421+
422+
```shell
423+
localhost
424+
425+
example.com
426+
427+
www.example.com
428+
```
429+
430+
Unacceptable input example:
431+
432+
```shell
433+
'www www.example.com'
434+
435+
2001:DB8::1
436+
```
437+
438+
#### `Stdlib::host`
439+
440+
Matches a valid host which could be a valid ipv4, ipv6 or fqdn
441+
442+
Acceptable input example:
443+
444+
```shell
445+
localhost
446+
447+
example.com
448+
449+
www.example.com
450+
451+
2001:0db8::1
452+
453+
192.0.2.1
454+
```
455+
456+
Unacceptable input example:
457+
458+
```shell
459+
'www www.example.com'
460+
461+
2001:0d8
462+
463+
%.example.com
464+
465+
bob@example.com
466+
```
467+
416468
### Facts
417469

418470
#### `package_provider`

spec/aliases/fqdn_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require 'spec_helper'
2+
3+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4+
describe 'test::fqdn', type: :class do
5+
describe 'valid handling' do
6+
%w(
7+
example
8+
example.com
9+
www.example.com
10+
).each do |value|
11+
describe value.inspect do
12+
let(:params) { { value: value } }
13+
it { is_expected.to compile }
14+
end
15+
end
16+
end
17+
18+
describe 'invalid path handling' do
19+
context 'garbage inputs' do
20+
[
21+
[nil],
22+
[nil, nil],
23+
{ 'foo' => 'bar' },
24+
{},
25+
'',
26+
'2001:DB8::1',
27+
'www www.example.com'
28+
].each do |value|
29+
describe value.inspect do
30+
let(:params) { { value: value } }
31+
it { is_expected.to compile.and_raise_error(%r{parameter 'value' expects a match for Stdlib::Fqdn}) }
32+
end
33+
end
34+
end
35+
end
36+
end
37+
end

spec/aliases/host_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require 'spec_helper'
2+
3+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4+
describe 'test::host', type: :class do
5+
describe 'valid handling' do
6+
%w(
7+
example
8+
example.com
9+
www.example.com
10+
2001:0db8:85a3:0000:0000:8a2e:0370:7334
11+
fa76:8765:34ac:0823:ab76:eee9:0987:1111
12+
2001:0db8::1
13+
224.0.0.0
14+
255.255.255.255
15+
0.0.0.0
16+
192.88.99.0
17+
).each do |value|
18+
describe value.inspect do
19+
let(:params) { { value: value } }
20+
it { is_expected.to compile }
21+
end
22+
end
23+
end
24+
25+
describe 'invalid handling' do
26+
context 'garbage inputs' do
27+
[
28+
[nil],
29+
[nil, nil],
30+
{ 'foo' => 'bar' },
31+
{},
32+
'',
33+
'www www.example.com',
34+
'bob@example.com',
35+
'%.example.com',
36+
'2001:0d8'
37+
].each do |value|
38+
describe value.inspect do
39+
let(:params) { { value: value } }
40+
it { is_expected.to compile.and_raise_error(%r{parameter 'value' expects a Stdlib::Host}) }
41+
end
42+
end
43+
end
44+
end
45+
end
46+
end

spec/fixtures/test/manifests/fqdn.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Class to test the Stdlib::Fqdn type alias
2+
class test::fqdn (
3+
Stdlib::Fqdn $value,
4+
) {
5+
notice('Success')
6+
}

spec/fixtures/test/manifests/host.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Class to test the Stdlib::Host type alias
2+
class test::host (
3+
Stdlib::Host $value,
4+
) {
5+
notice('Success')
6+
}

types/fqdn.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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])$/]

types/host.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type Stdlib::Host = Variant[Stdlib::Fqdn, Stdlib::Compat::Ip_address]

0 commit comments

Comments
 (0)