class Puppet::Settings::EnvironmentConf

Configuration settings for a single directory Environment. @api private

Constants

ENVIRONMENT_CONF_ONLY_SETTINGS
VALID_SETTINGS

Attributes

global_modulepath[R]
path_to_env[R]
section[R]

Public Class Methods

load_from(path_to_env, global_module_path) click to toggle source

Given a path to a directory environment, attempts to load and parse an environment.conf in ini format, and return an EnvironmentConf instance.

An environment.conf is optional, so if the file itself is missing, or empty, an EnvironmentConf with default values will be returned.

@note logs warnings if the environment.conf contains any ini sections, or has settings other than the three handled for directory environments (:manifest, :modulepath, :config_version)

@param path_to_env [String] path to the directory environment @param global_module_path [Array<String>] the installation's base modulepath

setting, appended to default environment modulepaths

@return [EnvironmentConf] the parsed EnvironmentConf object

   # File lib/puppet/settings/environment_conf.rb
23 def self.load_from(path_to_env, global_module_path)
24   path_to_env = File.expand_path(path_to_env)
25   conf_file = File.join(path_to_env, 'environment.conf')
26 
27   begin
28     config = Puppet.settings.parse_file(conf_file)
29     validate(conf_file, config)
30     section = config.sections[:main]
31   rescue Errno::ENOENT
32     # environment.conf is an optional file
33     Puppet.debug { "Path to #{path_to_env} does not exist, using default environment.conf" }
34   end
35 
36   new(path_to_env, section, global_module_path)
37 end
new(path_to_env, section, global_module_path) click to toggle source

Create through EnvironmentConf.load_from()

   # File lib/puppet/settings/environment_conf.rb
50 def initialize(path_to_env, section, global_module_path)
51   @path_to_env = path_to_env
52   @section = section
53   @global_module_path = global_module_path
54 end
static_for(environment, environment_timeout = 0, static_catalogs = false, rich_data = false) click to toggle source

Provides a configuration object tied directly to the passed environment. Configuration values are exactly those returned by the environment object, without interpolation. This is a special case for the default configured environment returned by the Puppet::Environments::StaticPrivate loader.

   # File lib/puppet/settings/environment_conf.rb
43 def self.static_for(environment, environment_timeout = 0, static_catalogs = false, rich_data = false)
44   Static.new(environment, environment_timeout, static_catalogs, nil, rich_data)
45 end

Private Class Methods

validate(path_to_conf_file, config) click to toggle source
    # File lib/puppet/settings/environment_conf.rb
135 def self.validate(path_to_conf_file, config)
136   valid = true
137   section_keys = config.sections.keys
138   main = config.sections[:main]
139   if section_keys.size > 1
140     # warn once per config file path
141     Puppet.warn_once(
142       :invalid_settings_section, "EnvironmentConf-section:#{path_to_conf_file}",
143       _("Invalid sections in environment.conf at '%{path_to_conf_file}'. Environment conf may not have sections. The following sections are being ignored: '%{sections}'") % {
144         path_to_conf_file: path_to_conf_file,
145         sections: (section_keys - [:main]).join(',')
146       })
147     valid = false
148   end
149 
150   extraneous_settings = main.settings.map(&:name) - VALID_SETTINGS
151   if !extraneous_settings.empty?
152     # warn once per config file path
153     Puppet.warn_once(
154       :invalid_settings, "EnvironmentConf-settings:#{path_to_conf_file}",
155       _("Invalid settings in environment.conf at '%{path_to_conf_file}'. The following unknown setting(s) are being ignored: %{ignored_settings}") % {
156         path_to_conf_file: path_to_conf_file,
157         ignored_settings: extraneous_settings.join(', ')
158       })
159     valid = false
160   end
161 
162   return valid
163 end

Public Instance Methods

config_version() click to toggle source
    # File lib/puppet/settings/environment_conf.rb
122 def config_version
123   get_setting(:config_version) do |config_version|
124     absolute(config_version)
125   end
126 end
environment_data_provider() click to toggle source
   # File lib/puppet/settings/environment_conf.rb
94 def environment_data_provider
95   get_setting(:environment_data_provider, Puppet.settings.value(:environment_data_provider)) do |value|
96     value
97   end
98 end
environment_timeout() click to toggle source
   # File lib/puppet/settings/environment_conf.rb
