Class: Puppet::Pops::Binder::Config::BinderConfig

Inherits:
Object
  • Object
show all
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:/default?optional'] },
  { 'name' => 'modules', 'include' => [ 'module:/*::default', 'module:/*::metadata'] },
]
DEFAULT_SCHEME_EXTENSIONS =
{}

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 46

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)
      expanded_config_file = File.expand_path(File.join(rootdir, '/binder_config.yaml'))
      if Puppet::FileSystem.exist?(expanded_config_file)
        @config_file = expanded_config_file
      end
    else
      raise ArgumentError, "No Puppet settings 'confdir', or it is not a String"
    end
  when String
    unless Puppet::FileSystem.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.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.message)
  end

  unless diagnostics.errors?
    @layering_config   = data['layers'] || default_layers
    @scheme_extensions = (data['extensions'] && data['extensions']['scheme_handlers'] || default_scheme_extensions)
  else
    @layering_config = []
    @scheme_extensions = {}
  end
end

Instance Attribute Details

#config_fileString

Returns the loaded config file.

Returns:

  • (String)

    the loaded config file



22
23
24
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 22

def config_file
  @config_file
end

#layering_configArray<Hash<String, String>, Hash<String, Array<String>>] (readonly)

The layering configuration is an array of layers from most to least significant. Each layer is represented by a Hash containing :name and :include and optionally :exclude

Returns:

  • (Array<Hash<String, String>, Hash<String, Array<String>>])

    Array<Hash<String, String>, Hash<String, Array<String>>]



15
16
17
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 15

def layering_config
  @layering_config
end

#scheme_extensionsHash<String, String> (readonly)

Returns ({}) optional mapping of bindings-scheme to handler class name.

Returns:

  • (Hash<String, String>)

    ({}) optional mapping of bindings-scheme to handler class name



18
19
20
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 18

def scheme_extensions
  @scheme_extensions
end

Instance Method Details

#confdirObject



36
37
38
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 36

def confdir()
  Puppet.settings[:confdir]
end

#default_configObject



31
32
33
34
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 31

def default_config()
  # This is hardcoded now, but may be a user supplied default configuration later
  {'version' => 1, 'layers' => default_layers }
end

#default_layersObject

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.



98
99
100
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 98

def default_layers
  DEFAULT_LAYERS
end

#default_scheme_extensionsObject

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.



103
104
105
# File 'lib/puppet/pops/binder/config/binder_config.rb', line 103

def default_scheme_extensions
  DEFAULT_SCHEME_EXTENSIONS
end