From d5dc3036eda210f318160e2442f7b65e0995ee23 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Thu, 21 Oct 2010 14:23:32 -0700 Subject: Fix for #5063 -- explicitly scope internal variable lookups When we lookup a global variable / fact from code we should explicitly look in the global scope. --- lib/puppet/parser/functions/extlookup.rb | 9 ++------- lib/puppet/parser/functions/fqdn_rand.rb | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/extlookup.rb b/lib/puppet/parser/functions/extlookup.rb index bc55410b9..b5688d644 100644 --- a/lib/puppet/parser/functions/extlookup.rb +++ b/lib/puppet/parser/functions/extlookup.rb @@ -91,14 +91,9 @@ This is for back compatibility to interpolate variables with %. % interpolation raise Puppet::ParseError, ("extlookup(): wrong number of arguments (#{args.length}; must be <= 3)") if args.length > 3 - extlookup_datadir = lookupvar('extlookup_datadir') - extlookup_precedence = Array.new + extlookup_datadir = lookupvar('::extlookup_datadir') - extlookup_precedence = lookupvar('extlookup_precedence').collect do |var| - var.gsub(/%\{(.+?)\}/) do |capture| - lookupvar($1) - end - end + extlookup_precedence = lookupvar('::extlookup_precedence').collect { |var| var.gsub(/%\{(.+?)\}/) { lookupvar("::#{$1}") } } datafiles = Array.new diff --git a/lib/puppet/parser/functions/fqdn_rand.rb b/lib/puppet/parser/functions/fqdn_rand.rb index 91157a148..93ab98bcd 100644 --- a/lib/puppet/parser/functions/fqdn_rand.rb +++ b/lib/puppet/parser/functions/fqdn_rand.rb @@ -7,6 +7,6 @@ Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => :rvalue, :doc => $random_number_seed = fqdn_rand(30,30)") do |args| require 'digest/md5' max = args.shift - srand(Digest::MD5.hexdigest([lookupvar('fqdn'),args].join(':')).hex) + srand(Digest::MD5.hexdigest([lookupvar('::fqdn'),args].join(':')).hex) rand(max).to_s end -- cgit From 31f8e660c8f4c0ec01f140322cf7c585144a0888 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Thu, 21 Oct 2010 17:24:09 -0700 Subject: Refactor en route to #5027 -- remove usestring parameter from lookupvar The usestring parameter to lookupvar was objectionable for several reasons; first, it performed a function orthogonal to the main purpose of the method, second its default was the least common value, and third it was causing other code to work for reasons that were not obvious (extlookup). This refactor breaks the value-transforming function out into a seperate method which allows the user to specify the value to be used in lieu of :undef and removes the parameter. The function, Scope#undef_as(default,exp) is written so that it can be used in user code (templates, functions, etc.) if needed. This refactor will introduce a user-visible behaviour change in the case where users were counting on lookupvar to return "" for undefined variables. The best solution is to have them use undef_as, replacing: lookupvar('myvar') with undef_as('',lookupvar('myvar')) (with the option to specify another default value if desired). If this is too objectionable, we could rename the existing lookupvar as raw_lookupvar and define def lookupvar(v) undef_as('',raw_lookupvar(v)) end to restore the present behaviour. --- lib/puppet/parser/functions/extlookup.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/extlookup.rb b/lib/puppet/parser/functions/extlookup.rb index b5688d644..5fbf26cec 100644 --- a/lib/puppet/parser/functions/extlookup.rb +++ b/lib/puppet/parser/functions/extlookup.rb @@ -91,9 +91,9 @@ This is for back compatibility to interpolate variables with %. % interpolation raise Puppet::ParseError, ("extlookup(): wrong number of arguments (#{args.length}; must be <= 3)") if args.length > 3 - extlookup_datadir = lookupvar('::extlookup_datadir') + extlookup_datadir = undef_as('',lookupvar('::extlookup_datadir')) - extlookup_precedence = lookupvar('::extlookup_precedence').collect { |var| var.gsub(/%\{(.+?)\}/) { lookupvar("::#{$1}") } } + extlookup_precedence = undef_as([],lookupvar('::extlookup_precedence')).collect { |var| var.gsub(/%\{(.+?)\}/) { lookupvar("::#{$1}") } } datafiles = Array.new -- cgit From 4ef622e0874c53c8060531d43da06f0fd6fddc36 Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Wed, 13 Apr 2011 15:00:56 -0700 Subject: (#6830) Fix sha1 to digest/sha1 require issue for Ruby 1.9 Reviewed-by: Daniel Pittman --- lib/puppet/parser/functions/sha1.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/sha1.rb b/lib/puppet/parser/functions/sha1.rb index 10cc55cfe..1e7d5abe4 100644 --- a/lib/puppet/parser/functions/sha1.rb +++ b/lib/puppet/parser/functions/sha1.rb @@ -1,5 +1,5 @@ Puppet::Parser::Functions::newfunction(:sha1, :type => :rvalue, :doc => "Returns a SHA1 hash value from a provided string.") do |args| - require 'sha1' + require 'digest/sha1' Digest::SHA1.hexdigest(args[0]) end -- cgit