84 def environment_timeout
85   # gen env specific config or use the default value
86   get_setting(:environment_timeout, Puppet.settings.value(:environment_timeout)) do |ttl|
87     # munges the string form statically without really needed the settings system, only
88     # its ability to munge "4s, 3m, 5d, and 'unlimited' into seconds - if already munged into
89     # numeric form, the TTLSetting handles that.
90     Puppet::Settings::TTLSetting.munge(ttl, 'environment_timeout')
91   end
92 end
manifest() click to toggle source
   # File lib/puppet/settings/environment_conf.rb
56 def manifest
57   puppet_conf_manifest = Pathname.new(Puppet.settings.value(:default_manifest))
58   disable_per_environment_manifest = Puppet.settings.value(:disable_per_environment_manifest)
59 
60   fallback_manifest_directory =
61   if puppet_conf_manifest.absolute?
62     puppet_conf_manifest.to_s
63   else
64     File.join(@path_to_env, puppet_conf_manifest.to_s)
65   end
66 
67   if disable_per_environment_manifest
68     environment_conf_manifest = absolute(raw_setting(:manifest))
69     if environment_conf_manifest && fallback_manifest_directory != environment_conf_manifest
70       #TRANSLATORS 'disable_per_environment_manifest' is a setting and 'environment.conf' is a file name and should not be translated
71       message = _("The 'disable_per_environment_manifest' setting is true, but the environment located at %{path_to_env} has a manifest setting in its environment.conf of '%{environment_conf}' which does not match the default_manifest setting '%{puppet_conf}'.") %
72           { path_to_env: @path_to_env, environment_conf: environment_conf_manifest, puppet_conf: puppet_conf_manifest }
73       message += ' ' + _("If this environment is expecting to find modules in '%{environment_conf}', they will not be available!") % { environment_conf: environment_conf_manifest }
74       Puppet.err(message)
75     end
76     fallback_manifest_directory.to_s
77   else
78     get_setting(:manifest, fallback_manifest_directory) do |manifest|
79       absolute(manifest)
80     end
81   end
82 end
modulepath() click to toggle source
    # File lib/puppet/settings/environment_conf.rb
100 def modulepath
101   default_modulepath = [File.join(@path_to_env, "modules")] + @global_module_path
102   get_setting(:modulepath, default_modulepath) do |modulepath|
103     path = modulepath.kind_of?(String) ?
104       modulepath.split(File::PATH_SEPARATOR) :
105       modulepath
106     path.map { |p| expand_glob(absolute(p)) }.flatten.join(File::PATH_SEPARATOR)
107   end
108 end
raw_setting(setting_name) click to toggle source
    # File lib/puppet/settings/environment_conf.rb
128 def raw_setting(setting_name)
129   setting = section.setting(setting_name) if section
130   setting.value if setting
131 end
rich_data() click to toggle source
    # File lib/puppet/settings/environment_conf.rb
110 def rich_data
111   get_setting(:rich_data, Puppet.settings.value(:rich_data)) do |value|
112     value
113   end
114 end
static_catalogs() click to toggle source
    # File lib/puppet/settings/environment_conf.rb
116 def static_catalogs
117   get_setting(:static_catalogs, Puppet.settings.value(:static_catalogs)) do |value|
118     value
119   end
120 end

Private Instance Methods

absolute(path) click to toggle source
    # File lib/puppet/settings/environment_conf.rb
181 def absolute(path)
182   return nil if path.nil?
183   if path =~ /^\$/
184     # Path begins with $something interpolatable
185     path
186   else
187     Puppet::FileSystem.expand_path(path, @path_to_env)
188   end
189 end
expand_glob(path) click to toggle source
    # File lib/puppet/settings/environment_conf.rb
172 def expand_glob(path)
173   return nil if path.nil?
174   if path =~ /[*?\[\{]/
175     Dir.glob(path)
176   else
177     path
178   end
179 end
get_setting(setting_name, default = nil) { |value| ... } click to toggle source
    # File lib/puppet/settings/environment_conf.rb
166 def get_setting(setting_name, default = nil)
167   value = raw_setting(setting_name)
168   value = default if value.nil?
169   yield value
170 end