summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.markdown48
-rw-r--r--spec/aliases/absolutepath_spec.rb49
-rw-r--r--spec/aliases/httpsurl_spec.rb40
-rw-r--r--spec/aliases/httpurl_spec.rb43
-rw-r--r--spec/aliases/unixpath_spec.rb41
-rw-r--r--spec/aliases/windowspath_spec.rb44
-rw-r--r--spec/fixtures/test/manifests/absolutepath.pp6
-rw-r--r--spec/fixtures/test/manifests/httpsurl.pp6
-rw-r--r--spec/fixtures/test/manifests/httpurl.pp6
-rw-r--r--spec/fixtures/test/manifests/unixpath.pp6
-rw-r--r--spec/fixtures/test/manifests/windowspath.pp6
-rw-r--r--types/absolutepath.pp2
-rw-r--r--types/httpsurl.pp1
-rw-r--r--types/httpurl.pp1
-rw-r--r--types/unixpath.pp2
-rw-r--r--types/windowspath.pp1
16 files changed, 298 insertions, 4 deletions
diff --git a/README.markdown b/README.markdown
index d27668b..210e9f3 100644
--- a/README.markdown
+++ b/README.markdown
@@ -22,7 +22,7 @@ This module provides a standard library of resources for the development of Pupp
* Facts
* Functions
* Defined resource types
- * Types
+ * Data Types
* Providers
> *Note:* As of version 3.7, Puppet Enterprise no longer includes the stdlib module. If you're running Puppet Enterprise, you should install the most recent release of stdlib for compatibility with Puppet modules.
@@ -73,7 +73,7 @@ The `stdlib::stages` class declares various run stages for deploying infrastruct
* `stdlib::stages`: Manages a standard set of run stages for Puppet. It is managed by the stdlib class and should not be declared independently.
-### Types
+### Resource Types
#### `file_line`
@@ -134,6 +134,46 @@ All parameters are optional, unless otherwise noted.
* `path`: **Required.** Defines the file in which Puppet will ensure the line specified by `line`. Must be an absolute path to the file.
* `replace`: Defines whether the resource will overwrite an existing line that matches the `match` parameter. If set to false and a line is found matching the `match` param, the line will not be placed in the file. Valid options: true, false, yes, no. Default: true
+### Data Types
+
+#### `absolutepath`
+
+A strict absolute path type. Uses a Variant of Unixpath and Windowspath types.
+
+Acceptable input examples: /usr2/username/bin:/usr/local/bin:/usr/bin:.
+ C:\\WINDOWS\\System32
+
+#### `httpsurl`
+
+Matches https URLs.
+Acceptable input example: https://hello.com
+Unacceptable input example: httds://notquiteright.org
+
+#### `httpurl`
+
+Matches both https and http URLs.
+
+Acceptable input example: https://hello.com
+ http://hello.com
+Unacceptable input example: httds://notquiteright.org
+
+#### `unixpath`
+
+Matches paths on Unix type Operating Systems.
+
+Acceptable input example: /usr2/username/bin:/usr/local/bin:/usr/bin:.
+ /var/tmp
+Unacceptable input example: C:/whatever
+
+#### `windowspath`
+
+Matches paths on Windows Operating systems.
+
+Acceptable input example: C:\\WINDOWS\\System32
+ C:\\
+ \\\\host\\windows
+Unacceptable input example: /usr2/username/bin:/usr/local/bin:/usr/bin:.
+
### Functions
#### `abs`
@@ -1372,7 +1412,7 @@ The following values will fail, causing compilation to abort:
Validates a value against both a specified type and a deprecated validation function. Silently passes if both pass, errors if only one validation passes, and fails if both validations return false.
-Accepts arguments for:
+Accepts arguments for:
* the type to check the value against,
* the full name of the previous validation function,
* the value to be checked,
@@ -1430,7 +1470,7 @@ class example(
validate_legacy(Numeric, 'validate_numeric', $value)
~~~
-Here, the type of `$value` is defined as `Variant[Stdlib::Compat::Numeric, Numeric]`, which allows any `Numeric` (the new type), as well as all values previously accepted by `validate_numeric` (through `Stdlib::Compat::Numeric`).
+Here, the type of `$value` is defined as `Variant[Stdlib::Compat::Numeric, Numeric]`, which allows any `Numeric` (the new type), as well as all values previously accepted by `validate_numeric` (through `Stdlib::Compat::Numeric`).
The call to `validate_legacy` takes care of triggering the correct log or fail message for you. It requires the new type, the previous validation function name, and all arguments to that function.
diff --git a/spec/aliases/absolutepath_spec.rb b/spec/aliases/absolutepath_spec.rb
new file mode 100644
index 0000000..aa435d7
--- /dev/null
+++ b/spec/aliases/absolutepath_spec.rb
@@ -0,0 +1,49 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::absolutepath', type: :class do
+ describe 'valid handling' do
+ %w{
+ /usr2/username/bin:/usr/local/bin:/usr/bin:.
+ C:/
+ C:\\
+ C:\\WINDOWS\\System32
+ C:/windows/system32
+ X:/foo/bar
+ X:\\foo\\bar
+ \\\\host\\windows
+ //host/windows
+ /var/tmp
+ /var/opt/../lib/puppet
+ }.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, nil ],
+ { 'foo' => 'bar' },
+ { },
+ '',
+ "*/Users//nope",
+ "\\Users/hc/wksp/stdlib",
+ "C:noslashes",
+ "\\var\\tmp"
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Variant/) }
+ end
+ end
+ end
+
+ end
+ end
+end
diff --git a/spec/aliases/httpsurl_spec.rb b/spec/aliases/httpsurl_spec.rb
new file mode 100644
index 0000000..97ae006
--- /dev/null
+++ b/spec/aliases/httpsurl_spec.rb
@@ -0,0 +1,40 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::httpsurl', type: :class do
+ describe 'valid handling' do
+ %w{
+ https://hello.com
+ https://notcreative.org
+ https://notexciting.co.uk
+ }.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, nil ],
+ { 'foo' => 'bar' },
+ { },
+ '',
+ "httds://notquiteright.org",
+ "hptts:/nah",
+ "https;//notrightbutclose.org"
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::HTTPSUrl/) }
+ end
+ end
+ end
+
+ end
+ end
+end
diff --git a/spec/aliases/httpurl_spec.rb b/spec/aliases/httpurl_spec.rb
new file mode 100644
index 0000000..8bd57ca
--- /dev/null
+++ b/spec/aliases/httpurl_spec.rb
@@ -0,0 +1,43 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::httpurl', type: :class do
+ describe 'valid handling' do
+ %w{
+ https://hello.com
+ https://notcreative.org
+ https://canstillaccepthttps.co.uk
+ http://anhttp.com
+ http://runningoutofideas.gov
+ http://
+ }.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, nil ],
+ { 'foo' => 'bar' },
+ { },
+ '',
+ "httds://notquiteright.org",
+ "hptts:/nah",
+ "https;//notrightbutclose.org"
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::HTTPUrl/) }
+ end
+ end
+ end
+
+ end
+ end
+end
diff --git a/spec/aliases/unixpath_spec.rb b/spec/aliases/unixpath_spec.rb
new file mode 100644
index 0000000..aee161d
--- /dev/null
+++ b/spec/aliases/unixpath_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::unixpath', type: :class do
+ describe 'valid handling' do
+ %w{
+ /usr2/username/bin:/usr/local/bin:/usr/bin:.
+ /var/tmp
+ /Users/helencampbell/workspace/puppetlabs-stdlib
+ }.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, nil ],
+ { 'foo' => 'bar' },
+ { },
+ '',
+ "C:/whatever",
+ "\\var\\tmp",
+ "\\Users/hc/wksp/stdlib",
+ "*/Users//nope"
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::Unixpath/) }
+ end
+ end
+ end
+
+ end
+ end
+end
diff --git a/spec/aliases/windowspath_spec.rb b/spec/aliases/windowspath_spec.rb
new file mode 100644
index 0000000..c13794e
--- /dev/null
+++ b/spec/aliases/windowspath_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::windowspath', type: :class do
+ describe 'valid handling' do
+ %w{
+ C:\\
+ C:\\WINDOWS\\System32
+ C:/windows/system32
+ X:/foo/bar
+ X:\\foo\\bar
+ \\\\host\\windows
+ }.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, nil ],
+ { 'foo' => 'bar' },
+ { },
+ '',
+ "httds://notquiteright.org",
+ "/usr2/username/bin:/usr/local/bin:/usr/bin:.",
+ "C;//notright/here",
+ "C:noslashes"
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::Windowspath/) }
+ end
+ end
+ end
+
+ end
+ end
+end
diff --git a/spec/fixtures/test/manifests/absolutepath.pp b/spec/fixtures/test/manifests/absolutepath.pp
new file mode 100644
index 0000000..8321471
--- /dev/null
+++ b/spec/fixtures/test/manifests/absolutepath.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Absolutepath type. Not to be confused with Stdlib::Compat::Absolute_path.
+class test::absolutepath(
+ Stdlib::Absolutepath $value,
+ ) {
+ notice("Success")
+}
diff --git a/spec/fixtures/test/manifests/httpsurl.pp b/spec/fixtures/test/manifests/httpsurl.pp
new file mode 100644
index 0000000..9d6b92d
--- /dev/null
+++ b/spec/fixtures/test/manifests/httpsurl.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::HTTPSUrl type alias
+class test::httpsurl(
+ Stdlib::HTTPSUrl $value,
+ ) {
+ notice("Success")
+}
diff --git a/spec/fixtures/test/manifests/httpurl.pp b/spec/fixtures/test/manifests/httpurl.pp
new file mode 100644
index 0000000..abf869e
--- /dev/null
+++ b/spec/fixtures/test/manifests/httpurl.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::HTTPUrl type alias
+class test::httpurl(
+ Stdlib::HTTPUrl $value,
+ ) {
+ notice("Success")
+}
diff --git a/spec/fixtures/test/manifests/unixpath.pp b/spec/fixtures/test/manifests/unixpath.pp
new file mode 100644
index 0000000..9311109
--- /dev/null
+++ b/spec/fixtures/test/manifests/unixpath.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Unixpath type alias
+class test::unixpath(
+ Stdlib::Unixpath $value,
+ ) {
+ notice("Success")
+}
diff --git a/spec/fixtures/test/manifests/windowspath.pp b/spec/fixtures/test/manifests/windowspath.pp
new file mode 100644
index 0000000..af93ed3
--- /dev/null
+++ b/spec/fixtures/test/manifests/windowspath.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Windowspath type alias
+class test::windowspath(
+ Stdlib::Windowspath $value,
+ ) {
+ notice("Success")
+}
diff --git a/types/absolutepath.pp b/types/absolutepath.pp
new file mode 100644
index 0000000..70ec916
--- /dev/null
+++ b/types/absolutepath.pp
@@ -0,0 +1,2 @@
+# A strict absolutepath type
+type Stdlib::Absolutepath = Variant[Stdlib::Windowspath, Stdlib::Unixpath]
diff --git a/types/httpsurl.pp b/types/httpsurl.pp
new file mode 100644
index 0000000..36fd30f
--- /dev/null
+++ b/types/httpsurl.pp
@@ -0,0 +1 @@
+type Stdlib::HTTPSUrl = Pattern[/^https:\/\//]
diff --git a/types/httpurl.pp b/types/httpurl.pp
new file mode 100644
index 0000000..0d93a95
--- /dev/null
+++ b/types/httpurl.pp
@@ -0,0 +1 @@
+type Stdlib::HTTPUrl = Pattern[/^https?:\/\//]
diff --git a/types/unixpath.pp b/types/unixpath.pp
new file mode 100644
index 0000000..76f2c17
--- /dev/null
+++ b/types/unixpath.pp
@@ -0,0 +1,2 @@
+# this regex rejects any path component that is a / or a NUL
+type Stdlib::Unixpath = Pattern[/^\/([^\/\0]+(\/)?)+$/]
diff --git a/types/windowspath.pp b/types/windowspath.pp
new file mode 100644
index 0000000..bc1ee9c
--- /dev/null
+++ b/types/windowspath.pp
@@ -0,0 +1 @@
+type Stdlib::Windowspath = Pattern[/^(([a-zA-Z]:[\\\/])|([\\\/][\\\/][^\\\/]+[\\\/][^\\\/]+)|([\\\/][\\\/]\?[\\\/][^\\\/]+))/]