Skip to content

Commit d9a9990

Browse files
committed
add Stdlib::Filesource
1 parent cb80a76 commit d9a9990

File tree

4 files changed

+109
-1
lines changed

4 files changed

+109
-1
lines changed

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,40 @@ C:\\
409409

410410
Unacceptable input example:
411411

412+
#### `Stdlib::Filesource`
413+
414+
Matches paths valid values for the source parameter of the puppet file type
415+
416+
Acceptable input example:
417+
412418
```shell
413-
/usr2/username/bin:/usr/local/bin:/usr/bin:.
419+
http://example.com
420+
421+
https://example.com
422+
423+
file:///hello/bla
424+
425+
/usr2/username/bin
426+
427+
C:\foo\bar
428+
429+
/var/opt/../lib/puppet
430+
431+
puppet:///modules/foo/bar.log
432+
```
433+
434+
Unacceptable input example:
435+
436+
```shell
437+
*/Users//nope
438+
439+
\Users/hc/wksp/stdlib
440+
441+
C:noslashes
442+
443+
puppet:///foo/bar.log
444+
445+
ftp://ftp.example.com
414446
```
415447

416448
### Facts

spec/aliases/filesource_spec.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
require 'spec_helper'
2+
3+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4+
describe 'test::filesource', type: :class do
5+
describe 'valid handling' do
6+
%w(
7+
https://hello.com
8+
https://notcreative.org
9+
https://canstillaccepthttps.co.uk
10+
http://anhttp.com
11+
http://runningoutofideas.gov
12+
file:///hello/bla
13+
file:///foo/bar.log
14+
puppet:///modules/foo/bar.log
15+
/usr2/username/bin:/usr/local/bin:/usr/bin:.
16+
C:/
17+
C:\\
18+
C:\\WINDOWS\\System32
19+
C:/windows/system32
20+
X:/foo/bar
21+
X:\\foo\\bar
22+
\\\\host\\windows
23+
//host/windows
24+
/var/tmp
25+
/var/opt/../lib/puppet
26+
).each do |value|
27+
describe value.inspect do
28+
let(:params) { { value: value } }
29+
it { is_expected.to compile }
30+
end
31+
end
32+
end
33+
34+
describe 'invalid path handling' do
35+
context 'garbage inputs' do
36+
[
37+
nil,
38+
[nil],
39+
[nil, nil],
40+
{ 'foo' => 'bar' },
41+
{},
42+
'',
43+
'*/Users//nope',
44+
'\\Users/hc/wksp/stdlib',
45+
'C:noslashes',
46+
'\\var\\tmp',
47+
'puppet:///foo/bar.log'
48+
].each do |value|
49+
describe value.inspect do
50+
let(:params) { { value: value } }
51+
it do
52+
is_expected.to compile.and_raise_error(
53+
%r{parameter 'value' expects a Stdlib::Filesource}
54+
)
55+
end
56+
end
57+
end
58+
end
59+
end
60+
end
61+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Class to test the Stdlib::Filesource type alias
2+
class test::filesource (
3+
Stdlib::Filesource $value,
4+
) {
5+
notice('Success')
6+
}

types/filesource.pp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Validate the source parameter on file types
2+
type Stdlib::Filesource = Variant[
3+
Stdlib::Absolutepath,
4+
Stdlib::HTTPUrl,
5+
Pattern[
6+
/^file:\/\/\/([^\/\0]+(\/)?)+$/,
7+
/^puppet:\/\/\/modules\/([^\/\0]+(\/)?)+$/,
8+
],
9+
]

0 commit comments

Comments
 (0)