Skip to content

Commit f852ba3

Browse files
committed
add Stdlib::Filesource
1 parent 3f7a243 commit f852ba3

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-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
#### `Stdlib::Fqdn`

spec/type_aliases/filesource_spec.rb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
require 'spec_helper'
2+
3+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4+
describe 'Stdlib::Filesource' 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+
puppet://pm.example.com/modules/foo/bar.log
16+
puppet://192.0.2.1/modules/foo/bar.log
17+
/usr2/username/bin:/usr/local/bin:/usr/bin:.
18+
C:/
19+
C:\\
20+
C:\\WINDOWS\\System32
21+
C:/windows/system32
22+
X:/foo/bar
23+
X:\\foo\\bar
24+
\\\\host\\windows
25+
//host/windows
26+
/var/tmp
27+
/var/opt/../lib/puppet
28+
].each do |value|
29+
describe value.inspect do
30+
it { is_expected.to allow_value(value) }
31+
end
32+
end
33+
end
34+
35+
describe 'invalid path handling' do
36+
context 'garbage inputs' do
37+
[
38+
nil,
39+
[nil],
40+
[nil, nil],
41+
{ 'foo' => 'bar' },
42+
{},
43+
'',
44+
'*/Users//nope',
45+
'\\Users/hc/wksp/stdlib',
46+
'C:noslashes',
47+
'\\var\\tmp',
48+
'puppet:///foo/bar.log',
49+
'puppet:///pm.example.com/modules/foo/bar.log',
50+
'puppet://bob@pm.example.com/modules/foo/bar.log',
51+
].each do |value|
52+
describe value.inspect do
53+
it { is_expected.not_to allow_value(value) }
54+
end
55+
end
56+
end
57+
end
58+
end
59+
end

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:\/\/(([\w-]+\.?)+)?\/modules\/([^\/\0]+(\/)?)+$/,
8+
],
9+
]

0 commit comments

Comments
 (0)