Class: Puppet::Pops::Binder::Config::BinderConfig
- Defined in:
- lib/puppet/pops/binder/config/binder_config.rb
Overview
Class holding the Binder Configuration The configuration is obtained from the file ‘binder_config.yaml’ that must reside in the root directory of the site
Constant Summary collapse
- DEFAULT_LAYERS =
[ { 'name' => 'site', 'include' => ['confdir-hiera:/', 'confdir:/default?optional'] }, { 'name' => 'modules', 'include' => ['module-hiera:/*/', 'module:/*::default'] }, ]
- DEFAULT_CATEGORIES =
[ ['node', "${fqdn}"], ['osfamily', "${osfamily}"], ['environment', "${environment}"], ['common', "true"] ]
- DEFAULT_SCHEME_EXTENSIONS =
{}
- DEFAULT_HIERA_BACKENDS_EXTENSIONS =
{}
Instance Attribute Summary collapse
-
#categorization ⇒ Array<Array(String, String)>
readonly
Array of Category tuples where Strings are not evaluated.
-
#config_file ⇒ String
The loaded config file.
-
#hiera_backends ⇒ Hash<String, String>
readonly
({}) optional mapping of hiera backend name to backend class name.
-
#layering_config ⇒ Array<Hash<String, String>, Hash<String, Array<String>>]
readonly
The bindings hierarchy is an array of categorizations where the array for each category has exactly three elements - the categorization name, category value, and the path that is later used by the backend to read the bindings for that category.
-
#scheme_extensions ⇒ Hash<String, String>
readonly
({}) optional mapping of bindings-scheme to handler class name.
Instance Method Summary collapse
- #confdir ⇒ Object
- #default_categories ⇒ Object private
- #default_config ⇒ Object
- #default_hiera_backends_extensions ⇒ Object private
- #default_layers ⇒ Object private
- #default_scheme_extensions ⇒ Object private
-
#initialize(diagnostics) ⇒ BinderConfig
constructor
Creates a new Config.
Constructor Details
#initialize(diagnostics) ⇒ BinderConfig
Creates a new Config. The configuration is loaded from the file ‘binder_config.yaml’ which is expected to be found in confdir.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 64 def initialize(diagnostics) @config_file = Puppet.settings[:binder_config] # if file is stated, it must exist # otherwise it is optional $confdir/binder_conf.yaml # and if that fails, the default case @config_file when NilClass # use the config file if it exists rootdir = confdir if rootdir.is_a?(String) = File.(File.join(rootdir, '/binder_config.yaml')) if Puppet::FileSystem::File.exist?() @config_file = end else raise ArgumentError, "No Puppet settings 'confdir', or it is not a String" end when String unless Puppet::FileSystem::File.exist?(@config_file) raise ArgumentError, "Cannot find the given binder configuration file '#{@config_file}'" end else raise ArgumentError, "The setting binder_config is expected to be a String, got: #{@config_file.class.name}." end unless @config_file.is_a?(String) && Puppet::FileSystem::File.exist?(@config_file) @config_file = nil # use defaults end validator = BinderConfigChecker.new(diagnostics) begin data = @config_file ? YAML.load_file(@config_file) : default_config() validator.validate(data, @config_file) rescue Errno::ENOENT diagnostics.accept(Issues::CONFIG_FILE_NOT_FOUND, @config_file) rescue Errno::ENOTDIR diagnostics.accept(Issues::CONFIG_FILE_NOT_FOUND, @config_file) rescue ::SyntaxError => e diagnostics.accept(Issues::CONFIG_FILE_SYNTAX_ERROR, @config_file, :detail => e.) end unless diagnostics.errors? @layering_config = data['layers'] or default_layers @categorization = data['categories'] or default_categories @scheme_extensions = (data['extensions'] and data['extensions']['scheme_handlers'] or default_scheme_extensions) @hiera_backends = (data['extensions'] and data['extensions']['hiera_backends'] or default_hiera_backends_extensions) else @layering_config = [] @categorization = {} @scheme_extensions = {} @hiera_backends = {} end end |
Instance Attribute Details
#categorization ⇒ Array<Array(String, String)> (readonly)
Returns Array of Category tuples where Strings are not evaluated.
22 23 24 |
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 22 def categorization @categorization end |
#config_file ⇒ String
Returns the loaded config file.
31 32 33 |
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 31 def config_file @config_file end |
#hiera_backends ⇒ Hash<String, String> (readonly)
Returns ({}) optional mapping of hiera backend name to backend class name.
28 29 30 |
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 28 def hiera_backends @hiera_backends end |
#layering_config ⇒ Array<Hash<String, String>, Hash<String, Array<String>>] (readonly)
The bindings hierarchy is an array of categorizations where the array for each category has exactly three elements - the categorization name, category value, and the path that is later used by the backend to read the bindings for that category
17 18 19 |
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 17 def layering_config @layering_config end |
Instance Method Details
#confdir ⇒ Object
54 55 56 |
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 54 def confdir() Puppet.settings[:confdir] end |
#default_categories ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
125 126 127 |
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 125 def default_categories DEFAULT_CATEGORIES end |
#default_config ⇒ Object
49 50 51 52 |
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 49 def default_config() # This is hardcoded now, but may be a user supplied default configuration later {'version' => 1, 'layers' => default_layers, 'categories' => default_categories} end |
#default_hiera_backends_extensions ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
135 136 137 |
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 135 def default_hiera_backends_extensions DEFAULT_HIERA_BACKENDS_EXTENSIONS end |
#default_layers ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
120 121 122 |
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 120 def default_layers DEFAULT_LAYERS end |
#default_scheme_extensions ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
130 131 132 |
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 130 def default_scheme_extensions DEFAULT_SCHEME_EXTENSIONS end |