diff options
-rw-r--r-- | CHANGELOG.md | 16 | ||||
-rw-r--r-- | README.markdown | 34 | ||||
-rw-r--r-- | lib/puppet/functions/length.rb | 14 | ||||
-rw-r--r-- | lib/puppet/parser/functions/base64.rb | 3 | ||||
-rw-r--r-- | lib/puppet/parser/functions/camelcase.rb | 1 | ||||
-rw-r--r-- | lib/puppet/parser/functions/capitalize.rb | 3 | ||||
-rw-r--r-- | lib/puppet/parser/functions/delete_regex.rb | 3 | ||||
-rw-r--r-- | lib/puppet/parser/functions/downcase.rb | 1 | ||||
-rw-r--r-- | lib/puppet/parser/functions/pw_hash.rb | 3 | ||||
-rw-r--r-- | lib/puppet/parser/functions/size.rb | 2 | ||||
-rw-r--r-- | lib/puppet/parser/functions/sort.rb | 3 | ||||
-rw-r--r-- | lib/puppet/parser/functions/str2saltedsha512.rb | 3 | ||||
-rw-r--r-- | lib/puppet/parser/functions/strftime.rb | 3 | ||||
-rw-r--r-- | lib/puppet/parser/functions/swapcase.rb | 1 | ||||
-rw-r--r-- | lib/puppet/parser/functions/upcase.rb | 3 | ||||
-rw-r--r-- | lib/puppet/parser/functions/uriescape.rb | 1 | ||||
-rw-r--r-- | metadata.json | 7 | ||||
-rw-r--r-- | spec/aliases/absolute_path_spec.rb | 1 | ||||
-rw-r--r-- | spec/aliases/absolutepath_spec.rb | 1 | ||||
-rw-r--r-- | spec/aliases/unixpath_spec.rb | 2 | ||||
-rwxr-xr-x | spec/functions/length.rb | 35 | ||||
-rw-r--r-- | types/unixpath.pp | 2 |
22 files changed, 129 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 98873f6..fe60dd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,19 @@ +## Supported Release 4.15.0 +### Summary + +This release introduces multiple new functions, a new fact and the addition of Ubuntu Xenial support. Also includes a bugfix and documentation update. + +#### Features +- Addition of puppet_server fact to return agents server. +- Addition of a pry function. +- Addition of tests for ensure_resources. +- Addition of FQDN UUID generation function. +- Addition of Ubuntu Xenial to OS Support. + +####Bugfixes +- Ensure_packages now works with Ruby < 2.0. +- Updated the documentation of str2bool function. + ## Supported Release 4.14.0 ### Summary diff --git a/README.markdown b/README.markdown index c8c2819..03daae9 100644 --- a/README.markdown +++ b/README.markdown @@ -209,6 +209,8 @@ Converts a string to and from base64 encoding. Requires an `action` ('encode', ' For backward compatibility, `method` will be set as `default` if not specified. +*Please note:* This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. + *Examples:* ~~~ base64('encode', 'hello') @@ -263,10 +265,18 @@ bool2str(false, 't', 'f') => 'f' Requires a single boolean as input. *Type*: rvalue. +#### `camelcase` + +Converts the case of a string or all strings in an array to camel case. *Type*: rvalue. + +*Please note:* This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. + #### `capitalize` Capitalizes the first character of a string or array of strings and lowercases the remaining characters of each string. Requires either a single string or an array as an input. *Type*: rvalue. +*Please note:* This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. + #### `ceiling` Returns the smallest integer greater than or equal to the argument. Takes a single numeric value as an argument. *Type*: rvalue. @@ -349,6 +359,8 @@ Deletes a determined indexed value from an array. For example, `delete_at(['a',' Deletes all instances of a given element from an array or hash that match a provided regular expression. A string will be treated as a one-item array. +*Please note:* This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. + For example, `delete_regex(['a','b','c','b'], 'b')` returns ['a','c']; `delete_regex({'a' => 1,'b' => 2,'c' => 3},['b','c'])` returns {'a'=> 1}, `delete_regex(['abf', 'ab', 'ac'], '^ab.*')` returns ['ac']. `delete_regex(['ab', 'b'], 'b')` returns ['ab']. *Type*: rvalue. @@ -477,6 +489,8 @@ See also [unix2dos](#unix2dos). Converts the case of a string or of all strings in an array to lowercase. *Type*: rvalue. +*Please note:* This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. + #### `empty` Returns true if the argument is an array or hash that contains no elements, or an empty string. Returns false when the argument is a numerical value. *Type*: rvalue. @@ -831,6 +845,10 @@ The return value is an array in which each element is one joined key/value pair. Returns the keys of a hash as an array. *Type*: rvalue. +#### `length` + +Returns the length of a given string, array or hash. To eventually replace the deprecated size() function as can handle the new type functionality introduced in Puppet 4. *Type*: rvalue. + #### `loadyaml` Loads a YAML file containing an array, string, or hash, and returns the data in the corresponding native data type. @@ -1010,6 +1028,8 @@ The third argument to this function is the salt to use. *Type*: rvalue. +**Please note:** This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. + **Note:** this uses the Puppet master's implementation of crypt(3). If your environment contains several different operating systems, ensure that they are compatible before using this function. #### `range` @@ -1083,12 +1103,14 @@ Randomizes the order of a string or array elements. *Type*: rvalue. #### `size` -Returns the number of elements in a string, an array or a hash. *Type*: rvalue. +Returns the number of elements in a string, an array or a hash. May get confused around Puppet 4 type values and as such is to be deprecated in the next release and replaced with the new stdlib length function. *Type*: rvalue. #### `sort` Sorts strings and arrays lexically. *Type*: rvalue. +*Please note:* This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. + #### `squeeze` Returns a new string where runs of the same character that occur in this set are replaced by a single character. *Type*: rvalue. @@ -1102,10 +1124,14 @@ Converts certain strings to a boolean. This attempts to convert strings that con Converts a string to a salted-SHA512 password hash, used for OS X versions >= 10.7. Given any string, this function returns a hex version of a salted-SHA512 password hash, which can be inserted into your Puppet manifests as a valid password attribute. *Type*: rvalue. +*Please note:* This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. + #### `strftime` Returns formatted time. For example, `strftime("%s")` returns the time since Unix epoch, and `strftime("%Y-%m-%d")` returns the date. *Type*: rvalue. +*Please note:* This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. + *Format:* * `%a`: The abbreviated weekday name ('Sun') @@ -1171,6 +1197,8 @@ For example: Swaps the existing case of a string. For example, `swapcase("aBcD")` results in "AbCd". *Type*: rvalue. +*Please note:* This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. + #### `time` Returns the current Unix epoch time as an integer. For example, `time()` returns something like '1311972653'. *Type*: rvalue. @@ -1258,10 +1286,14 @@ See also [dos2unix](#dos2unix). Converts an object, array or hash of objects that respond to upcase to uppercase. For example, `upcase('abcd')` returns 'ABCD'. *Type*: rvalue. +*Please note:* This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. + #### `uriescape` URLEncodes a string or array of strings. Requires either a single string or an array as an input. *Type*: rvalue. +*Please note:* This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. + #### `validate_absolute_path` Validates that a given string represents an absolute path in the filesystem. Works for Windows and Unix style paths. diff --git a/lib/puppet/functions/length.rb b/lib/puppet/functions/length.rb new file mode 100644 index 0000000..86e735c --- /dev/null +++ b/lib/puppet/functions/length.rb @@ -0,0 +1,14 @@ +#A function to eventually replace the old size() function for stdlib - The original size function did not handle Puppets new type capabilities, so this function is a Puppet 4 compatible solution. +Puppet::Functions.create_function(:length) do + dispatch :length do + param 'Variant[String,Array,Hash]', :value + end + def length(value) + if value.is_a?(String) + result = value.length + elsif value.is_a?(Array) || value.is_a?(Hash) + result = value.size + end + return result + end +end diff --git a/lib/puppet/parser/functions/base64.rb b/lib/puppet/parser/functions/base64.rb index a8998f2..d610146 100644 --- a/lib/puppet/parser/functions/base64.rb +++ b/lib/puppet/parser/functions/base64.rb @@ -1,3 +1,6 @@ + +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. + module Puppet::Parser::Functions newfunction(:base64, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args| diff --git a/lib/puppet/parser/functions/camelcase.rb b/lib/puppet/parser/functions/camelcase.rb index dd67915..085b3c6 100644 --- a/lib/puppet/parser/functions/camelcase.rb +++ b/lib/puppet/parser/functions/camelcase.rb @@ -1,5 +1,6 @@ # # camelcase.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions diff --git a/lib/puppet/parser/functions/capitalize.rb b/lib/puppet/parser/functions/capitalize.rb index 08f1c30..096bc5d 100644 --- a/lib/puppet/parser/functions/capitalize.rb +++ b/lib/puppet/parser/functions/capitalize.rb @@ -1,5 +1,6 @@ # # capitalize.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions @@ -27,5 +28,3 @@ module Puppet::Parser::Functions return result end end - -# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/delete_regex.rb b/lib/puppet/parser/functions/delete_regex.rb index e2c32db..e5dc1fd 100644 --- a/lib/puppet/parser/functions/delete_regex.rb +++ b/lib/puppet/parser/functions/delete_regex.rb @@ -1,5 +1,6 @@ # -# delete_regex.rb +# delete_regex.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions diff --git a/lib/puppet/parser/functions/downcase.rb b/lib/puppet/parser/functions/downcase.rb index 7a16afc..ab04f8a 100644 --- a/lib/puppet/parser/functions/downcase.rb +++ b/lib/puppet/parser/functions/downcase.rb @@ -1,5 +1,6 @@ # # downcase.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions diff --git a/lib/puppet/parser/functions/pw_hash.rb b/lib/puppet/parser/functions/pw_hash.rb index 41d4223..d99ee5b 100644 --- a/lib/puppet/parser/functions/pw_hash.rb +++ b/lib/puppet/parser/functions/pw_hash.rb @@ -1,3 +1,6 @@ + +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. + Puppet::Parser::Functions::newfunction( :pw_hash, :type => :rvalue, diff --git a/lib/puppet/parser/functions/size.rb b/lib/puppet/parser/functions/size.rb index 507c72a..b503aa0 100644 --- a/lib/puppet/parser/functions/size.rb +++ b/lib/puppet/parser/functions/size.rb @@ -12,6 +12,8 @@ Returns the number of elements in a string, an array or a hash item = arguments[0] + function_deprecation([:size, 'This method is going to be deprecated, please use the stdlib length function.']) + if item.is_a?(String) begin diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb index 7c8a1c9..d7792f5 100644 --- a/lib/puppet/parser/functions/sort.rb +++ b/lib/puppet/parser/functions/sort.rb @@ -1,5 +1,6 @@ # -# sort.rb +# sort.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions diff --git a/lib/puppet/parser/functions/str2saltedsha512.rb b/lib/puppet/parser/functions/str2saltedsha512.rb index 7e98d9f..0410c62 100644 --- a/lib/puppet/parser/functions/str2saltedsha512.rb +++ b/lib/puppet/parser/functions/str2saltedsha512.rb @@ -1,5 +1,6 @@ # -# str2saltedsha512.rb +# str2saltedsha512.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions diff --git a/lib/puppet/parser/functions/strftime.rb b/lib/puppet/parser/functions/strftime.rb index f0dc5cf..deae329 100644 --- a/lib/puppet/parser/functions/strftime.rb +++ b/lib/puppet/parser/functions/strftime.rb @@ -1,5 +1,6 @@ # -# strftime.rb +# strftime.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions diff --git a/lib/puppet/parser/functions/swapcase.rb b/lib/puppet/parser/functions/swapcase.rb index 8158f3c..f3276fb 100644 --- a/lib/puppet/parser/functions/swapcase.rb +++ b/lib/puppet/parser/functions/swapcase.rb @@ -1,5 +1,6 @@ # # swapcase.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb index 9f09110..e847e51 100644 --- a/lib/puppet/parser/functions/upcase.rb +++ b/lib/puppet/parser/functions/upcase.rb @@ -1,5 +1,6 @@ # -# upcase.rb +# upcase.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions diff --git a/lib/puppet/parser/functions/uriescape.rb b/lib/puppet/parser/functions/uriescape.rb index 8296d8b..4c5c400 100644 --- a/lib/puppet/parser/functions/uriescape.rb +++ b/lib/puppet/parser/functions/uriescape.rb @@ -1,5 +1,6 @@ # # uriescape.rb +# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # require 'uri' diff --git a/metadata.json b/metadata.json index b697da0..378ae11 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-stdlib", - "version": "4.14.0", + "version": "4.15.0", "author": "puppetlabs", "summary": "Standard library of resources for Puppet modules.", "license": "Apache-2.0", @@ -66,15 +66,14 @@ "10.04", "12.04", "14.04", - "16.06" + "16.04" ] }, { "operatingsystem": "Solaris", "operatingsystemrelease": [ "10", - "11", - "12" + "11" ] }, { diff --git a/spec/aliases/absolute_path_spec.rb b/spec/aliases/absolute_path_spec.rb index 0e9798e..308a3aa 100644 --- a/spec/aliases/absolute_path_spec.rb +++ b/spec/aliases/absolute_path_spec.rb @@ -15,6 +15,7 @@ if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 / /var/tmp /var/opt/../lib/puppet + /var/opt//lib/puppet /var/ůťƒ8 /var/ネット }.each do |value| diff --git a/spec/aliases/absolutepath_spec.rb b/spec/aliases/absolutepath_spec.rb index 337074c..cd442f2 100644 --- a/spec/aliases/absolutepath_spec.rb +++ b/spec/aliases/absolutepath_spec.rb @@ -15,6 +15,7 @@ if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 //host/windows /var/tmp /var/opt/../lib/puppet + /var/opt//lib/puppet }.each do |value| describe value.inspect do let(:params) {{ value: value }} diff --git a/spec/aliases/unixpath_spec.rb b/spec/aliases/unixpath_spec.rb index ac7d64d..6aecfe7 100644 --- a/spec/aliases/unixpath_spec.rb +++ b/spec/aliases/unixpath_spec.rb @@ -9,6 +9,8 @@ if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 /Users/helencampbell/workspace/puppetlabs-stdlib /var/ůťƒ8 /var/ネット + /var//tmp + /var/../tmp }.each do |value| describe value.inspect do let(:params) {{ value: value }} diff --git a/spec/functions/length.rb b/spec/functions/length.rb new file mode 100755 index 0000000..d1ab003 --- /dev/null +++ b/spec/functions/length.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe 'length' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params().and_raise_error(ArgumentError, /'length' expects 1 argument, got none/) } + it { is_expected.to run.with_params([], 'extra').and_raise_error(ArgumentError, /'length' expects 1 argument, got 2/) } + it { is_expected.to run.with_params(1).and_raise_error(ArgumentError, /expects a value of type String, Array, or Hash, got Integer/) } + it { is_expected.to run.with_params(true).and_raise_error(ArgumentError, /expects a value of type String, Array, or Hash, got Boolean/) } + it { is_expected.to run.with_params('1').and_return(1) } + it { is_expected.to run.with_params('1.0').and_return(3) } + it { is_expected.to run.with_params([]).and_return(0) } + it { is_expected.to run.with_params(['a']).and_return(1) } + it { is_expected.to run.with_params(['one', 'two', 'three']).and_return(3) } + it { is_expected.to run.with_params(['one', 'two', 'three', 'four']).and_return(4) } + + it { is_expected.to run.with_params({}).and_return(0) } + it { is_expected.to run.with_params({'1' => '2'}).and_return(1) } + it { is_expected.to run.with_params({'1' => '2', '4' => '4'}).and_return(2) } + it { is_expected.to run.with_params({'€' => '@', '竹' => 'ǿňè'}).and_return(2) } + + it { is_expected.to run.with_params('').and_return(0) } + it { is_expected.to run.with_params('a').and_return(1) } + it { is_expected.to run.with_params('abc').and_return(3) } + it { is_expected.to run.with_params('abcd').and_return(4) } + it { is_expected.to run.with_params('万').and_return(1) } + it { is_expected.to run.with_params('āβćđ').and_return(4) } + + context 'when using a class extending String' do + it 'should call its size method' do + value = AlsoString.new('asdfghjkl') + value.expects(:length).returns('foo') + expect(subject).to run.with_params(value).and_return('foo') + end + end +end diff --git a/types/unixpath.pp b/types/unixpath.pp index 76f2c17..ec3bf7d 100644 --- a/types/unixpath.pp +++ b/types/unixpath.pp @@ -1,2 +1,2 @@ # this regex rejects any path component that is a / or a NUL -type Stdlib::Unixpath = Pattern[/^\/([^\/\0]+(\/)?)+$/] +type Stdlib::Unixpath = Pattern[/^\/([^\/\0]+\/*)+$/] |