Class: Puppet::Pops::Binder::BindingsComposer

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/binder/bindings_composer.rb

Defined Under Namespace

Classes: SchemeHandlerHelper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBindingsComposer

Returns a new instance of BindingsComposer.



41
42
43
44
45
46
47
48
49
# File 'lib/puppet/pops/binder/bindings_composer.rb', line 41

def initialize()
  @acceptor = Puppet::Pops::Validation::Acceptor.new()
  @diagnostics = Puppet::Pops::Binder::Config::DiagnosticProducer.new(acceptor)
  @config = Puppet::Pops::Binder::Config::BinderConfig.new(@diagnostics)
  if acceptor.errors?
    Puppet::Pops::IssueReporter.assert_and_report(acceptor, :message => 'Binding Composer: error while reading config.')
    raise Puppet::DevError.new("Internal Error: IssueReporter did not raise exception for errors in bindings config.")
  end
end

Instance Attribute Details

#acceptorObject (readonly)

Container of all warnings and errors produced while initializing and loading bindings



38
39
40
# File 'lib/puppet/pops/binder/bindings_composer.rb', line 38

def acceptor
  @acceptor
end

#confdirObject (readonly)

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.



30
31
32
# File 'lib/puppet/pops/binder/bindings_composer.rb', line 30

def confdir
  @confdir
end

#configObject (readonly)

The BindingsConfig instance holding the read and parsed, but not evaluated configuration



19
20
21
# File 'lib/puppet/pops/binder/bindings_composer.rb', line 19

def config
  @config
end

#diagnosticsObject (readonly)

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.



33
34
35
# File 'lib/puppet/pops/binder/bindings_composer.rb', line 33

def diagnostics
  @diagnostics
end

#name_to_moduleHash{String => Puppet::Module} (readonly)

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.

Returns map of module name to module instance.

Returns:



27
28
29
# File 'lib/puppet/pops/binder/bindings_composer.rb', line 27

def name_to_module
  @name_to_module
end

#scheme_handlersObject (readonly)

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.

map of scheme name to handler



23
24
25
# File 'lib/puppet/pops/binder/bindings_composer.rb', line 23

def scheme_handlers
  @scheme_handlers
end

Instance Method Details

#compose(scope) ⇒ Puppet::Pops::Binder::Bindings::LayeredBindings



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
116
# File 'lib/puppet/pops/binder/bindings_composer.rb', line 86

def compose(scope)
  # The boot injector is used to lookup scheme-handlers
  configure_and_create_injector(scope)

  # get all existing modules and their root path
  @name_to_module = {}
  scope.environment.modules.each {|mod| name_to_module[mod.name] = mod }

  # setup the confdir
  @confdir = Puppet.settings[:confdir]

  factory = Puppet::Pops::Binder::BindingsFactory
  contributions = []
  configured_layers = @config.layering_config.collect do |  layer_config |
    # get contributions
    contribs = configure_layer(layer_config, scope, diagnostics)
    # collect the contributions separately for later checking of category precedence
    contributions.concat(contribs)
    # create a named layer with all the bindings for this layer
    factory.named_layer(layer_config['name'], *contribs.collect {|c| c.bindings }.flatten)
  end

  # Add the two system layers; the final - highest ("can not be overridden" layer), and the lowest
  # Everything here can be overridden 'default' layer.
  #
  configured_layers.insert(0, Puppet::Pops::Binder::SystemBindings.final_contribution)
  configured_layers.insert(-1, Puppet::Pops::Binder::SystemBindings.default_contribution)

  # and finally... create the resulting structure
  factory.layered_bindings(*configured_layers)
end

#configure_and_create_injector(scope) ⇒ 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.

Configures and creates the boot injector. The read config may optionally contain mapping of bindings scheme handler name to handler class, and mapping of biera2 backend symbolic name to backend class. If present, these are turned into bindings in the category ‘extension’ (which is only used in the boot injector) which has higher precedence than ‘default’. This is done to allow users to override the default bindings for schemes and backends.

Parameters:

  • scope (Puppet::Parser:Scope)

    the scope (used to find compiler and injector for the environment)



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/puppet/pops/binder/bindings_composer.rb', line 60

def configure_and_create_injector(scope)
  # create the injector (which will pick up the bindings registered above)
  @scheme_handlers = SchemeHandlerHelper.new(scope)

  # get extensions from the config
  # ------------------------------
  scheme_extensions = @config.scheme_extensions

  # Define a named bindings that are known by the SystemBindings
  boot_bindings = Puppet::Pops::Binder::BindingsFactory.named_bindings(Puppet::Pops::Binder::SystemBindings::ENVIRONMENT_BOOT_BINDINGS_NAME) do
    scheme_extensions.each_pair do |scheme, class_name|
      # turn each scheme => class_name into a binding (contribute to the buildings-schemes multibind).
      # do this in category 'extensions' to allow them to override the 'default'
      bind do
        name(scheme)
        instance_of(Puppet::Plugins::BindingSchemes::BINDINGS_SCHEMES_TYPE)
        in_multibind(Puppet::Plugins::BindingSchemes::BINDINGS_SCHEMES_KEY)
        to_instance(class_name)
        end
    end
  end

  @injector = scope.compiler.create_boot_injector(boot_bindings.model)
end