From 76d0ec471d074a07cc2cece3963dd9c8c2d18aeb Mon Sep 17 00:00:00 2001 From: Emerson Prado Date: Fri, 3 Feb 2017 17:00:03 -0200 Subject: Include routine to converge ensure values 'present' and 'installed' If user declares ensure_package concurrently with ensure values 'present' and 'installed', function fails as if values were different Change causes function to interpret ensure => 'installed' as 'present', effectively elliminating the error Also works if user doesn't specify ensure value, since 'present' is the default --- lib/puppet/parser/functions/ensure_packages.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/ensure_packages.rb b/lib/puppet/parser/functions/ensure_packages.rb index 439af1e..93dd4fb 100644 --- a/lib/puppet/parser/functions/ensure_packages.rb +++ b/lib/puppet/parser/functions/ensure_packages.rb @@ -20,6 +20,9 @@ third argument to the ensure_resource() function. 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,6 +34,9 @@ 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 -- cgit v1.2.3 From 6092ede8d86746038df4a367191d232003652c55 Mon Sep 17 00:00:00 2001 From: Sascha Spreitzer Date: Sat, 4 Feb 2017 13:30:59 +0100 Subject: Add glob function --- lib/puppet/parser/functions/glob.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lib/puppet/parser/functions/glob.rb (limited to 'lib/puppet/parser/functions') 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 -- cgit v1.2.3 From e2a8690fa6a41e481ae14e9642f4f5efeaa2d681 Mon Sep 17 00:00:00 2001 From: Eric Putnam Date: Tue, 28 Feb 2017 15:31:36 -0800 Subject: (MODULES-4473) join strings for i18n parser This commit joins all strings that are split over two lines with a plus, backslash, or double less than so that our magical i18n parser can wave over the module and mark every ruby string with our i18n function. --- lib/puppet/parser/functions/abs.rb | 6 ++---- lib/puppet/parser/functions/any2bool.rb | 3 +-- lib/puppet/parser/functions/assert_private.rb | 3 +-- lib/puppet/parser/functions/bool2num.rb | 3 +-- lib/puppet/parser/functions/bool2str.rb | 3 +-- lib/puppet/parser/functions/camelcase.rb | 6 ++---- lib/puppet/parser/functions/capitalize.rb | 6 ++---- lib/puppet/parser/functions/ceiling.rb | 9 +++------ lib/puppet/parser/functions/chomp.rb | 6 ++---- lib/puppet/parser/functions/chop.rb | 6 ++---- lib/puppet/parser/functions/clamp.rb | 3 +-- lib/puppet/parser/functions/concat.rb | 3 +-- lib/puppet/parser/functions/count.rb | 3 +-- lib/puppet/parser/functions/delete.rb | 6 ++---- lib/puppet/parser/functions/delete_at.rb | 9 +++------ lib/puppet/parser/functions/delete_regex.rb | 8 +++----- lib/puppet/parser/functions/delete_undef_values.rb | 7 ++----- lib/puppet/parser/functions/delete_values.rb | 7 ++----- lib/puppet/parser/functions/deprecation.rb | 3 +-- lib/puppet/parser/functions/difference.rb | 3 +-- lib/puppet/parser/functions/dig44.rb | 9 +++------ lib/puppet/parser/functions/downcase.rb | 6 ++---- lib/puppet/parser/functions/empty.rb | 6 ++---- lib/puppet/parser/functions/enclose_ipv6.rb | 9 +++------ lib/puppet/parser/functions/ensure_packages.rb | 5 ++--- lib/puppet/parser/functions/flatten.rb | 3 +-- lib/puppet/parser/functions/floor.rb | 9 +++------ lib/puppet/parser/functions/fqdn_rotate.rb | 6 ++---- lib/puppet/parser/functions/grep.rb | 3 +-- lib/puppet/parser/functions/has_interface_with.rb | 3 +-- lib/puppet/parser/functions/has_ip_address.rb | 3 +-- lib/puppet/parser/functions/has_ip_network.rb | 3 +-- lib/puppet/parser/functions/hash.rb | 6 ++---- lib/puppet/parser/functions/intersection.rb | 3 +-- lib/puppet/parser/functions/is_array.rb | 3 +-- lib/puppet/parser/functions/is_bool.rb | 3 +-- lib/puppet/parser/functions/is_domain_name.rb | 3 +-- lib/puppet/parser/functions/is_email_address.rb | 3 +-- lib/puppet/parser/functions/is_float.rb | 3 +-- lib/puppet/parser/functions/is_function_available.rb | 3 +-- lib/puppet/parser/functions/is_hash.rb | 3 +-- lib/puppet/parser/functions/is_integer.rb | 3 +-- lib/puppet/parser/functions/is_ip_address.rb | 3 +-- lib/puppet/parser/functions/is_ipv4_address.rb | 3 +-- lib/puppet/parser/functions/is_ipv6_address.rb | 3 +-- lib/puppet/parser/functions/is_mac_address.rb | 3 +-- lib/puppet/parser/functions/is_numeric.rb | 3 +-- lib/puppet/parser/functions/is_string.rb | 3 +-- lib/puppet/parser/functions/join.rb | 3 +-- lib/puppet/parser/functions/join_keys_to_values.rb | 9 +++------ lib/puppet/parser/functions/keys.rb | 3 +-- lib/puppet/parser/functions/lstrip.rb | 6 ++---- lib/puppet/parser/functions/max.rb | 3 +-- lib/puppet/parser/functions/member.rb | 6 ++---- lib/puppet/parser/functions/min.rb | 3 +-- lib/puppet/parser/functions/num2bool.rb | 3 +-- lib/puppet/parser/functions/prefix.rb | 3 +-- lib/puppet/parser/functions/range.rb | 6 ++---- lib/puppet/parser/functions/regexpescape.rb | 6 ++---- lib/puppet/parser/functions/reverse.rb | 6 ++---- lib/puppet/parser/functions/rstrip.rb | 6 ++---- lib/puppet/parser/functions/shell_escape.rb | 3 +-- lib/puppet/parser/functions/shell_join.rb | 3 +-- lib/puppet/parser/functions/shell_split.rb | 3 +-- lib/puppet/parser/functions/shuffle.rb | 6 ++---- lib/puppet/parser/functions/size.rb | 6 ++---- lib/puppet/parser/functions/sort.rb | 3 +-- lib/puppet/parser/functions/squeeze.rb | 3 +-- lib/puppet/parser/functions/str2bool.rb | 6 ++---- lib/puppet/parser/functions/str2saltedsha512.rb | 6 ++---- lib/puppet/parser/functions/strftime.rb | 6 ++---- lib/puppet/parser/functions/strip.rb | 6 ++---- lib/puppet/parser/functions/suffix.rb | 3 +-- lib/puppet/parser/functions/swapcase.rb | 6 ++---- lib/puppet/parser/functions/time.rb | 3 +-- lib/puppet/parser/functions/to_bytes.rb | 3 +-- lib/puppet/parser/functions/type3x.rb | 3 +-- lib/puppet/parser/functions/union.rb | 3 +-- lib/puppet/parser/functions/unique.rb | 6 ++---- lib/puppet/parser/functions/upcase.rb | 6 ++---- lib/puppet/parser/functions/uriescape.rb | 6 ++---- lib/puppet/parser/functions/values.rb | 3 +-- lib/puppet/parser/functions/values_at.rb | 18 ++++++------------ lib/puppet/parser/functions/zip.rb | 3 +-- 84 files changed, 132 insertions(+), 264 deletions(-) (limited to 'lib/puppet/parser/functions') 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/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..dd67915 100644 --- a/lib/puppet/parser/functions/camelcase.rb +++ b/lib/puppet/parser/functions/camelcase.rb @@ -8,15 +8,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..08f1c30 100644 --- a/lib/puppet/parser/functions/capitalize.rb +++ b/lib/puppet/parser/functions/capitalize.rb @@ -9,14 +9,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) 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/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..e2c32db 100644 --- a/lib/puppet/parser/functions/delete_regex.rb +++ b/lib/puppet/parser/functions/delete_regex.rb @@ -12,7 +12,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 +25,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 +33,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..7a16afc 100644 --- a/lib/puppet/parser/functions/downcase.rb +++ b/lib/puppet/parser/functions/downcase.rb @@ -8,14 +8,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..504273d 100644 --- a/lib/puppet/parser/functions/ensure_packages.rb +++ b/lib/puppet/parser/functions/ensure_packages.rb @@ -11,9 +11,8 @@ 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 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/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/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/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..507c72a 100644 --- a/lib/puppet/parser/functions/size.rb +++ b/lib/puppet/parser/functions/size.rb @@ -8,8 +8,7 @@ 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] @@ -26,8 +25,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..7c8a1c9 100644 --- a/lib/puppet/parser/functions/sort.rb +++ b/lib/puppet/parser/functions/sort.rb @@ -9,8 +9,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..7e98d9f 100644 --- a/lib/puppet/parser/functions/str2saltedsha512.rb +++ b/lib/puppet/parser/functions/str2saltedsha512.rb @@ -12,14 +12,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..f0dc5cf 100644 --- a/lib/puppet/parser/functions/strftime.rb +++ b/lib/puppet/parser/functions/strftime.rb @@ -71,13 +71,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..8158f3c 100644 --- a/lib/puppet/parser/functions/swapcase.rb +++ b/lib/puppet/parser/functions/swapcase.rb @@ -14,14 +14,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..b57431d 100644 --- a/lib/puppet/parser/functions/unique.rb +++ b/lib/puppet/parser/functions/unique.rb @@ -24,14 +24,12 @@ This returns: EOS ) do |arguments| - raise(Puppet::ParseError, "unique(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") if arguments.size < 1 + 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..9f09110 100644 --- a/lib/puppet/parser/functions/upcase.rb +++ b/lib/puppet/parser/functions/upcase.rb @@ -16,14 +16,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..8296d8b 100644 --- a/lib/puppet/parser/functions/uriescape.rb +++ b/lib/puppet/parser/functions/uriescape.rb @@ -10,14 +10,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/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] -- cgit v1.2.3 From 6077460d9b2a6012dee3eb02ae43a9c6060e39be Mon Sep 17 00:00:00 2001 From: mbakerbp Date: Fri, 10 Mar 2017 07:20:16 +0800 Subject: Should only try to aplpy the resource if it not defined --- lib/puppet/parser/functions/ensure_packages.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/ensure_packages.rb b/lib/puppet/parser/functions/ensure_packages.rb index 439af1e..6c59b20 100644 --- a/lib/puppet/parser/functions/ensure_packages.rb +++ b/lib/puppet/parser/functions/ensure_packages.rb @@ -37,7 +37,9 @@ third argument to the ensure_resource() function. Puppet::Parser::Functions.function(:ensure_resource) packages.each { |package_name| + if !findresource("Package[#{package_name}]") function_ensure_resource(['package', package_name, defaults ]) + end } end end -- cgit v1.2.3 From 2d9a94ebe827d88222c46af33416ae333ae102b2 Mon Sep 17 00:00:00 2001 From: Helen Campbell Date: Mon, 13 Mar 2017 14:09:29 +0000 Subject: Addition of new length function --- lib/puppet/parser/functions/size.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/size.rb b/lib/puppet/parser/functions/size.rb index 0d6cc96..cae4368 100644 --- a/lib/puppet/parser/functions/size.rb +++ b/lib/puppet/parser/functions/size.rb @@ -13,6 +13,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 -- cgit v1.2.3 From 2c138deb4fa9c1d9e1e7b1daa506d85eb3aa1666 Mon Sep 17 00:00:00 2001 From: Helen Campbell Date: Wed, 15 Mar 2017 11:13:45 +0000 Subject: (FM-6051) Adds comments to warn for UTF8 incompatibility --- lib/puppet/parser/functions/base64.rb | 3 +++ lib/puppet/parser/functions/camelcase.rb | 1 + lib/puppet/parser/functions/capitalize.rb | 3 +-- lib/puppet/parser/functions/delete_regex.rb | 3 ++- lib/puppet/parser/functions/downcase.rb | 1 + lib/puppet/parser/functions/pw_hash.rb | 3 +++ lib/puppet/parser/functions/sort.rb | 3 ++- lib/puppet/parser/functions/str2saltedsha512.rb | 3 ++- lib/puppet/parser/functions/strftime.rb | 3 ++- lib/puppet/parser/functions/swapcase.rb | 1 + lib/puppet/parser/functions/upcase.rb | 3 ++- lib/puppet/parser/functions/uriescape.rb | 1 + 12 files changed, 21 insertions(+), 7 deletions(-) (limited to 'lib/puppet/parser/functions') 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/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' -- cgit v1.2.3 From 4f19c27137d6de29ae63bf73115f1e8fefd00b03 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 25 Apr 2017 12:08:46 -0700 Subject: (PE-20308) Pass a literal type and not a string to findresource - `defined_with_params` calls `findresource(reference.to_s)` - `findresource` is https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/parser/compiler.rb#L407 and points to https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource/catalog.rb#L352 - This calls `Puppet::Resource.new` with the type https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource/catalog.rb#L366 - This ends up calling `resource_type` via https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource.rb#L317-L319 and that ends up declaring the type via the autoloader api at https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource.rb#L390 - But why does the autoloader API fail to find it in the current environment? - Okay, so when the autoloader is trying to find the type, it uses the typeloader to look it up in the current environment https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/metatype/manager.rb#L171 - this calls `get_file` and `mark_loaded` https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/util/autoload.rb#L64-L67 Suggested workaround is to pass a literal type instead of a string to `findresource` to fix in stdlib, and also to fix loading/requiring of type in core puppet. This seems to affect more recent versions of puppet, so fallback to original behavior on pre-4.5 --- lib/puppet/parser/functions/defined_with_params.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/defined_with_params.rb b/lib/puppet/parser/functions/defined_with_params.rb index 99687ae..f2c6230 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.5.0') >= 0 + # Workaround for PE-20308 + if reference.is_a?(String) + type_name, title = Puppet::Resource.type_and_title(reference, nil) + type = Puppet::Type.type(type_name) + 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? -- cgit v1.2.3 From ccabfd3e1f4617a583546efaa4303bc24e53b89c Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Wed, 26 Apr 2017 09:18:43 -0700 Subject: (PE-20308) Correct boundary for 4.5 vs 4.6 --- lib/puppet/parser/functions/defined_with_params.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/defined_with_params.rb b/lib/puppet/parser/functions/defined_with_params.rb index f2c6230..7f1fe93 100644 --- a/lib/puppet/parser/functions/defined_with_params.rb +++ b/lib/puppet/parser/functions/defined_with_params.rb @@ -25,7 +25,7 @@ ENDOFDOC end ret = false - if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 + 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) -- cgit v1.2.3 From 32e5a87bb3b8c1d0fabc1e8c2687e4a750173cb5 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Fri, 28 Apr 2017 15:48:56 -0700 Subject: (PE-20308) Also fix defined type strings & references --- lib/puppet/parser/functions/defined_with_params.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/defined_with_params.rb b/lib/puppet/parser/functions/defined_with_params.rb index 7f1fe93..e0d4e37 100644 --- a/lib/puppet/parser/functions/defined_with_params.rb +++ b/lib/puppet/parser/functions/defined_with_params.rb @@ -29,7 +29,7 @@ ENDOFDOC # Workaround for PE-20308 if reference.is_a?(String) type_name, title = Puppet::Resource.type_and_title(reference, nil) - type = Puppet::Type.type(type_name) + type = Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_resource_type_or_class(find_global_scope, type_name) elsif reference.is_a?(Puppet::Resource) type = reference.resource_type title = reference.title -- cgit v1.2.3 From 5ad49ebaecbdbc6faa58282c45aad1c46d4d7f2c Mon Sep 17 00:00:00 2001 From: Alex Dacre Date: Wed, 26 Apr 2017 12:47:29 +0100 Subject: Fix issue where the following causes obscure catalog compilation errors: ``` file { '/tmp/somefile': ensure => 'file', } File['/tmp/somefile'] -> Package <| |> ensure_packages($somearray) ``` If $somearray is undefined or one of the elements contains an empty string, an error like the following is thrown: Could not find resource 'Package[]' for relationship from 'File[/tmp/somefile]' on node $::fqdn --- lib/puppet/parser/functions/ensure_packages.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/ensure_packages.rb b/lib/puppet/parser/functions/ensure_packages.rb index 17942b8..034f997 100644 --- a/lib/puppet/parser/functions/ensure_packages.rb +++ b/lib/puppet/parser/functions/ensure_packages.rb @@ -36,6 +36,7 @@ third argument to the ensure_resource() function. 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 -- cgit v1.2.3 From 7b8b9f8aff906460dcac5d84ef8f44449b8ce395 Mon Sep 17 00:00:00 2001 From: Thomas Hallgren Date: Wed, 14 Jun 2017 10:34:13 +0200 Subject: (MODULES-5095) Workaround for PUP-7650 This commit adds a simple workaround for the problem described in PUP-7650. The workaround is harmless and can remain in place regardless of if the fix for PUP-7650 is in place or not. --- lib/puppet/parser/functions/defined_with_params.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/defined_with_params.rb b/lib/puppet/parser/functions/defined_with_params.rb index e0d4e37..c45a9df 100644 --- a/lib/puppet/parser/functions/defined_with_params.rb +++ b/lib/puppet/parser/functions/defined_with_params.rb @@ -29,7 +29,7 @@ ENDOFDOC # 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) + 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 -- cgit v1.2.3 From fe7ccd8b89556cc6cc1f5ea7f58b5ac2aedb23ec Mon Sep 17 00:00:00 2001 From: Frank de Jong Date: Sat, 8 Jul 2017 09:43:40 +0200 Subject: Add validate_domain_name function --- .../parser/functions/validate_domain_name.rb | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib/puppet/parser/functions/validate_domain_name.rb (limited to 'lib/puppet/parser/functions') 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 -- cgit v1.2.3 From 33922a4ec7a8c204a17e0c3017eea21faa220f39 Mon Sep 17 00:00:00 2001 From: tphoney Date: Fri, 14 Jul 2017 10:14:04 +0100 Subject: FM-6239 clean up for puppet 5.tests/deprecation --- lib/puppet/parser/functions/unique.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/unique.rb b/lib/puppet/parser/functions/unique.rb index b57431d..1e2a895 100644 --- a/lib/puppet/parser/functions/unique.rb +++ b/lib/puppet/parser/functions/unique.rb @@ -24,6 +24,10 @@ This returns: EOS ) do |arguments| + 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] -- cgit v1.2.3 From 42d4ea7af9197f77a3062727eb166c719ca6296a Mon Sep 17 00:00:00 2001 From: Eric Putnam Date: Fri, 7 Jul 2017 17:30:17 -0700 Subject: (MODULES-4908) adds support for sensitive data type to pw_hash Also includes a small fix to integer_spec so tests pass. --- lib/puppet/parser/functions/pw_hash.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/pw_hash.rb b/lib/puppet/parser/functions/pw_hash.rb index d99ee5b..0deeb3a 100644 --- a/lib/puppet/parser/functions/pw_hash.rb +++ b/lib/puppet/parser/functions/pw_hash.rb @@ -27,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 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', -- cgit v1.2.3 From 772a2d2f406b65ef65161a04455865b37a1c8456 Mon Sep 17 00:00:00 2001 From: Eric Putnam Date: Thu, 27 Jul 2017 09:24:52 -0700 Subject: (maint) move/rewrite round() as ruby function --- lib/puppet/parser/functions/round.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/puppet/parser/functions/round.rb (limited to 'lib/puppet/parser/functions') 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 -- cgit v1.2.3 From b1071e486578c63a4d93911585e02be44e9efbed Mon Sep 17 00:00:00 2001 From: Eric Putnam Date: Mon, 28 Aug 2017 09:34:27 -0700 Subject: (MODULES-5546) add check for pw_hash Older versions of Puppet end up choking on the sensitive data type check in the pw_hash function added in 42d4ea7af9197f77a3062727eb166c719ca6296a. this adds a check for the Sensitive class and then the type of the arg, so that if the class has not been declared, it will just move on. --- lib/puppet/parser/functions/pw_hash.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/pw_hash.rb b/lib/puppet/parser/functions/pw_hash.rb index 0deeb3a..adcc719 100644 --- a/lib/puppet/parser/functions/pw_hash.rb +++ b/lib/puppet/parser/functions/pw_hash.rb @@ -28,7 +28,7 @@ Puppet::Parser::Functions::newfunction( 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 arg.is_a? Puppet::Pops::Types::PSensitiveType::Sensitive + if (defined? Puppet::Pops::Types::PSensitiveType::Sensitive) && (arg.is_a? Puppet::Pops::Types::PSensitiveType::Sensitive) arg.unwrap else arg -- cgit v1.2.3