class Puppet::Settings::ChainedValues
Lookup configuration setting value through a chain of different value sources.
@api public
Constants
- ENVIRONMENT_INTERPOLATION_ALLOWED
- ENVIRONMENT_SETTING
Public Class Methods
new(mode, environment, value_sets, defaults)
click to toggle source
@see Puppet::Settings.values
@api private
# File lib/puppet/settings.rb 1409 def initialize(mode, environment, value_sets, defaults) 1410 @mode = mode 1411 @environment = environment 1412 @value_sets = value_sets 1413 @defaults = defaults 1414 end
Public Instance Methods
interpolate(name)
click to toggle source
Lookup the interpolated value. All instances of `$name` in the value will be replaced by performing a lookup of `name` and substituting the text for `$name` in the original value. This interpolation is only performed if the looked up value is a String.
@param name [Symbol] The configuration setting name to look up @return [Object] The configuration setting value or nil if the setting is not known @api public
# File lib/puppet/settings.rb 1449 def interpolate(name) 1450 setting = @defaults[name] 1451 return nil unless setting 1452 1453 lookup_and_convert(name) do |val| 1454 setting.munge(val) 1455 end 1456 end
lookup(name)
click to toggle source
Lookup the uninterpolated value.
@param name [Symbol] The configuration setting name to look up @return [Object] The configuration setting value or nil if the setting is not known @api public
# File lib/puppet/settings.rb 1421 def lookup(name) 1422 set = @value_sets.find do |value_set| 1423 value_set.include?(name) 1424 end 1425 if set 1426 value = set.lookup(name) 1427 if !value.nil? 1428 return value 1429 end 1430 end 1431 1432 setting = @defaults[name] 1433 if setting.respond_to?(:alias_name) 1434 val = lookup(setting.alias_name) 1435 return val if val 1436 end 1437 1438 @defaults[name].default 1439 end
print(name)
click to toggle source
# File lib/puppet/settings.rb 1458 def print(name) 1459 setting = @defaults[name] 1460 return nil unless setting 1461 1462 lookup_and_convert(name) do |val| 1463 setting.print(val) 1464 end 1465 end
Private Instance Methods
convert(value, setting_name)
click to toggle source
# File lib/puppet/settings.rb 1488 def convert(value, setting_name) 1489 case value 1490 when nil 1491 nil 1492 when String 1493 failed_environment_interpolation = false 1494 interpolated_value = value.gsub(/\$(\w+)|\$\{(\w+)\}/) do |expression| 1495 varname = $2 || $1 1496 interpolated_expression = 1497 if varname != ENVIRONMENT_SETTING || ok_to_interpolate_environment(setting_name) 1498 if varname == ENVIRONMENT_SETTING && @environment 1499 @environment 1500 elsif varname == "run_mode" 1501 @mode 1502 elsif !(pval = interpolate(varname.to_sym)).nil? 1503 pval 1504 else 1505 raise InterpolationError, _("Could not find value for %{expression}") % { expression: expression } 1506 end 1507 else 1508 failed_environment_interpolation = true 1509 expression 1510 end 1511 interpolated_expression 1512 end 1513 if failed_environment_interpolation 1514 #TRANSLATORS '$environment' is a Puppet specific variable and should not be translated 1515 Puppet.warning(_("You cannot interpolate $environment within '%{setting_name}' when using directory environments.") % { setting_name: setting_name } + 1516 ' ' + _("Its value will remain %{value}.") % { value: interpolated_value }) 1517 end 1518 interpolated_value 1519 else 1520 value 1521 end 1522 end
lookup_and_convert(name) { |val| ... }
click to toggle source
# File lib/puppet/settings.rb 1469 def lookup_and_convert(name, &block) 1470 val = lookup(name) 1471 # if we interpolate code, all hell breaks loose. 1472 if name == :code 1473 val 1474 else 1475 # Convert it if necessary 1476 begin 1477 val = convert(val, name) 1478 rescue InterpolationError => err 1479 # This happens because we don't have access to the param name when the 1480 # exception is originally raised, but we want it in the message 1481 raise InterpolationError, _("Error converting value for param '%{name}': %{detail}") % { name: name, detail: err }, err.backtrace 1482 end 1483 1484 yield val 1485 end 1486 end
ok_to_interpolate_environment(setting_name)
click to toggle source
# File lib/puppet/settings.rb 1524 def ok_to_interpolate_environment(setting_name) 1525 ENVIRONMENT_INTERPOLATION_ALLOWED.include?(setting_name.to_s) 1526 end