diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/facter/facter_dot_d.rb | 2 | ||||
-rw-r--r-- | lib/puppet/parser/functions/concat.rb | 10 | ||||
-rw-r--r-- | lib/puppet/parser/functions/ensure_packages.rb | 16 | ||||
-rw-r--r-- | lib/puppet/parser/functions/floor.rb | 7 | ||||
-rw-r--r-- | lib/puppet/parser/functions/is_domain_name.rb | 3 | ||||
-rw-r--r-- | lib/puppet/parser/functions/is_float.rb | 3 | ||||
-rw-r--r-- | lib/puppet/parser/functions/is_function_available.rb | 3 |
7 files changed, 36 insertions, 8 deletions
diff --git a/lib/facter/facter_dot_d.rb b/lib/facter/facter_dot_d.rb index e414b20..2c096b0 100644 --- a/lib/facter/facter_dot_d.rb +++ b/lib/facter/facter_dot_d.rb @@ -40,7 +40,7 @@ class Facter::Util::DotD def txt_parser(file) File.readlines(file).each do |line| - if line =~ /^(.+)=(.+)$/ + if line =~ /^([^=]+)=(.+)$/ var = $1; val = $2 Facter.add(var) do diff --git a/lib/puppet/parser/functions/concat.rb b/lib/puppet/parser/functions/concat.rb index c86aa00..6c86382 100644 --- a/lib/puppet/parser/functions/concat.rb +++ b/lib/puppet/parser/functions/concat.rb @@ -23,12 +23,16 @@ Would result in: a = arguments[0] b = arguments[1] - # Check that both args are arrays. - unless a.is_a?(Array) and b.is_a?(Array) + # Check that the first parameter is an array + unless a.is_a?(Array) raise(Puppet::ParseError, 'concat(): Requires array to work with') end - result = a.concat(b) + if b.is_a?(Array) + result = a.concat(b) + else + result = a << b + end return result end diff --git a/lib/puppet/parser/functions/ensure_packages.rb b/lib/puppet/parser/functions/ensure_packages.rb index 1e0f225..f1da4aa 100644 --- a/lib/puppet/parser/functions/ensure_packages.rb +++ b/lib/puppet/parser/functions/ensure_packages.rb @@ -5,19 +5,29 @@ module Puppet::Parser::Functions newfunction(:ensure_packages, :type => :statement, :doc => <<-EOS Takes a list of packages and only installs them if they don't already exist. +It optionally takes a hash as a second parameter that will be passed as the +third argument to the ensure_resource() function. EOS ) do |arguments| - if arguments.size != 1 + if arguments.size > 2 or arguments.size == 0 raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") + "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 packages = Array(arguments[0]) + if arguments[1] + defaults = { 'ensure' => 'present' }.merge(arguments[1]) + else + defaults = { 'ensure' => 'present' } + end + Puppet::Parser::Functions.function(:ensure_resource) packages.each { |package_name| - function_ensure_resource(['package', package_name, {'ensure' => 'present' } ]) + function_ensure_resource(['package', package_name, defaults ]) } end end diff --git a/lib/puppet/parser/functions/floor.rb b/lib/puppet/parser/functions/floor.rb index a401923..9a6f014 100644 --- a/lib/puppet/parser/functions/floor.rb +++ b/lib/puppet/parser/functions/floor.rb @@ -8,7 +8,12 @@ module Puppet::Parser::Functions raise(Puppet::ParseError, "floor(): Wrong number of arguments " + "given (#{arguments.size} for 1)") if arguments.size != 1 - arg = arguments[0] + begin + arg = Float(arguments[0]) + rescue TypeError, ArgumentError => e + 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 diff --git a/lib/puppet/parser/functions/is_domain_name.rb b/lib/puppet/parser/functions/is_domain_name.rb index 5826dc0..b3fee96 100644 --- a/lib/puppet/parser/functions/is_domain_name.rb +++ b/lib/puppet/parser/functions/is_domain_name.rb @@ -20,6 +20,9 @@ Returns true if the string passed to this function is a syntactically correct do label_min_length=1 label_max_length=63 + # Only allow string types + return false unless domain.is_a?(String) + # Allow ".", it is the top level domain return true if domain == '.' diff --git a/lib/puppet/parser/functions/is_float.rb b/lib/puppet/parser/functions/is_float.rb index 911f3c2..a2da943 100644 --- a/lib/puppet/parser/functions/is_float.rb +++ b/lib/puppet/parser/functions/is_float.rb @@ -15,6 +15,9 @@ Returns true if the variable passed to this function is a float. value = arguments[0] + # Only allow Numeric or String types + return false unless value.is_a?(Numeric) or value.is_a?(String) + if value != value.to_f.to_s and !value.is_a? Float then return false else diff --git a/lib/puppet/parser/functions/is_function_available.rb b/lib/puppet/parser/functions/is_function_available.rb index 6cbd35c..6da82c8 100644 --- a/lib/puppet/parser/functions/is_function_available.rb +++ b/lib/puppet/parser/functions/is_function_available.rb @@ -15,6 +15,9 @@ true if the function exists, false if not. "given #{arguments.size} for 1") end + # Only allow String types + return false unless arguments[0].is_a?(String) + function = Puppet::Parser::Functions.function(arguments[0].to_sym) function.is_a?(String) and not function.empty? end |