diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/facter/puppet_settings.rb | 35 | ||||
-rw-r--r-- | lib/facter/puppet_vardir.rb | 26 | ||||
-rw-r--r-- | lib/puppet/functions/validate_absolute_path.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_array.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_bool.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_hash.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_integer.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_ip_address.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_ipv4_address.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_ipv6_address.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_numeric.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_re.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_string.rb | 3 | ||||
-rw-r--r-- | lib/puppet/parser/functions/dig44.rb | 37 | ||||
-rw-r--r-- | lib/puppet_x/puppetlabs/stdlib/deprecation_gen.rb | 21 |
15 files changed, 62 insertions, 90 deletions
diff --git a/lib/facter/puppet_settings.rb b/lib/facter/puppet_settings.rb new file mode 100644 index 0000000..e6a066a --- /dev/null +++ b/lib/facter/puppet_settings.rb @@ -0,0 +1,35 @@ +# These facter facts return the value of the Puppet vardir and environment path +# settings for the node running puppet or puppet agent. The intent is to +# enable Puppet modules to automatically have insight into a place where they +# can place variable data, or for modules running on the puppet master to know +# where environments are stored. +# +# The values should be directly usable in a File resource path attribute. +# +begin + require 'facter/util/puppet_settings' +rescue LoadError => e + # puppet apply does not add module lib directories to the $LOAD_PATH (See + # #4248). It should (in the future) but for the time being we need to be + # defensive which is what this rescue block is doing. + rb_file = File.join(File.dirname(__FILE__), 'util', 'puppet_settings.rb') + load rb_file if File.exists?(rb_file) or raise e +end + + +# These will be nil if Puppet is not available. +Facter.add(:puppet_vardir) do + setcode do + Facter::Util::PuppetSettings.with_puppet do + Puppet[:vardir] + end + end +end + +Facter.add(:puppet_environmentpath) do + setcode do + Facter::Util::PuppetSettings.with_puppet do + Puppet[:environmentpath] + end + end +end diff --git a/lib/facter/puppet_vardir.rb b/lib/facter/puppet_vardir.rb deleted file mode 100644 index 0e6af40..0000000 --- a/lib/facter/puppet_vardir.rb +++ /dev/null @@ -1,26 +0,0 @@ -# This facter fact returns the value of the Puppet vardir setting for the node -# running puppet or puppet agent. The intent is to enable Puppet modules to -# automatically have insight into a place where they can place variable data, -# regardless of the node's platform. -# -# The value should be directly usable in a File resource path attribute. - - -begin - require 'facter/util/puppet_settings' -rescue LoadError => e - # puppet apply does not add module lib directories to the $LOAD_PATH (See - # #4248). It should (in the future) but for the time being we need to be - # defensive which is what this rescue block is doing. - rb_file = File.join(File.dirname(__FILE__), 'util', 'puppet_settings.rb') - load rb_file if File.exists?(rb_file) or raise e -end - -Facter.add(:puppet_vardir) do - setcode do - # This will be nil if Puppet is not available. - Facter::Util::PuppetSettings.with_puppet do - Puppet[:vardir] - end - end -end diff --git a/lib/puppet/functions/validate_absolute_path.rb b/lib/puppet/functions/validate_absolute_path.rb deleted file mode 100644 index 5ae9d29..0000000 --- a/lib/puppet/functions/validate_absolute_path.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'puppet_x/puppetlabs/stdlib/deprecation_gen' -PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_absolute_path", "Stdlib::Compat::Absolute_Path") -# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_array.rb b/lib/puppet/functions/validate_array.rb deleted file mode 100644 index 9155784..0000000 --- a/lib/puppet/functions/validate_array.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'puppet_x/puppetlabs/stdlib/deprecation_gen' -PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_array", "Stdlib::Compat::Array") -# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_bool.rb b/lib/puppet/functions/validate_bool.rb deleted file mode 100644 index 10f6edf..0000000 --- a/lib/puppet/functions/validate_bool.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'puppet_x/puppetlabs/stdlib/deprecation_gen' -PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_bool", "Stdlib::Compat::Bool") -# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_hash.rb b/lib/puppet/functions/validate_hash.rb deleted file mode 100644 index 5349664..0000000 --- a/lib/puppet/functions/validate_hash.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'puppet_x/puppetlabs/stdlib/deprecation_gen' -PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_hash", "Stdlib::Compat::Hash") -# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_integer.rb b/lib/puppet/functions/validate_integer.rb deleted file mode 100644 index 2c4645d..0000000 --- a/lib/puppet/functions/validate_integer.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'puppet_x/puppetlabs/stdlib/deprecation_gen' -PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_integer", "Stdlib::Compat::Integer") -# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_ip_address.rb b/lib/puppet/functions/validate_ip_address.rb deleted file mode 100644 index 15a710e..0000000 --- a/lib/puppet/functions/validate_ip_address.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'puppet_x/puppetlabs/stdlib/deprecation_gen' -PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_ip_address", "Stdlib::Compat::Ip_Address") -# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_ipv4_address.rb b/lib/puppet/functions/validate_ipv4_address.rb deleted file mode 100644 index 8e1bc59..0000000 --- a/lib/puppet/functions/validate_ipv4_address.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'puppet_x/puppetlabs/stdlib/deprecation_gen' -PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_ipv4_address", "Stdlib::Compat::Ipv4_Address") -# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_ipv6_address.rb b/lib/puppet/functions/validate_ipv6_address.rb deleted file mode 100644 index 865648a..0000000 --- a/lib/puppet/functions/validate_ipv6_address.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'puppet_x/puppetlabs/stdlib/deprecation_gen' -PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_ipv6_address", "Stdlib::Compat::Ipv6_address") -# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_numeric.rb b/lib/puppet/functions/validate_numeric.rb deleted file mode 100644 index 0c2e1f2..0000000 --- a/lib/puppet/functions/validate_numeric.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'puppet_x/puppetlabs/stdlib/deprecation_gen' -PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_numeric", "Stdlib::Compat::Numeric") -# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_re.rb b/lib/puppet/functions/validate_re.rb deleted file mode 100644 index d63ed42..0000000 --- a/lib/puppet/functions/validate_re.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'puppet_x/puppetlabs/stdlib/deprecation_gen' -PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_re", "Stdlib::Compat::Re") -# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_string.rb b/lib/puppet/functions/validate_string.rb deleted file mode 100644 index a196f43..0000000 --- a/lib/puppet/functions/validate_string.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'puppet_x/puppetlabs/stdlib/deprecation_gen' -PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_string", "Stdlib::Compat::String") -# Puppet::Functions.create_function diff --git a/lib/puppet/parser/functions/dig44.rb b/lib/puppet/parser/functions/dig44.rb index a7de363..1e7c318 100644 --- a/lib/puppet/parser/functions/dig44.rb +++ b/lib/puppet/parser/functions/dig44.rb @@ -3,21 +3,28 @@ # module Puppet::Parser::Functions - newfunction(:dig44, :type => :rvalue, :doc => <<-EOS + newfunction( + :dig44, + :type => :rvalue, + :arity => -2, + :doc => <<-eos DEPRECATED: This function has been replaced in puppet 4.5.0. -Looks up into a complex structure of arrays and hashes and returns nil +Looks up into a complex structure of arrays and hashes and returns a value or the default value if nothing was found. -Path is an array of keys to be looked up in data argument. The function -will go down the structure and try to extract the required value. +Key can contain slashes to describe path components. The function will go down +the structure and try to extract the required value. $data = { 'a' => { 'b' => [ 'b1', 'b2', - 'b3' ]}} + 'b3', + ] + } +} $value = dig44($data, ['a', 'b', '2'], 'not_found') => $value = 'b3' @@ -29,18 +36,18 @@ b -> second hash key not_found -> (optional) will be returned if there is no value or the path did not match. Defaults to nil. -In addition to the required "path" argument, "dig44" accepts default +In addition to the required "key" argument, the function accepts a default argument. It will be returned if no value was found or a path component is missing. And the fourth argument can set a variable path separator. - EOS - ) do |arguments| + 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 data, path, default = *arguments - if !(data.is_a?(Hash) || data.is_a?(Array)) + 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}") end @@ -50,7 +57,17 @@ missing. And the fourth argument can set a variable path separator. "given #{path.class.name}") end - value = path.reduce(data) { |h, k| (h.is_a?(Hash) || h.is_a?(Array)) ? h[k] : break } + value = path.reduce(data) do |structure, key| + if structure.is_a? Hash or structure.is_a? Array + if structure.is_a? Array + key = Integer key rescue break + end + break if structure[key].nil? or structure[key] == :undef + structure[key] + else + break + end + end value.nil? ? default : value end end diff --git a/lib/puppet_x/puppetlabs/stdlib/deprecation_gen.rb b/lib/puppet_x/puppetlabs/stdlib/deprecation_gen.rb deleted file mode 100644 index a3d830b..0000000 --- a/lib/puppet_x/puppetlabs/stdlib/deprecation_gen.rb +++ /dev/null @@ -1,21 +0,0 @@ -# Creates a Puppet 4 function for the corresponding puppet 3 validate function, who's name will be passed as an argument, alongside the type for deprecation output purposes. -module PuppetX - module Puppetlabs - module Stdlib - def self.deprecation_gen(funct, type) - Puppet::Functions.create_function(funct, Puppet::Functions::InternalFunction) do - @@funct = funct - @@type = type - dispatch :deprecation_gen do - scope_param - optional_repeated_param 'Any', :args - end - def deprecation_gen(scope, *args) - call_function('deprecation', 'puppet_3_type_check', "This method is deprecated, please use the stdlib validate_legacy function, with #{@@type}. There is further documentation for validate_legacy function in the README.") - scope.send("function_#{@@funct}", args) - end - end - end - end - end -end |