summaryrefslogtreecommitdiff
path: root/lib/puppet/parser/functions
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/parser/functions')
-rw-r--r--lib/puppet/parser/functions/abs.rb6
-rw-r--r--lib/puppet/parser/functions/any2bool.rb3
-rw-r--r--lib/puppet/parser/functions/assert_private.rb3
-rw-r--r--lib/puppet/parser/functions/base64.rb3
-rw-r--r--lib/puppet/parser/functions/bool2num.rb3
-rw-r--r--lib/puppet/parser/functions/bool2str.rb3
-rw-r--r--lib/puppet/parser/functions/camelcase.rb7
-rw-r--r--lib/puppet/parser/functions/capitalize.rb9
-rw-r--r--lib/puppet/parser/functions/ceiling.rb9
-rw-r--r--lib/puppet/parser/functions/chomp.rb6
-rw-r--r--lib/puppet/parser/functions/chop.rb6
-rw-r--r--lib/puppet/parser/functions/clamp.rb3
-rw-r--r--lib/puppet/parser/functions/concat.rb3
-rw-r--r--lib/puppet/parser/functions/count.rb3
-rw-r--r--lib/puppet/parser/functions/defined_with_params.rb20
-rw-r--r--lib/puppet/parser/functions/delete.rb6
-rw-r--r--lib/puppet/parser/functions/delete_at.rb9
-rw-r--r--lib/puppet/parser/functions/delete_regex.rb11
-rw-r--r--lib/puppet/parser/functions/delete_undef_values.rb7
-rw-r--r--lib/puppet/parser/functions/delete_values.rb7
-rw-r--r--lib/puppet/parser/functions/deprecation.rb3
-rw-r--r--lib/puppet/parser/functions/difference.rb3
-rw-r--r--lib/puppet/parser/functions/dig44.rb9
-rw-r--r--lib/puppet/parser/functions/downcase.rb7
-rw-r--r--lib/puppet/parser/functions/empty.rb6
-rw-r--r--lib/puppet/parser/functions/enclose_ipv6.rb9
-rw-r--r--lib/puppet/parser/functions/ensure_packages.rb14
-rw-r--r--lib/puppet/parser/functions/flatten.rb3
-rw-r--r--lib/puppet/parser/functions/floor.rb9
-rw-r--r--lib/puppet/parser/functions/fqdn_rotate.rb6
-rw-r--r--lib/puppet/parser/functions/glob.rb22
-rw-r--r--lib/puppet/parser/functions/grep.rb3
-rw-r--r--lib/puppet/parser/functions/has_interface_with.rb3
-rw-r--r--lib/puppet/parser/functions/has_ip_address.rb3
-rw-r--r--lib/puppet/parser/functions/has_ip_network.rb3
-rw-r--r--lib/puppet/parser/functions/hash.rb6
-rw-r--r--lib/puppet/parser/functions/intersection.rb3
-rw-r--r--lib/puppet/parser/functions/is_array.rb3
-rw-r--r--lib/puppet/parser/functions/is_bool.rb3
-rw-r--r--lib/puppet/parser/functions/is_domain_name.rb3
-rw-r--r--lib/puppet/parser/functions/is_email_address.rb3
-rw-r--r--lib/puppet/parser/functions/is_float.rb3
-rw-r--r--lib/puppet/parser/functions/is_function_available.rb3
-rw-r--r--lib/puppet/parser/functions/is_hash.rb3
-rw-r--r--lib/puppet/parser/functions/is_integer.rb3
-rw-r--r--lib/puppet/parser/functions/is_ip_address.rb3
-rw-r--r--lib/puppet/parser/functions/is_ipv4_address.rb3
-rw-r--r--lib/puppet/parser/functions/is_ipv6_address.rb3
-rw-r--r--lib/puppet/parser/functions/is_mac_address.rb3
-rw-r--r--lib/puppet/parser/functions/is_numeric.rb3
-rw-r--r--lib/puppet/parser/functions/is_string.rb3
-rw-r--r--lib/puppet/parser/functions/join.rb3
-rw-r--r--lib/puppet/parser/functions/join_keys_to_values.rb9
-rw-r--r--lib/puppet/parser/functions/keys.rb3
-rw-r--r--lib/puppet/parser/functions/lstrip.rb6
-rw-r--r--lib/puppet/parser/functions/max.rb3
-rw-r--r--lib/puppet/parser/functions/member.rb6
-rw-r--r--lib/puppet/parser/functions/min.rb3
-rw-r--r--lib/puppet/parser/functions/num2bool.rb3
-rw-r--r--lib/puppet/parser/functions/prefix.rb3
-rw-r--r--lib/puppet/parser/functions/pw_hash.rb10
-rw-r--r--lib/puppet/parser/functions/range.rb6
-rw-r--r--lib/puppet/parser/functions/regexpescape.rb6
-rw-r--r--lib/puppet/parser/functions/reverse.rb6
-rw-r--r--lib/puppet/parser/functions/round.rb33
-rw-r--r--lib/puppet/parser/functions/rstrip.rb6
-rw-r--r--lib/puppet/parser/functions/shell_escape.rb3
-rw-r--r--lib/puppet/parser/functions/shell_join.rb3
-rw-r--r--lib/puppet/parser/functions/shell_split.rb3
-rw-r--r--lib/puppet/parser/functions/shuffle.rb6
-rw-r--r--lib/puppet/parser/functions/size.rb8
-rw-r--r--lib/puppet/parser/functions/sort.rb6
-rw-r--r--lib/puppet/parser/functions/squeeze.rb3
-rw-r--r--lib/puppet/parser/functions/str2bool.rb6
-rw-r--r--lib/puppet/parser/functions/str2saltedsha512.rb9
-rw-r--r--lib/puppet/parser/functions/strftime.rb9
-rw-r--r--lib/puppet/parser/functions/strip.rb6
-rw-r--r--lib/puppet/parser/functions/suffix.rb3
-rw-r--r--lib/puppet/parser/functions/swapcase.rb7
-rw-r--r--lib/puppet/parser/functions/time.rb3
-rw-r--r--lib/puppet/parser/functions/to_bytes.rb3
-rw-r--r--lib/puppet/parser/functions/type3x.rb3
-rw-r--r--lib/puppet/parser/functions/union.rb3
-rw-r--r--lib/puppet/parser/functions/unique.rb10
-rw-r--r--lib/puppet/parser/functions/upcase.rb9
-rw-r--r--lib/puppet/parser/functions/uriescape.rb7
-rw-r--r--lib/puppet/parser/functions/validate_domain_name.rb39
-rw-r--r--lib/puppet/parser/functions/values.rb3
-rw-r--r--lib/puppet/parser/functions/values_at.rb18
-rw-r--r--lib/puppet/parser/functions/zip.rb3
90 files changed, 288 insertions, 272 deletions
diff --git a/lib/puppet/parser/functions/abs.rb b/lib/puppet/parser/functions/abs.rb
index 11d2d7f..222a902 100644
--- a/lib/puppet/parser/functions/abs.rb
+++ b/lib/puppet/parser/functions/abs.rb
@@ -9,8 +9,7 @@ module Puppet::Parser::Functions
EOS
) do |arguments|
- raise(Puppet::ParseError, "abs(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "abs(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
@@ -21,8 +20,7 @@ module Puppet::Parser::Functions
elsif value.match(/^-?\d+$/)
value = value.to_i
else
- raise(Puppet::ParseError, 'abs(): Requires float or ' +
- 'integer to work with')
+ raise(Puppet::ParseError, 'abs(): Requires float or integer to work with')
end
end
diff --git a/lib/puppet/parser/functions/any2bool.rb b/lib/puppet/parser/functions/any2bool.rb
index f0f8f83..17612bf 100644
--- a/lib/puppet/parser/functions/any2bool.rb
+++ b/lib/puppet/parser/functions/any2bool.rb
@@ -15,8 +15,7 @@ This converts 'anything' to a boolean. In practise it does the following:
EOS
) do |arguments|
- raise(Puppet::ParseError, "any2bool(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "any2bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
# If argument is already Boolean, return it
if !!arguments[0] == arguments[0]
diff --git a/lib/puppet/parser/functions/assert_private.rb b/lib/puppet/parser/functions/assert_private.rb
index 66c79cc..62e2c6b 100644
--- a/lib/puppet/parser/functions/assert_private.rb
+++ b/lib/puppet/parser/functions/assert_private.rb
@@ -9,8 +9,7 @@ module Puppet::Parser::Functions
EOS
) do |args|
- raise(Puppet::ParseError, "assert_private(): Wrong number of arguments "+
- "given (#{args.size}}) for 0 or 1)") if args.size > 1
+ raise(Puppet::ParseError, "assert_private(): Wrong number of arguments given (#{args.size}}) for 0 or 1)") if args.size > 1
scope = self
if scope.lookupvar('module_name') != scope.lookupvar('caller_module_name')
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/bool2num.rb b/lib/puppet/parser/functions/bool2num.rb
index 6ad6cf4..92e4dde 100644
--- a/lib/puppet/parser/functions/bool2num.rb
+++ b/lib/puppet/parser/functions/bool2num.rb
@@ -11,8 +11,7 @@ module Puppet::Parser::Functions
EOS
) do |arguments|
- raise(Puppet::ParseError, "bool2num(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "bool2num(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
value = function_str2bool([arguments[0]])
diff --git a/lib/puppet/parser/functions/bool2str.rb b/lib/puppet/parser/functions/bool2str.rb
index 7e36474..37d4a4e 100644
--- a/lib/puppet/parser/functions/bool2str.rb
+++ b/lib/puppet/parser/functions/bool2str.rb
@@ -20,8 +20,7 @@ module Puppet::Parser::Functions
) do |arguments|
unless arguments.size == 1 or arguments.size == 3
- raise(Puppet::ParseError, "bool2str(): Wrong number of arguments " +
- "given (#{arguments.size} for 3)")
+ raise(Puppet::ParseError, "bool2str(): Wrong number of arguments given (#{arguments.size} for 3)")
end
value = arguments[0]
diff --git a/lib/puppet/parser/functions/camelcase.rb b/lib/puppet/parser/functions/camelcase.rb
index d7f43f7..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
@@ -8,15 +9,13 @@ Converts the case of a string or all strings in an array to camel case.
EOS
) do |arguments|
- raise(Puppet::ParseError, "camelcase(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "camelcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
klass = value.class
unless [Array, String].include?(klass)
- raise(Puppet::ParseError, 'camelcase(): Requires either ' +
- 'array or string to work with')
+ raise(Puppet::ParseError, 'camelcase(): Requires either array or string to work with')
end
if value.is_a?(Array)
diff --git a/lib/puppet/parser/functions/capitalize.rb b/lib/puppet/parser/functions/capitalize.rb
index 98b2d16..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
@@ -9,14 +10,12 @@ module Puppet::Parser::Functions
EOS
) do |arguments|
- raise(Puppet::ParseError, "capitalize(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "capitalize(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
unless value.is_a?(Array) || value.is_a?(String)
- raise(Puppet::ParseError, 'capitalize(): Requires either ' +
- 'array or string to work with')
+ raise(Puppet::ParseError, 'capitalize(): Requires either array or string to work with')
end
if value.is_a?(Array)
@@ -29,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/ceiling.rb b/lib/puppet/parser/functions/ceiling.rb
index 5f3b10b..bec4266 100644
--- a/lib/puppet/parser/functions/ceiling.rb
+++ b/lib/puppet/parser/functions/ceiling.rb
@@ -5,18 +5,15 @@ module Puppet::Parser::Functions
EOS
) do |arguments|
- raise(Puppet::ParseError, "ceiling(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size != 1
+ raise(Puppet::ParseError, "ceiling(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
begin
arg = Float(arguments[0])
rescue TypeError, ArgumentError => e
- raise(Puppet::ParseError, "ceiling(): Wrong argument type " +
- "given (#{arguments[0]} for Numeric)")
+ raise(Puppet::ParseError, "ceiling(): Wrong argument type given (#{arguments[0]} for Numeric)")
end
- raise(Puppet::ParseError, "ceiling(): Wrong argument type " +
- "given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false
+ raise(Puppet::ParseError, "ceiling(): Wrong argument type given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false
arg.ceil
end
diff --git a/lib/puppet/parser/functions/chomp.rb b/lib/puppet/parser/functions/chomp.rb
index c55841e..f9da50f 100644
--- a/lib/puppet/parser/functions/chomp.rb
+++ b/lib/puppet/parser/functions/chomp.rb
@@ -10,14 +10,12 @@ module Puppet::Parser::Functions
EOS
) do |arguments|
- raise(Puppet::ParseError, "chomp(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "chomp(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
unless value.is_a?(Array) || value.is_a?(String)
- raise(Puppet::ParseError, 'chomp(): Requires either ' +
- 'array or string to work with')
+ raise(Puppet::ParseError, 'chomp(): Requires either array or string to work with')
end
if value.is_a?(Array)
diff --git a/lib/puppet/parser/functions/chop.rb b/lib/puppet/parser/functions/chop.rb
index b24ab78..809349d 100644
--- a/lib/puppet/parser/functions/chop.rb
+++ b/lib/puppet/parser/functions/chop.rb
@@ -12,14 +12,12 @@ module Puppet::Parser::Functions
EOS
) do |arguments|
- raise(Puppet::ParseError, "chop(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "chop(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
unless value.is_a?(Array) || value.is_a?(String)
- raise(Puppet::ParseError, 'chop(): Requires either an ' +
- 'array or string to work with')
+ raise(Puppet::ParseError, 'chop(): Requires either an array or string to work with')
end
if value.is_a?(Array)
diff --git a/lib/puppet/parser/functions/clamp.rb b/lib/puppet/parser/functions/clamp.rb
index 432c7c1..c4503fe 100644
--- a/lib/puppet/parser/functions/clamp.rb
+++ b/lib/puppet/parser/functions/clamp.rb
@@ -10,8 +10,7 @@ module Puppet::Parser::Functions
args.flatten!
- raise(Puppet::ParseError, 'clamp(): Wrong number of arguments, ' +
- 'need three to clamp') if args.size != 3
+ raise(Puppet::ParseError, 'clamp(): Wrong number of arguments, need three to clamp') if args.size != 3
# check values out
args.each do |value|
diff --git a/lib/puppet/parser/functions/concat.rb b/lib/puppet/parser/functions/concat.rb
index 91edb4e..0a49cfe 100644
--- a/lib/puppet/parser/functions/concat.rb
+++ b/lib/puppet/parser/functions/concat.rb
@@ -17,8 +17,7 @@ Would result in:
) do |arguments|
# Check that more than 2 arguments have been given ...
- raise(Puppet::ParseError, "concat(): Wrong number of arguments " +
- "given (#{arguments.size} for < 2)") if arguments.size < 2
+ raise(Puppet::ParseError, "concat(): Wrong number of arguments given (#{arguments.size} for < 2)") if arguments.size < 2
a = arguments[0]
diff --git a/lib/puppet/parser/functions/count.rb b/lib/puppet/parser/functions/count.rb
index 52de1b8..cef2637 100644
--- a/lib/puppet/parser/functions/count.rb
+++ b/lib/puppet/parser/functions/count.rb
@@ -7,8 +7,7 @@ If called with only an array it counts the number of elements that are not nil/u
) do |args|
if (args.size > 2) then
- raise(ArgumentError, "count(): Wrong number of arguments "+
- "given #{args.size} for 1 or 2.")
+ raise(ArgumentError, "count(): Wrong number of arguments given #{args.size} for 1 or 2.")
end
collection, item = args
diff --git a/lib/puppet/parser/functions/defined_with_params.rb b/lib/puppet/parser/functions/defined_with_params.rb
index 99687ae..c45a9df 100644
--- a/lib/puppet/parser/functions/defined_with_params.rb
+++ b/lib/puppet/parser/functions/defined_with_params.rb
@@ -24,7 +24,25 @@ ENDOFDOC
params = {}
end
ret = false
- if resource = findresource(reference.to_s)
+
+ if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0
+ # Workaround for PE-20308
+ if reference.is_a?(String)
+ type_name, title = Puppet::Resource.type_and_title(reference, nil)
+ type = Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_resource_type_or_class(find_global_scope, type_name.downcase)
+ elsif reference.is_a?(Puppet::Resource)
+ type = reference.resource_type
+ title = reference.title
+ else
+ raise(ArgumentError, "Reference is not understood: '#{reference.class}'")
+ end
+ #end workaround
+ else
+ type = reference.to_s
+ title = nil
+ end
+
+ if resource = findresource(type, title)
matches = params.collect do |key, value|
# eql? avoids bugs caused by monkeypatching in puppet
resource_is_undef = resource[key].eql?(:undef) || resource[key].nil?
diff --git a/lib/puppet/parser/functions/delete.rb b/lib/puppet/parser/functions/delete.rb
index 466c55c..9dd5164 100644
--- a/lib/puppet/parser/functions/delete.rb
+++ b/lib/puppet/parser/functions/delete.rb
@@ -23,8 +23,7 @@ string, or key from a hash.
EOS
) do |arguments|
- raise(Puppet::ParseError, "delete(): Wrong number of arguments "+
- "given #{arguments.size} for 2") unless arguments.size == 2
+ raise(Puppet::ParseError, "delete(): Wrong number of arguments given #{arguments.size} for 2") unless arguments.size == 2
collection = arguments[0].dup
Array(arguments[1]).each do |item|
@@ -34,8 +33,7 @@ string, or key from a hash.
when String
collection.gsub! item, ''
else
- raise(TypeError, "delete(): First argument must be an Array, " +
- "String, or Hash. Given an argument of class #{collection.class}.")
+ raise(TypeError, "delete(): First argument must be an Array, String, or Hash. Given an argument of class #{collection.class}.")
end
end
collection
diff --git a/lib/puppet/parser/functions/delete_at.rb b/lib/puppet/parser/functions/delete_at.rb
index 3eb4b53..daf3721 100644
--- a/lib/puppet/parser/functions/delete_at.rb
+++ b/lib/puppet/parser/functions/delete_at.rb
@@ -14,8 +14,7 @@ Would return: ['a','c']
EOS
) do |arguments|
- raise(Puppet::ParseError, "delete_at(): Wrong number of arguments " +
- "given (#{arguments.size} for 2)") if arguments.size < 2
+ raise(Puppet::ParseError, "delete_at(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size < 2
array = arguments[0]
@@ -26,8 +25,7 @@ Would return: ['a','c']
index = arguments[1]
if index.is_a?(String) and not index.match(/^\d+$/)
- raise(Puppet::ParseError, 'delete_at(): You must provide ' +
- 'non-negative numeric index')
+ raise(Puppet::ParseError, 'delete_at(): You must provide non-negative numeric index')
end
result = array.clone
@@ -36,8 +34,7 @@ Would return: ['a','c']
index = index.to_i
if index > result.size - 1 # First element is at index 0 is it not?
- raise(Puppet::ParseError, 'delete_at(): Given index ' +
- 'exceeds size of array given')
+ raise(Puppet::ParseError, 'delete_at(): Given index exceeds size of array given')
end
result.delete_at(index) # We ignore the element that got deleted ...
diff --git a/lib/puppet/parser/functions/delete_regex.rb b/lib/puppet/parser/functions/delete_regex.rb
index d72b3e9..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
@@ -12,7 +13,7 @@ to be matched as an OR.
delete_regex(['a','b','c','b'], 'b')
Would return: ['a','c']
-
+
delete_regex(['a','b','c','b'], ['b', 'c'])
Would return: ['a']
@@ -25,8 +26,7 @@ to be matched as an OR.
EOS
) do |arguments|
- raise(Puppet::ParseError, "delete_regex(): Wrong number of arguments "+
- "given #{arguments.size} for 2") unless arguments.size == 2
+ raise(Puppet::ParseError, "delete_regex(): Wrong number of arguments given #{arguments.size} for 2") unless arguments.size == 2
collection = arguments[0].dup
Array(arguments[1]).each do |item|
@@ -34,8 +34,7 @@ to be matched as an OR.
when Array, Hash, String
collection.reject! { |coll_item| (coll_item =~ %r{\b#{item}\b}) }
else
- raise(TypeError, "delete_regex(): First argument must be an Array, " +
- "Hash, or String. Given an argument of class #{collection.class}.")
+ raise(TypeError, "delete_regex(): First argument must be an Array, Hash, or String. Given an argument of class #{collection.class}.")
end
end
collection
diff --git a/lib/puppet/parser/functions/delete_undef_values.rb b/lib/puppet/parser/functions/delete_undef_values.rb
index f94d4da..00bd252 100644
--- a/lib/puppet/parser/functions/delete_undef_values.rb
+++ b/lib/puppet/parser/functions/delete_undef_values.rb
@@ -15,13 +15,10 @@ Would return: ['A','',false]
EOS
) do |args|
- raise(Puppet::ParseError,
- "delete_undef_values(): Wrong number of arguments given " +
- "(#{args.size})") if args.size < 1
+ raise(Puppet::ParseError, "delete_undef_values(): Wrong number of arguments given (#{args.size})") if args.size < 1
unless args[0].is_a? Array or args[0].is_a? Hash
- raise(Puppet::ParseError,
- "delete_undef_values(): expected an array or hash, got #{args[0]} type #{args[0].class} ")
+ raise(Puppet::ParseError, "delete_undef_values(): expected an array or hash, got #{args[0]} type #{args[0].class} ")
end
result = args[0].dup
if result.is_a?(Hash)
diff --git a/lib/puppet/parser/functions/delete_values.rb b/lib/puppet/parser/functions/delete_values.rb
index f6c8c0e..e799aef 100644
--- a/lib/puppet/parser/functions/delete_values.rb
+++ b/lib/puppet/parser/functions/delete_values.rb
@@ -11,15 +11,12 @@ Would return: {'a'=>'A','c'=>'C','B'=>'D'}
EOS
) do |arguments|
- raise(Puppet::ParseError,
- "delete_values(): Wrong number of arguments given " +
- "(#{arguments.size} of 2)") if arguments.size != 2
+ raise(Puppet::ParseError, "delete_values(): Wrong number of arguments given (#{arguments.size} of 2)") if arguments.size != 2
hash, item = arguments
if not hash.is_a?(Hash)
- raise(TypeError, "delete_values(): First argument must be a Hash. " + \
- "Given an argument of class #{hash.class}.")
+ raise(TypeError, "delete_values(): First argument must be a Hash. Given an argument of class #{hash.class}.")
end
hash.dup.delete_if { |key, val| item == val }
end
diff --git a/lib/puppet/parser/functions/deprecation.rb b/lib/puppet/parser/functions/deprecation.rb
index cd64fe2..39d306a 100644
--- a/lib/puppet/parser/functions/deprecation.rb
+++ b/lib/puppet/parser/functions/deprecation.rb
@@ -4,8 +4,7 @@ module Puppet::Parser::Functions
EOS
) do |arguments|
- raise(Puppet::ParseError, "deprecation: Wrong number of arguments " +
- "given (#{arguments.size} for 2)") unless arguments.size == 2
+ raise(Puppet::ParseError, "deprecation: Wrong number of arguments given (#{arguments.size} for 2)") unless arguments.size == 2
key = arguments[0]
message = arguments[1]
diff --git a/lib/puppet/parser/functions/difference.rb b/lib/puppet/parser/functions/difference.rb
index cd258f7..c9ac478 100644
--- a/lib/puppet/parser/functions/difference.rb
+++ b/lib/puppet/parser/functions/difference.rb
@@ -17,8 +17,7 @@ Would return: ["a"]
) do |arguments|
# Two arguments are required
- raise(Puppet::ParseError, "difference(): Wrong number of arguments " +
- "given (#{arguments.size} for 2)") if arguments.size != 2
+ raise(Puppet::ParseError, "difference(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size != 2
first = arguments[0]
second = arguments[1]
diff --git a/lib/puppet/parser/functions/dig44.rb b/lib/puppet/parser/functions/dig44.rb
index 1e7c318..21c0a8c 100644
--- a/lib/puppet/parser/functions/dig44.rb
+++ b/lib/puppet/parser/functions/dig44.rb
@@ -42,19 +42,16 @@ missing. And the fourth argument can set a variable path separator.
eos
) do |arguments|
# Two arguments are required
- raise(Puppet::ParseError, "dig44(): Wrong number of arguments " +
- "given (#{arguments.size} for at least 2)") if arguments.size < 2
+ raise(Puppet::ParseError, "dig44(): Wrong number of arguments given (#{arguments.size} for at least 2)") if arguments.size < 2
data, path, default = *arguments
unless data.is_a?(Hash) or data.is_a?(Array)
- raise(Puppet::ParseError, "dig44(): first argument must be a hash or an array, " <<
- "given #{data.class.name}")
+ raise(Puppet::ParseError, "dig44(): first argument must be a hash or an array, given #{data.class.name}")
end
unless path.is_a? Array
- raise(Puppet::ParseError, "dig44(): second argument must be an array, " <<
- "given #{path.class.name}")
+ raise(Puppet::ParseError, "dig44(): second argument must be an array, given #{path.class.name}")
end
value = path.reduce(data) do |structure, key|
diff --git a/lib/puppet/parser/functions/downcase.rb b/lib/puppet/parser/functions/downcase.rb
index 040b84f..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
@@ -8,14 +9,12 @@ Converts the case of a string or all strings in an array to lower case.
EOS
) do |arguments|
- raise(Puppet::ParseError, "downcase(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "downcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
unless value.is_a?(Array) || value.is_a?(String)
- raise(Puppet::ParseError, 'downcase(): Requires either ' +
- 'array or string to work with')
+ raise(Puppet::ParseError, 'downcase(): Requires either array or string to work with')
end
if value.is_a?(Array)
diff --git a/lib/puppet/parser/functions/empty.rb b/lib/puppet/parser/functions/empty.rb
index b5a3cde..4f77ad3 100644
--- a/lib/puppet/parser/functions/empty.rb
+++ b/lib/puppet/parser/functions/empty.rb
@@ -8,14 +8,12 @@ Returns true if the variable is empty.
EOS
) do |arguments|
- raise(Puppet::ParseError, "empty(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "empty(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
unless value.is_a?(Array) || value.is_a?(Hash) || value.is_a?(String) || value.is_a?(Numeric)
- raise(Puppet::ParseError, 'empty(): Requires either ' +
- 'array, hash, string or integer to work with')
+ raise(Puppet::ParseError, 'empty(): Requires either array, hash, string or integer to work with')
end
if value.is_a?(Numeric)
diff --git a/lib/puppet/parser/functions/enclose_ipv6.rb b/lib/puppet/parser/functions/enclose_ipv6.rb
index 80ffc3a..1f8a454 100644
--- a/lib/puppet/parser/functions/enclose_ipv6.rb
+++ b/lib/puppet/parser/functions/enclose_ipv6.rb
@@ -16,12 +16,10 @@ Takes an array of ip addresses and encloses the ipv6 addresses with square brack
end
if (arguments.size != 1) then
- raise(Puppet::ParseError, "enclose_ipv6(): Wrong number of arguments "+
- "given #{arguments.size} for 1")
+ raise(Puppet::ParseError, "enclose_ipv6(): Wrong number of arguments given #{arguments.size} for 1")
end
unless arguments[0].is_a?(String) or arguments[0].is_a?(Array) then
- raise(Puppet::ParseError, "enclose_ipv6(): Wrong argument type "+
- "given #{arguments[0].class} expected String or Array")
+ raise(Puppet::ParseError, "enclose_ipv6(): Wrong argument type given #{arguments[0].class} expected String or Array")
end
input = [arguments[0]].flatten.compact
@@ -32,8 +30,7 @@ Takes an array of ip addresses and encloses the ipv6 addresses with square brack
begin
ip = IPAddr.new(val)
rescue *rescuable_exceptions
- raise(Puppet::ParseError, "enclose_ipv6(): Wrong argument "+
- "given #{val} is not an ip address.")
+ raise(Puppet::ParseError, "enclose_ipv6(): Wrong argument given #{val} is not an ip address.")
end
val = "[#{ip.to_s}]" if ip.ipv6?
end
diff --git a/lib/puppet/parser/functions/ensure_packages.rb b/lib/puppet/parser/functions/ensure_packages.rb
index 439af1e..1bf8bf1 100644
--- a/lib/puppet/parser/functions/ensure_packages.rb
+++ b/lib/puppet/parser/functions/ensure_packages.rb
@@ -11,15 +11,17 @@ third argument to the ensure_resource() function.
) do |arguments|
if arguments.size > 2 or arguments.size == 0
- raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments " +
- "given (#{arguments.size} for 1 or 2)")
- elsif arguments.size == 2 and !arguments[1].is_a?(Hash)
+ raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments given (#{arguments.size} for 1 or 2)")
+ elsif arguments.size == 2 and !arguments[1].is_a?(Hash)
raise(Puppet::ParseError, 'ensure_packages(): Requires second argument to be a Hash')
end
if arguments[0].is_a?(Hash)
if arguments[1]
defaults = { 'ensure' => 'present' }.merge(arguments[1])
+ if defaults['ensure'] == 'installed'
+ defaults['ensure'] = 'present'
+ end
else
defaults = { 'ensure' => 'present' }
end
@@ -31,13 +33,19 @@ third argument to the ensure_resource() function.
if arguments[1]
defaults = { 'ensure' => 'present' }.merge(arguments[1])
+ if defaults['ensure'] == 'installed'
+ defaults['ensure'] = 'present'
+ end
else
defaults = { 'ensure' => 'present' }
end
Puppet::Parser::Functions.function(:ensure_resource)
packages.each { |package_name|
+ raise(Puppet::ParseError, 'ensure_packages(): Empty String provided for package name') if package_name.length == 0
+ if !findresource("Package[#{package_name}]")
function_ensure_resource(['package', package_name, defaults ])
+ end
}
end
end
diff --git a/lib/puppet/parser/functions/flatten.rb b/lib/puppet/parser/functions/flatten.rb
index a1ed183..4401bdb 100644
--- a/lib/puppet/parser/functions/flatten.rb
+++ b/lib/puppet/parser/functions/flatten.rb
@@ -15,8 +15,7 @@ Would return: ['a','b','c']
EOS
) do |arguments|
- raise(Puppet::ParseError, "flatten(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size != 1
+ raise(Puppet::ParseError, "flatten(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
array = arguments[0]
diff --git a/lib/puppet/parser/functions/floor.rb b/lib/puppet/parser/functions/floor.rb
index 9a6f014..9e4b504 100644
--- a/lib/puppet/parser/functions/floor.rb
+++ b/lib/puppet/parser/functions/floor.rb
@@ -5,18 +5,15 @@ module Puppet::Parser::Functions
EOS
) do |arguments|
- raise(Puppet::ParseError, "floor(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size != 1
+ raise(Puppet::ParseError, "floor(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
begin
arg = Float(arguments[0])
rescue TypeError, ArgumentError => e
- raise(Puppet::ParseError, "floor(): Wrong argument type " +
- "given (#{arguments[0]} for Numeric)")
+ raise(Puppet::ParseError, "floor(): Wrong argument type given (#{arguments[0]} for Numeric)")
end
- raise(Puppet::ParseError, "floor(): Wrong argument type " +
- "given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false
+ raise(Puppet::ParseError, "floor(): Wrong argument type given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false
arg.floor
end
diff --git a/lib/puppet/parser/functions/fqdn_rotate.rb b/lib/puppet/parser/functions/fqdn_rotate.rb
index b66431d..05bdcc7 100644
--- a/lib/puppet/parser/functions/fqdn_rotate.rb
+++ b/lib/puppet/parser/functions/fqdn_rotate.rb
@@ -15,15 +15,13 @@ Puppet::Parser::Functions.newfunction(
result will be the same every time unless its hostname changes.) Adding
a SEED can be useful if you need more than one unrelated rotation.") do |args|
- raise(Puppet::ParseError, "fqdn_rotate(): Wrong number of arguments " +
- "given (#{args.size} for 1)") if args.size < 1
+ raise(Puppet::ParseError, "fqdn_rotate(): Wrong number of arguments given (#{args.size} for 1)") if args.size < 1
value = args.shift
require 'digest/md5'
unless value.is_a?(Array) || value.is_a?(String)
- raise(Puppet::ParseError, 'fqdn_rotate(): Requires either ' +
- 'array or string to work with')
+ raise(Puppet::ParseError, 'fqdn_rotate(): Requires either array or string to work with')
end
result = value.clone
diff --git a/lib/puppet/parser/functions/glob.rb b/lib/puppet/parser/functions/glob.rb
new file mode 100644
index 0000000..54cdda6
--- /dev/null
+++ b/lib/puppet/parser/functions/glob.rb
@@ -0,0 +1,22 @@
+#
+# glob.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:glob, :type => :rvalue, :doc => <<-'EOS'
+ Returns an Array of file entries of a directory or an Array of directories.
+ Uses same patterns as Dir#glob
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "glob(): Wrong number of arguments given " +
+ "(#{arguments.size} for 1)") unless arguments.size == 1
+
+ pattern = arguments[0]
+
+ raise(Puppet::ParseError, 'glob(): Requires either array or string ' +
+ 'to work') unless pattern.is_a?(String) || pattern.is_a?(Array)
+
+ Dir.glob(pattern)
+ end
+end
diff --git a/lib/puppet/parser/functions/grep.rb b/lib/puppet/parser/functions/grep.rb
index ceba9ec..c611a7e 100644
--- a/lib/puppet/parser/functions/grep.rb
+++ b/lib/puppet/parser/functions/grep.rb
@@ -18,8 +18,7 @@ Would return:
) do |arguments|
if (arguments.size != 2) then
- raise(Puppet::ParseError, "grep(): Wrong number of arguments "+
- "given #{arguments.size} for 2")
+ raise(Puppet::ParseError, "grep(): Wrong number of arguments given #{arguments.size} for 2")
end
a = arguments[0]
diff --git a/lib/puppet/parser/functions/has_interface_with.rb b/lib/puppet/parser/functions/has_interface_with.rb
index e762798..f6cb74b 100644
--- a/lib/puppet/parser/functions/has_interface_with.rb
+++ b/lib/puppet/parser/functions/has_interface_with.rb
@@ -19,8 +19,7 @@ has_interface_with("lo") => true
EOS
) do |args|
- raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments " +
- "given (#{args.size} for 1 or 2)") if args.size < 1 or args.size > 2
+ raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments given (#{args.size} for 1 or 2)") if args.size < 1 or args.size > 2
interfaces = lookupvar('interfaces')
diff --git a/lib/puppet/parser/functions/has_ip_address.rb b/lib/puppet/parser/functions/has_ip_address.rb
index 842c8ec..a0071c8 100644
--- a/lib/puppet/parser/functions/has_ip_address.rb
+++ b/lib/puppet/parser/functions/has_ip_address.rb
@@ -11,8 +11,7 @@ This function iterates through the 'interfaces' fact and checks the
EOS
) do |args|
- raise(Puppet::ParseError, "has_ip_address(): Wrong number of arguments " +
- "given (#{args.size} for 1)") if args.size != 1
+ raise(Puppet::ParseError, "has_ip_address(): Wrong number of arguments given (#{args.size} for 1)") if args.size != 1
Puppet::Parser::Functions.autoloader.load(:has_interface_with) \
unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with)
diff --git a/lib/puppet/parser/functions/has_ip_network.rb b/lib/puppet/parser/functions/has_ip_network.rb
index 9ccf902..b02c0c0 100644
--- a/lib/puppet/parser/functions/has_ip_network.rb
+++ b/lib/puppet/parser/functions/has_ip_network.rb
@@ -11,8 +11,7 @@ This function iterates through the 'interfaces' fact and checks the
EOS
) do |args|
- raise(Puppet::ParseError, "has_ip_network(): Wrong number of arguments " +
- "given (#{args.size} for 1)") if args.size != 1
+ raise(Puppet::ParseError, "has_ip_network(): Wrong number of arguments given (#{args.size} for 1)") if args.size != 1
Puppet::Parser::Functions.autoloader.load(:has_interface_with) \
unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with)
diff --git a/lib/puppet/parser/functions/hash.rb b/lib/puppet/parser/functions/hash.rb
index 89d0e07..22763f3 100644
--- a/lib/puppet/parser/functions/hash.rb
+++ b/lib/puppet/parser/functions/hash.rb
@@ -14,8 +14,7 @@ Would return: {'a'=>1,'b'=>2,'c'=>3}
EOS
) do |arguments|
- raise(Puppet::ParseError, "hash(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "hash(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
array = arguments[0]
@@ -30,8 +29,7 @@ Would return: {'a'=>1,'b'=>2,'c'=>3}
array = array.flatten
result = Hash[*array]
rescue StandardError
- raise(Puppet::ParseError, 'hash(): Unable to compute ' +
- 'hash from array given')
+ raise(Puppet::ParseError, 'hash(): Unable to compute hash from array given')
end
return result
diff --git a/lib/puppet/parser/functions/intersection.rb b/lib/puppet/parser/functions/intersection.rb
index bfbb4ba..8a438f4 100644
--- a/lib/puppet/parser/functions/intersection.rb
+++ b/lib/puppet/parser/functions/intersection.rb
@@ -15,8 +15,7 @@ This function returns an array of the intersection of two.
) do |arguments|
# Two arguments are required
- raise(Puppet::ParseError, "intersection(): Wrong number of arguments " +
- "given (#{arguments.size} for 2)") if arguments.size != 2
+ raise(Puppet::ParseError, "intersection(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size != 2
first = arguments[0]
second = arguments[1]
diff --git a/lib/puppet/parser/functions/is_array.rb b/lib/puppet/parser/functions/is_array.rb
index 1d2c0fa..a33afe4 100644
--- a/lib/puppet/parser/functions/is_array.rb
+++ b/lib/puppet/parser/functions/is_array.rb
@@ -10,8 +10,7 @@ Returns true if the variable passed to this function is an array.
function_deprecation([:is_array, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Array. There is further documentation for validate_legacy function in the README.'])
- raise(Puppet::ParseError, "is_array(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "is_array(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
type = arguments[0]
diff --git a/lib/puppet/parser/functions/is_bool.rb b/lib/puppet/parser/functions/is_bool.rb
index 83d2ebe..2ebe430 100644
--- a/lib/puppet/parser/functions/is_bool.rb
+++ b/lib/puppet/parser/functions/is_bool.rb
@@ -10,8 +10,7 @@ Returns true if the variable passed to this function is a boolean.
function_deprecation([:is_bool, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Bool. There is further documentation for validate_legacy function in the README.'])
- raise(Puppet::ParseError, "is_bool(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size != 1
+ raise(Puppet::ParseError, "is_bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
type = arguments[0]
diff --git a/lib/puppet/parser/functions/is_domain_name.rb b/lib/puppet/parser/functions/is_domain_name.rb
index 90ede32..247db3b 100644
--- a/lib/puppet/parser/functions/is_domain_name.rb
+++ b/lib/puppet/parser/functions/is_domain_name.rb
@@ -9,8 +9,7 @@ Returns true if the string passed to this function is a syntactically correct do
) do |arguments|
if (arguments.size != 1) then
- raise(Puppet::ParseError, "is_domain_name(): Wrong number of arguments "+
- "given #{arguments.size} for 1")
+ raise(Puppet::ParseError, "is_domain_name(): Wrong number of arguments given #{arguments.size} for 1")
end
# Only allow string types
diff --git a/lib/puppet/parser/functions/is_email_address.rb b/lib/puppet/parser/functions/is_email_address.rb
index 4fb0229..bcd7921 100644
--- a/lib/puppet/parser/functions/is_email_address.rb
+++ b/lib/puppet/parser/functions/is_email_address.rb
@@ -8,8 +8,7 @@ Returns true if the string passed to this function is a valid email address.
EOS
) do |arguments|
if arguments.size != 1
- raise(Puppet::ParseError, 'is_email_address(): Wrong number of arguments '\
- "given #{arguments.size} for 1")
+ raise(Puppet::ParseError, "is_email_address(): Wrong number of arguments given #{arguments.size} for 1")
end
# Taken from http://emailregex.com/ (simpler regex)
diff --git a/lib/puppet/parser/functions/is_float.rb b/lib/puppet/parser/functions/is_float.rb
index 1186458..aa84a2b 100644
--- a/lib/puppet/parser/functions/is_float.rb
+++ b/lib/puppet/parser/functions/is_float.rb
@@ -11,8 +11,7 @@ Returns true if the variable passed to this function is a float.
function_deprecation([:is_float, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Float. There is further documentation for validate_legacy function in the README.'])
if (arguments.size != 1) then
- raise(Puppet::ParseError, "is_float(): Wrong number of arguments "+
- "given #{arguments.size} for 1")
+ raise(Puppet::ParseError, "is_float(): Wrong number of arguments given #{arguments.size} for 1")
end
value = arguments[0]
diff --git a/lib/puppet/parser/functions/is_function_available.rb b/lib/puppet/parser/functions/is_function_available.rb
index 6da82c8..50cd5e1 100644
--- a/lib/puppet/parser/functions/is_function_available.rb
+++ b/lib/puppet/parser/functions/is_function_available.rb
@@ -11,8 +11,7 @@ true if the function exists, false if not.
) do |arguments|
if (arguments.size != 1) then
- raise(Puppet::ParseError, "is_function_available?(): Wrong number of arguments "+
- "given #{arguments.size} for 1")
+ raise(Puppet::ParseError, "is_function_available?(): Wrong number of arguments given #{arguments.size} for 1")
end
# Only allow String types
diff --git a/lib/puppet/parser/functions/is_hash.rb b/lib/puppet/parser/functions/is_hash.rb
index ad907f0..3162f7d 100644
--- a/lib/puppet/parser/functions/is_hash.rb
+++ b/lib/puppet/parser/functions/is_hash.rb
@@ -8,8 +8,7 @@ Returns true if the variable passed to this function is a hash.
EOS
) do |arguments|
- raise(Puppet::ParseError, "is_hash(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size != 1
+ raise(Puppet::ParseError, "is_hash(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
type = arguments[0]
diff --git a/lib/puppet/parser/functions/is_integer.rb b/lib/puppet/parser/functions/is_integer.rb
index e04fd1f..8965b15 100644
--- a/lib/puppet/parser/functions/is_integer.rb
+++ b/lib/puppet/parser/functions/is_integer.rb
@@ -16,8 +16,7 @@ If given any other argument `false` is returned.
function_deprecation([:is_integer, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Integer. There is further documentation for validate_legacy function in the README.'])
if (arguments.size != 1) then
- raise(Puppet::ParseError, "is_integer(): Wrong number of arguments "+
- "given #{arguments.size} for 1")
+ raise(Puppet::ParseError, "is_integer(): Wrong number of arguments given #{arguments.size} for 1")
end
value = arguments[0]
diff --git a/lib/puppet/parser/functions/is_ip_address.rb b/lib/puppet/parser/functions/is_ip_address.rb
index 5f1d765..79ddb98 100644
--- a/lib/puppet/parser/functions/is_ip_address.rb
+++ b/lib/puppet/parser/functions/is_ip_address.rb
@@ -13,8 +13,7 @@ Returns true if the string passed to this function is a valid IP address.
function_deprecation([:is_ip_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ip_address. There is further documentation for validate_legacy function in the README.'])
if (arguments.size != 1) then
- raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments "+
- "given #{arguments.size} for 1")
+ raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments given #{arguments.size} for 1")
end
begin
diff --git a/lib/puppet/parser/functions/is_ipv4_address.rb b/lib/puppet/parser/functions/is_ipv4_address.rb
index 1764e61..91869b6 100644
--- a/lib/puppet/parser/functions/is_ipv4_address.rb
+++ b/lib/puppet/parser/functions/is_ipv4_address.rb
@@ -13,8 +13,7 @@ Returns true if the string passed to this function is a valid IPv4 address.
function_deprecation([:is_ipv4_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv4. There is further documentation for validate_legacy function in the README.'])
if (arguments.size != 1) then
- raise(Puppet::ParseError, "is_ipv4_address(): Wrong number of arguments "+
- "given #{arguments.size} for 1")
+ raise(Puppet::ParseError, "is_ipv4_address(): Wrong number of arguments given #{arguments.size} for 1")
end
begin
diff --git a/lib/puppet/parser/functions/is_ipv6_address.rb b/lib/puppet/parser/functions/is_ipv6_address.rb
index 7ca4997..4d96202 100644
--- a/lib/puppet/parser/functions/is_ipv6_address.rb
+++ b/lib/puppet/parser/functions/is_ipv6_address.rb
@@ -13,8 +13,7 @@ Returns true if the string passed to this function is a valid IPv6 address.
require 'ipaddr'
if (arguments.size != 1) then
- raise(Puppet::ParseError, "is_ipv6_address(): Wrong number of arguments "+
- "given #{arguments.size} for 1")
+ raise(Puppet::ParseError, "is_ipv6_address(): Wrong number of arguments given #{arguments.size} for 1")
end
begin
diff --git a/lib/puppet/parser/functions/is_mac_address.rb b/lib/puppet/parser/functions/is_mac_address.rb
index 2619d44..5993ed2 100644
--- a/lib/puppet/parser/functions/is_mac_address.rb
+++ b/lib/puppet/parser/functions/is_mac_address.rb
@@ -9,8 +9,7 @@ Returns true if the string passed to this function is a valid mac address.
) do |arguments|
if (arguments.size != 1) then
- raise(Puppet::ParseError, "is_mac_address(): Wrong number of arguments "+
- "given #{arguments.size} for 1")
+ raise(Puppet::ParseError, "is_mac_address(): Wrong number of arguments given #{arguments.size} for 1")
end
mac = arguments[0]
diff --git a/lib/puppet/parser/functions/is_numeric.rb b/lib/puppet/parser/functions/is_numeric.rb
index 4a55225..7800edd 100644
--- a/lib/puppet/parser/functions/is_numeric.rb
+++ b/lib/puppet/parser/functions/is_numeric.rb
@@ -27,8 +27,7 @@ Valid examples:
function_deprecation([:is_numeric, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Numeric. There is further documentation for validate_legacy function in the README.'])
if (arguments.size != 1) then
- raise(Puppet::ParseError, "is_numeric(): Wrong number of arguments "+
- "given #{arguments.size} for 1")
+ raise(Puppet::ParseError, "is_numeric(): Wrong number of arguments given #{arguments.size} for 1")
end
value = arguments[0]
diff --git a/lib/puppet/parser/functions/is_string.rb b/lib/puppet/parser/functions/is_string.rb
index 31ee91e..0ed6aec 100644
--- a/lib/puppet/parser/functions/is_string.rb
+++ b/lib/puppet/parser/functions/is_string.rb
@@ -10,8 +10,7 @@ Returns true if the variable passed to this function is a string.
function_deprecation([:is_string, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README.'])
- raise(Puppet::ParseError, "is_string(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "is_string(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
type = arguments[0]
diff --git a/lib/puppet/parser/functions/join.rb b/lib/puppet/parser/functions/join.rb
index 6c0a6ba..1c17997 100644
--- a/lib/puppet/parser/functions/join.rb
+++ b/lib/puppet/parser/functions/join.rb
@@ -15,8 +15,7 @@ Would result in: "a,b,c"
) do |arguments|
# Technically we support two arguments but only first is mandatory ...
- raise(Puppet::ParseError, "join(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "join(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
array = arguments[0]
diff --git a/lib/puppet/parser/functions/join_keys_to_values.rb b/lib/puppet/parser/functions/join_keys_to_values.rb
index e3baf9f..d8966ba 100644
--- a/lib/puppet/parser/functions/join_keys_to_values.rb
+++ b/lib/puppet/parser/functions/join_keys_to_values.rb
@@ -23,22 +23,19 @@ Would result in: ["a is 1","b is 2","b is 3"]
# Validate the number of arguments.
if arguments.size != 2
- raise(Puppet::ParseError, "join_keys_to_values(): Takes exactly two " +
- "arguments, but #{arguments.size} given.")
+ raise(Puppet::ParseError, "join_keys_to_values(): Takes exactly two arguments, but #{arguments.size} given.")
end
# Validate the first argument.
hash = arguments[0]
if not hash.is_a?(Hash)
- raise(TypeError, "join_keys_to_values(): The first argument must be a " +
- "hash, but a #{hash.class} was given.")
+ raise(TypeError, "join_keys_to_values(): The first argument must be a hash, but a #{hash.class} was given.")
end
# Validate the second argument.
separator = arguments[1]
if not separator.is_a?(String)
- raise(TypeError, "join_keys_to_values(): The second argument must be a " +
- "string, but a #{separator.class} was given.")
+ raise(TypeError, "join_keys_to_values(): The second argument must be a string, but a #{separator.class} was given.")
end
# Join the keys to their values.
diff --git a/lib/puppet/parser/functions/keys.rb b/lib/puppet/parser/functions/keys.rb
index f0d13b6..199e319 100644
--- a/lib/puppet/parser/functions/keys.rb
+++ b/lib/puppet/parser/functions/keys.rb
@@ -8,8 +8,7 @@ Returns the keys of a hash as an array.
EOS
) do |arguments|
- raise(Puppet::ParseError, "keys(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "keys(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
hash = arguments[0]
diff --git a/lib/puppet/parser/functions/lstrip.rb b/lib/puppet/parser/functions/lstrip.rb
index 624e4c8..9a9ee29 100644
--- a/lib/puppet/parser/functions/lstrip.rb
+++ b/lib/puppet/parser/functions/lstrip.rb
@@ -8,14 +8,12 @@ Strips leading spaces to the left of a string.
EOS
) do |arguments|
- raise(Puppet::ParseError, "lstrip(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "lstrip(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
unless value.is_a?(Array) || value.is_a?(String)
- raise(Puppet::ParseError, 'lstrip(): Requires either ' +
- 'array or string to work with')
+ raise(Puppet::ParseError, 'lstrip(): Requires either array or string to work with')
end
if value.is_a?(Array)
diff --git a/lib/puppet/parser/functions/max.rb b/lib/puppet/parser/functions/max.rb
index 60fb94a..758c42c 100644
--- a/lib/puppet/parser/functions/max.rb
+++ b/lib/puppet/parser/functions/max.rb
@@ -5,8 +5,7 @@ module Puppet::Parser::Functions
EOS
) do |args|
- raise(Puppet::ParseError, "max(): Wrong number of arguments " +
- "need at least one") if args.size == 0
+ raise(Puppet::ParseError, "max(): Wrong number of arguments need at least one") if args.size == 0
# Sometimes we get numbers as numerics and sometimes as strings.
# We try to compare them as numbers when possible
diff --git a/lib/puppet/parser/functions/member.rb b/lib/puppet/parser/functions/member.rb
index 1e5b3de..fb93452 100644
--- a/lib/puppet/parser/functions/member.rb
+++ b/lib/puppet/parser/functions/member.rb
@@ -30,8 +30,7 @@ would return: false
EOS
) do |arguments|
- raise(Puppet::ParseError, "member(): Wrong number of arguments " +
- "given (#{arguments.size} for 2)") if arguments.size < 2
+ raise(Puppet::ParseError, "member(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size < 2
array = arguments[0]
@@ -50,8 +49,7 @@ would return: false
end
- raise(Puppet::ParseError, 'member(): You must provide item ' +
- 'to search for within array given') if item.respond_to?('empty?') && item.empty?
+ raise(Puppet::ParseError, 'member(): You must provide item to search for within array given') if item.respond_to?('empty?') && item.empty?
result = (item - array).empty?
diff --git a/lib/puppet/parser/functions/min.rb b/lib/puppet/parser/functions/min.rb
index 6bd6ebf..f10a2b2 100644
--- a/lib/puppet/parser/functions/min.rb
+++ b/lib/puppet/parser/functions/min.rb
@@ -5,8 +5,7 @@ module Puppet::Parser::Functions
EOS
) do |args|
- raise(Puppet::ParseError, "min(): Wrong number of arguments " +
- "need at least one") if args.size == 0
+ raise(Puppet::ParseError, "min(): Wrong number of arguments need at least one") if args.size == 0
# Sometimes we get numbers as numerics and sometimes as strings.
# We try to compare them as numbers when possible
diff --git a/lib/puppet/parser/functions/num2bool.rb b/lib/puppet/parser/functions/num2bool.rb
index af0e6ed..9ad59b2 100644
--- a/lib/puppet/parser/functions/num2bool.rb
+++ b/lib/puppet/parser/functions/num2bool.rb
@@ -10,8 +10,7 @@ become true.
EOS
) do |arguments|
- raise(Puppet::ParseError, "num2bool(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size != 1
+ raise(Puppet::ParseError, "num2bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
number = arguments[0]
diff --git a/lib/puppet/parser/functions/prefix.rb b/lib/puppet/parser/functions/prefix.rb
index ac1c58a..b1c1e35 100644
--- a/lib/puppet/parser/functions/prefix.rb
+++ b/lib/puppet/parser/functions/prefix.rb
@@ -15,8 +15,7 @@ Will return: ['pa','pb','pc']
) do |arguments|
# Technically we support two arguments but only first is mandatory ...
- raise(Puppet::ParseError, "prefix(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "prefix(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
enumerable = arguments[0]
diff --git a/lib/puppet/parser/functions/pw_hash.rb b/lib/puppet/parser/functions/pw_hash.rb
index 41d4223..adcc719 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,
@@ -24,6 +27,13 @@ Puppet::Parser::Functions::newfunction(
environment contains several different operating systems, ensure that they
are compatible before using this function.") do |args|
raise ArgumentError, "pw_hash(): wrong number of arguments (#{args.size} for 3)" if args.size != 3
+ args.map! do |arg|
+ if (defined? Puppet::Pops::Types::PSensitiveType::Sensitive) && (arg.is_a? Puppet::Pops::Types::PSensitiveType::Sensitive)
+ arg.unwrap
+ else
+ arg
+ end
+ end
raise ArgumentError, "pw_hash(): first argument must be a string" unless args[0].is_a? String or args[0].nil?
raise ArgumentError, "pw_hash(): second argument must be a string" unless args[1].is_a? String
hashes = { 'md5' => '1',
diff --git a/lib/puppet/parser/functions/range.rb b/lib/puppet/parser/functions/range.rb
index d690df7..72c373a 100644
--- a/lib/puppet/parser/functions/range.rb
+++ b/lib/puppet/parser/functions/range.rb
@@ -37,8 +37,7 @@ Will return: [0,2,4,6,8]
EOS
) do |arguments|
- raise(Puppet::ParseError, 'range(): Wrong number of ' +
- 'arguments given (0 for 1)') if arguments.size == 0
+ raise(Puppet::ParseError, 'range(): Wrong number of arguments given (0 for 1)') if arguments.size == 0
if arguments.size > 1
start = arguments[0]
@@ -57,8 +56,7 @@ Will return: [0,2,4,6,8]
type = m[2]
step = 1
elsif value.match(/^.+$/)
- raise(Puppet::ParseError, "range(): Unable to compute range " +
- "from the value: #{value}")
+ raise(Puppet::ParseError, "range(): Unable to compute range from the value: #{value}")
else
raise(Puppet::ParseError, "range(): Unknown range format: #{value}")
end
diff --git a/lib/puppet/parser/functions/regexpescape.rb b/lib/puppet/parser/functions/regexpescape.rb
index 477ee87..2cfa3bb 100644
--- a/lib/puppet/parser/functions/regexpescape.rb
+++ b/lib/puppet/parser/functions/regexpescape.rb
@@ -7,14 +7,12 @@ module Puppet::Parser::Functions
Requires either a single string or an array as an input.
EOS
) do |arguments| # rubocop:disable Style/ClosingParenthesisIndentation
- raise(Puppet::ParseError, 'regexpescape(): Wrong number of arguments ' \
- "given (#{arguments.size} for 1)") if arguments.empty?
+ raise(Puppet::ParseError, "regexpescape(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
value = arguments[0]
unless value.is_a?(Array) || value.is_a?(String)
- raise(Puppet::ParseError, 'regexpescape(): Requires either ' \
- 'array or string to work with')
+ raise(Puppet::ParseError, 'regexpescape(): Requires either array or string to work with')
end
result = if value.is_a?(Array)
diff --git a/lib/puppet/parser/functions/reverse.rb b/lib/puppet/parser/functions/reverse.rb
index 7f1018f..aca98ce 100644
--- a/lib/puppet/parser/functions/reverse.rb
+++ b/lib/puppet/parser/functions/reverse.rb
@@ -8,14 +8,12 @@ Reverses the order of a string or array.
EOS
) do |arguments|
- raise(Puppet::ParseError, "reverse(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "reverse(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
unless value.is_a?(Array) || value.is_a?(String)
- raise(Puppet::ParseError, 'reverse(): Requires either ' +
- 'array or string to work with')
+ raise(Puppet::ParseError, 'reverse(): Requires either array or string to work with')
end
result = value.reverse
diff --git a/lib/puppet/parser/functions/round.rb b/lib/puppet/parser/functions/round.rb
new file mode 100644
index 0000000..489c301
--- /dev/null
+++ b/lib/puppet/parser/functions/round.rb
@@ -0,0 +1,33 @@
+#
+# round.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:round, :type => :rvalue, :doc => <<-EOS
+ Rounds a number to the nearest integer
+
+ *Examples:*
+
+ round(2.9)
+
+ returns: 3
+
+ round(2.4)
+
+ returns: 2
+
+ EOS
+ ) do |args|
+
+ raise Puppet::ParseError, "round(): Wrong number of arguments given #{args.size} for 1" if args.size != 1
+ raise Puppet::ParseError, "round(): Expected a Numeric, got #{args[0].class}" unless args[0].is_a? Numeric
+
+ value = args[0]
+
+ if value >= 0
+ Integer(value + 0.5)
+ else
+ Integer(value - 0.5)
+ end
+ end
+end
diff --git a/lib/puppet/parser/functions/rstrip.rb b/lib/puppet/parser/functions/rstrip.rb
index 0cf8d22..e24abd5 100644
--- a/lib/puppet/parser/functions/rstrip.rb
+++ b/lib/puppet/parser/functions/rstrip.rb
@@ -8,14 +8,12 @@ Strips leading spaces to the right of the string.
EOS
) do |arguments|
- raise(Puppet::ParseError, "rstrip(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "rstrip(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
unless value.is_a?(Array) || value.is_a?(String)
- raise(Puppet::ParseError, 'rstrip(): Requires either ' +
- 'array or string to work with')
+ raise(Puppet::ParseError, 'rstrip(): Requires either array or string to work with')
end
if value.is_a?(Array)
diff --git a/lib/puppet/parser/functions/shell_escape.rb b/lib/puppet/parser/functions/shell_escape.rb
index 447fe35..7306b7c 100644
--- a/lib/puppet/parser/functions/shell_escape.rb
+++ b/lib/puppet/parser/functions/shell_escape.rb
@@ -15,8 +15,7 @@ This function behaves the same as ruby's Shellwords.shellescape() function.
EOS
) do |arguments|
- raise(Puppet::ParseError, "shell_escape(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size != 1
+ raise(Puppet::ParseError, "shell_escape(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
# explicit conversion to string is required for ruby 1.9
string = arguments[0].to_s
diff --git a/lib/puppet/parser/functions/shell_join.rb b/lib/puppet/parser/functions/shell_join.rb
index 05aeb95..682ed8d 100644
--- a/lib/puppet/parser/functions/shell_join.rb
+++ b/lib/puppet/parser/functions/shell_join.rb
@@ -13,8 +13,7 @@ This function behaves the same as ruby's Shellwords.shelljoin() function
EOS
) do |arguments|
- raise(Puppet::ParseError, "shell_join(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size != 1
+ raise(Puppet::ParseError, "shell_join(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
array = arguments[0]
diff --git a/lib/puppet/parser/functions/shell_split.rb b/lib/puppet/parser/functions/shell_split.rb
index 0446448..09e6e78 100644
--- a/lib/puppet/parser/functions/shell_split.rb
+++ b/lib/puppet/parser/functions/shell_split.rb
@@ -12,8 +12,7 @@ This function behaves the same as ruby's Shellwords.shellsplit() function
EOS
) do |arguments|
- raise(Puppet::ParseError, "shell_split(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size != 1
+ raise(Puppet::ParseError, "shell_split(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
string = arguments[0].to_s
diff --git a/lib/puppet/parser/functions/shuffle.rb b/lib/puppet/parser/functions/shuffle.rb
index 30c663d..942cbce 100644
--- a/lib/puppet/parser/functions/shuffle.rb
+++ b/lib/puppet/parser/functions/shuffle.rb
@@ -8,14 +8,12 @@ Randomizes the order of a string or array elements.
EOS
) do |arguments|
- raise(Puppet::ParseError, "shuffle(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "shuffle(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
unless value.is_a?(Array) || value.is_a?(String)
- raise(Puppet::ParseError, 'shuffle(): Requires either ' +
- 'array or string to work with')
+ raise(Puppet::ParseError, 'shuffle(): Requires either array or string to work with')
end
result = value.clone
diff --git a/lib/puppet/parser/functions/size.rb b/lib/puppet/parser/functions/size.rb
index 0d6cc96..b503aa0 100644
--- a/lib/puppet/parser/functions/size.rb
+++ b/lib/puppet/parser/functions/size.rb
@@ -8,11 +8,12 @@ Returns the number of elements in a string, an array or a hash
EOS
) do |arguments|
- raise(Puppet::ParseError, "size(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "size(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
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
@@ -26,8 +27,7 @@ Returns the number of elements in a string, an array or a hash
#
Float(item)
- raise(Puppet::ParseError, 'size(): Requires either ' +
- 'string, array or hash to work with')
+ raise(Puppet::ParseError, 'size(): Requires either string, array or hash to work with')
rescue ArgumentError
result = item.size
diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb
index cefbe54..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
@@ -9,8 +10,7 @@ Sorts strings and arrays lexically.
) do |arguments|
if (arguments.size != 1) then
- raise(Puppet::ParseError, "sort(): Wrong number of arguments "+
- "given #{arguments.size} for 1")
+ raise(Puppet::ParseError, "sort(): Wrong number of arguments given #{arguments.size} for 1")
end
value = arguments[0]
diff --git a/lib/puppet/parser/functions/squeeze.rb b/lib/puppet/parser/functions/squeeze.rb
index 81fadfd..f5757d1 100644
--- a/lib/puppet/parser/functions/squeeze.rb
+++ b/lib/puppet/parser/functions/squeeze.rb
@@ -9,8 +9,7 @@ Returns a new string where runs of the same character that occur in this set are
) do |arguments|
if ((arguments.size != 2) and (arguments.size != 1)) then
- raise(Puppet::ParseError, "squeeze(): Wrong number of arguments "+
- "given #{arguments.size} for 2 or 1")
+ raise(Puppet::ParseError, "squeeze(): Wrong number of arguments given #{arguments.size} for 2 or 1")
end
item = arguments[0]
diff --git a/lib/puppet/parser/functions/str2bool.rb b/lib/puppet/parser/functions/str2bool.rb
index 472506d..38ad1ce 100644
--- a/lib/puppet/parser/functions/str2bool.rb
+++ b/lib/puppet/parser/functions/str2bool.rb
@@ -10,8 +10,7 @@ like: 0, F,f, N,n, false, FALSE, no to 'false'.
EOS
) do |arguments|
- raise(Puppet::ParseError, "str2bool(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "str2bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
string = arguments[0]
@@ -21,8 +20,7 @@ like: 0, F,f, N,n, false, FALSE, no to 'false'.
end
unless string.is_a?(String)
- raise(Puppet::ParseError, 'str2bool(): Requires ' +
- 'string to work with')
+ raise(Puppet::ParseError, 'str2bool(): Requires string to work with')
end
# We consider all the yes, no, y, n and so on too ...
diff --git a/lib/puppet/parser/functions/str2saltedsha512.rb b/lib/puppet/parser/functions/str2saltedsha512.rb
index 7fe7b01..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
@@ -12,14 +13,12 @@ manifests as a valid password attribute.
) do |arguments|
require 'digest/sha2'
- raise(Puppet::ParseError, "str2saltedsha512(): Wrong number of arguments " +
- "passed (#{arguments.size} but we require 1)") if arguments.size != 1
+ raise(Puppet::ParseError, "str2saltedsha512(): Wrong number of arguments passed (#{arguments.size} but we require 1)") if arguments.size != 1
password = arguments[0]
unless password.is_a?(String)
- raise(Puppet::ParseError, 'str2saltedsha512(): Requires a ' +
- "String argument, you passed: #{password.class}")
+ raise(Puppet::ParseError, "str2saltedsha512(): Requires a String argument, you passed: #{password.class}")
end
seedint = rand(2**31 - 1)
diff --git a/lib/puppet/parser/functions/strftime.rb b/lib/puppet/parser/functions/strftime.rb
index 0b52ade..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
@@ -71,13 +72,11 @@ To return the date:
) do |arguments|
# Technically we support two arguments but only first is mandatory ...
- raise(Puppet::ParseError, "strftime(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "strftime(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
format = arguments[0]
- raise(Puppet::ParseError, 'strftime(): You must provide ' +
- 'format for evaluation') if format.empty?
+ raise(Puppet::ParseError, 'strftime(): You must provide format for evaluation') if format.empty?
# The Time Zone argument is optional ...
time_zone = arguments[1] if arguments[1]
diff --git a/lib/puppet/parser/functions/strip.rb b/lib/puppet/parser/functions/strip.rb
index 3fac47d..9e8366f 100644
--- a/lib/puppet/parser/functions/strip.rb
+++ b/lib/puppet/parser/functions/strip.rb
@@ -15,14 +15,12 @@ Would result in: "aaa"
EOS
) do |arguments|
- raise(Puppet::ParseError, "strip(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "strip(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
unless value.is_a?(Array) || value.is_a?(String)
- raise(Puppet::ParseError, 'strip(): Requires either ' +
- 'array or string to work with')
+ raise(Puppet::ParseError, 'strip(): Requires either array or string to work with')
end
if value.is_a?(Array)
diff --git a/lib/puppet/parser/functions/suffix.rb b/lib/puppet/parser/functions/suffix.rb
index 2908434..7c5057d 100644
--- a/lib/puppet/parser/functions/suffix.rb
+++ b/lib/puppet/parser/functions/suffix.rb
@@ -16,8 +16,7 @@ Will return: ['ap','bp','cp']
) do |arguments|
# Technically we support two arguments but only first is mandatory ...
- raise(Puppet::ParseError, "suffix(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "suffix(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
enumerable = arguments[0]
diff --git a/lib/puppet/parser/functions/swapcase.rb b/lib/puppet/parser/functions/swapcase.rb
index eb7fe13..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
@@ -14,14 +15,12 @@ Would result in: "AbCd"
EOS
) do |arguments|
- raise(Puppet::ParseError, "swapcase(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "swapcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
unless value.is_a?(Array) || value.is_a?(String)
- raise(Puppet::ParseError, 'swapcase(): Requires either ' +
- 'array or string to work with')
+ raise(Puppet::ParseError, 'swapcase(): Requires either array or string to work with')
end
if value.is_a?(Array)
diff --git a/lib/puppet/parser/functions/time.rb b/lib/puppet/parser/functions/time.rb
index c574747..d7780c8 100644
--- a/lib/puppet/parser/functions/time.rb
+++ b/lib/puppet/parser/functions/time.rb
@@ -18,8 +18,7 @@ Will return something like: 1311972653
time_zone = arguments[0] if arguments[0]
if (arguments.size != 0) and (arguments.size != 1) then
- raise(Puppet::ParseError, "time(): Wrong number of arguments "+
- "given #{arguments.size} for 0 or 1")
+ raise(Puppet::ParseError, "time(): Wrong number of arguments given #{arguments.size} for 0 or 1")
end
time = Time.new
diff --git a/lib/puppet/parser/functions/to_bytes.rb b/lib/puppet/parser/functions/to_bytes.rb
index df490ea..bf72503 100644
--- a/lib/puppet/parser/functions/to_bytes.rb
+++ b/lib/puppet/parser/functions/to_bytes.rb
@@ -7,8 +7,7 @@ module Puppet::Parser::Functions
EOS
) do |arguments|
- raise(Puppet::ParseError, "to_bytes(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size != 1
+ raise(Puppet::ParseError, "to_bytes(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
arg = arguments[0]
diff --git a/lib/puppet/parser/functions/type3x.rb b/lib/puppet/parser/functions/type3x.rb
index 0800b4a..b17380e 100644
--- a/lib/puppet/parser/functions/type3x.rb
+++ b/lib/puppet/parser/functions/type3x.rb
@@ -16,8 +16,7 @@ Returns the type when passed a value. Type can be one of:
* boolean
EOS
) do |args|
- raise(Puppet::ParseError, "type3x(): Wrong number of arguments " +
- "given (#{args.size} for 1)") if args.size < 1
+ raise(Puppet::ParseError, "type3x(): Wrong number of arguments given (#{args.size} for 1)") if args.size < 1
value = args[0]
diff --git a/lib/puppet/parser/functions/union.rb b/lib/puppet/parser/functions/union.rb
index 6c5bb83..abe2dc8 100644
--- a/lib/puppet/parser/functions/union.rb
+++ b/lib/puppet/parser/functions/union.rb
@@ -15,8 +15,7 @@ Would return: ["a","b","c","d"]
) do |arguments|
# Check that 2 or more arguments have been given ...
- raise(Puppet::ParseError, "union(): Wrong number of arguments " +
- "given (#{arguments.size} for < 2)") if arguments.size < 2
+ raise(Puppet::ParseError, "union(): Wrong number of arguments given (#{arguments.size} for < 2)") if arguments.size < 2
arguments.each do |argument|
raise(Puppet::ParseError, 'union(): Every parameter must be an array') unless argument.is_a?(Array)
diff --git a/lib/puppet/parser/functions/unique.rb b/lib/puppet/parser/functions/unique.rb
index cf770f3..1e2a895 100644
--- a/lib/puppet/parser/functions/unique.rb
+++ b/lib/puppet/parser/functions/unique.rb
@@ -24,14 +24,16 @@ This returns:
EOS
) do |arguments|
- raise(Puppet::ParseError, "unique(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ if Puppet::Util::Package.versioncmp(Puppet.version, '5.0.0') >= 0
+ function_deprecation([:unique, 'This method is deprecated, please use the core puppet unique function. There is further documentation for the function in the release notes of Puppet 5.0.'])
+ end
+
+ raise(Puppet::ParseError, "unique(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
unless value.is_a?(Array) || value.is_a?(String)
- raise(Puppet::ParseError, 'unique(): Requires either ' +
- 'array or string to work with')
+ raise(Puppet::ParseError, 'unique(): Requires either array or string to work with')
end
result = value.clone
diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb
index 44b3bcd..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
@@ -16,14 +17,12 @@ Will return:
EOS
) do |arguments|
- raise(Puppet::ParseError, "upcase(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size != 1
+ raise(Puppet::ParseError, "upcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
value = arguments[0]
unless value.is_a?(Array) || value.is_a?(Hash) || value.respond_to?(:upcase)
- raise(Puppet::ParseError, 'upcase(): Requires an ' +
- 'array, hash or object that responds to upcase in order to work')
+ raise(Puppet::ParseError, 'upcase(): Requires an array, hash or object that responds to upcase in order to work')
end
if value.is_a?(Array)
diff --git a/lib/puppet/parser/functions/uriescape.rb b/lib/puppet/parser/functions/uriescape.rb
index 45bbed2..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'
@@ -10,14 +11,12 @@ module Puppet::Parser::Functions
EOS
) do |arguments|
- raise(Puppet::ParseError, "uriescape(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "uriescape(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
unless value.is_a?(Array) || value.is_a?(String)
- raise(Puppet::ParseError, 'uriescape(): Requires either ' +
- 'array or string to work with')
+ raise(Puppet::ParseError, 'uriescape(): Requires either array or string to work with')
end
if value.is_a?(Array)
diff --git a/lib/puppet/parser/functions/validate_domain_name.rb b/lib/puppet/parser/functions/validate_domain_name.rb
new file mode 100644
index 0000000..c3fad78
--- /dev/null
+++ b/lib/puppet/parser/functions/validate_domain_name.rb
@@ -0,0 +1,39 @@
+module Puppet::Parser::Functions
+ newfunction(:validate_domain_name, :doc => <<-ENDHEREDOC
+ Validate that all values passed are syntactically correct domain names.
+ Fail compilation if any value fails this check.
+
+ The following values will pass:
+
+ $my_domain_name = 'server.domain.tld'
+ validate_domain_name($my_domain_name)
+ validate_domain_name('domain.tld', 'puppet.com', $my_domain_name)
+
+ The following values will fail, causing compilation to abort:
+
+ validate_domain_name(1)
+ validate_domain_name(true)
+ validate_domain_name('invalid domain')
+ validate_domain_name('-foo.example.com')
+ validate_domain_name('www.example.2com')
+
+ ENDHEREDOC
+ ) do |args|
+
+ rescuable_exceptions = [ArgumentError]
+
+ if args.empty?
+ raise Puppet::ParseError, "validate_domain_name(): wrong number of arguments (#{args.length}; must be > 0)"
+ end
+
+ args.each do |arg|
+ raise Puppet::ParseError, "#{arg.inspect} is not a string." unless arg.is_a?(String)
+
+ begin
+ raise Puppet::ParseError, "#{arg.inspect} is not a syntactically correct domain name" unless function_is_domain_name([arg])
+ rescue *rescuable_exceptions
+ raise Puppet::ParseError, "#{arg.inspect} is not a syntactically correct domain name"
+ end
+ end
+ end
+end
diff --git a/lib/puppet/parser/functions/values.rb b/lib/puppet/parser/functions/values.rb
index 1606756..0ca236c 100644
--- a/lib/puppet/parser/functions/values.rb
+++ b/lib/puppet/parser/functions/values.rb
@@ -21,8 +21,7 @@ This example would return:
EOS
) do |arguments|
- raise(Puppet::ParseError, "values(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ raise(Puppet::ParseError, "values(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
hash = arguments[0]
diff --git a/lib/puppet/parser/functions/values_at.rb b/lib/puppet/parser/functions/values_at.rb
index f350f53..04a3d1a 100644
--- a/lib/puppet/parser/functions/values_at.rb
+++ b/lib/puppet/parser/functions/values_at.rb
@@ -29,8 +29,7 @@ Would return ['a','c','d'].
EOS
) do |arguments|
- raise(Puppet::ParseError, "values_at(): Wrong number of " +
- "arguments given (#{arguments.size} for 2)") if arguments.size < 2
+ raise(Puppet::ParseError, "values_at(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size < 2
array = arguments.shift
@@ -41,8 +40,7 @@ Would return ['a','c','d'].
indices = [arguments.shift].flatten() # Get them all ... Pokemon ...
if not indices or indices.empty?
- raise(Puppet::ParseError, 'values_at(): You must provide ' +
- 'at least one positive index to collect')
+ raise(Puppet::ParseError, 'values_at(): You must provide at least one positive index to collect')
end
result = []
@@ -57,11 +55,9 @@ Would return ['a','c','d'].
type = m[2]
if start > stop
- raise(Puppet::ParseError, 'values_at(): Stop index in ' +
- 'given indices range is smaller than the start index')
+ raise(Puppet::ParseError, 'values_at(): Stop index in given indices range is smaller than the start index')
elsif stop > array.size - 1 # First element is at index 0 is it not?
- raise(Puppet::ParseError, 'values_at(): Stop index in ' +
- 'given indices range exceeds array size')
+ raise(Puppet::ParseError, 'values_at(): Stop index in given indices range exceeds array size')
end
range = case type
@@ -73,16 +69,14 @@ Would return ['a','c','d'].
else
# Only positive numbers allowed in this case ...
if not i.match(/^\d+$/)
- raise(Puppet::ParseError, 'values_at(): Unknown format ' +
- 'of given index')
+ raise(Puppet::ParseError, 'values_at(): Unknown format of given index')
end
# In Puppet numbers are often string-encoded ...
i = i.to_i
if i > array.size - 1 # Same story. First element is at index 0 ...
- raise(Puppet::ParseError, 'values_at(): Given index ' +
- 'exceeds array size')
+ raise(Puppet::ParseError, 'values_at(): Given index exceeds array size')
end
indices_list << i
diff --git a/lib/puppet/parser/functions/zip.rb b/lib/puppet/parser/functions/zip.rb
index 3074f28..13e24b6 100644
--- a/lib/puppet/parser/functions/zip.rb
+++ b/lib/puppet/parser/functions/zip.rb
@@ -17,8 +17,7 @@ Would result in:
) do |arguments|
# Technically we support three arguments but only first is mandatory ...
- raise(Puppet::ParseError, "zip(): Wrong number of arguments " +
- "given (#{arguments.size} for 2)") if arguments.size < 2
+ raise(Puppet::ParseError, "zip(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size < 2
a = arguments[0]
b = arguments[1]