Class: R10K::Action::Runner
- Inherits:
-
Object
- Object
- R10K::Action::Runner
show all
- Includes:
- Logging
- Defined in:
- lib/r10k/action/runner.rb
Constant Summary
Constants included
from Logging
Logging::LOG_LEVELS
Instance Method Summary
collapse
Methods included from Logging
debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level
Constructor Details
#initialize(opts, argv, klass) ⇒ Runner
Returns a new instance of Runner.
11
12
13
14
15
16
17
|
# File 'lib/r10k/action/runner.rb', line 11
def initialize(opts, argv, klass)
@opts = opts
@argv = argv
@klass = klass
@settings = {}
end
|
Instance Method Details
#call ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/r10k/action/runner.rb', line 28
def call
setup_logging
setup_settings
setup_authorization
instance.call
end
|
#instance ⇒ Object
19
20
21
22
23
24
25
26
|
# File 'lib/r10k/action/runner.rb', line 19
def instance
if @_instance.nil?
iopts = @opts.dup
iopts.delete(:loglevel)
@_instance = @klass.new(iopts, @argv, @settings)
end
@_instance
end
|
#setup_authorization ⇒ Object
Set up authorization from license file if it wasn’t already set via the config
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/r10k/action/runner.rb', line 75
def setup_authorization
if PuppetForge::Connection.authorization.nil?
begin
license = R10K::Util::License.load
if license.respond_to?(:authorization_token)
logger.debug "Using token from license to connect to the Forge."
PuppetForge::Connection.authorization = license.authorization_token
end
rescue R10K::Error => e
logger.warn e.message
end
end
end
|
#setup_logging ⇒ Object
36
37
38
39
40
|
# File 'lib/r10k/action/runner.rb', line 36
def setup_logging
if @opts.key?(:loglevel)
R10K::Logging.level = @opts[:loglevel]
end
end
|
#setup_settings ⇒ Object
42
43
44
45
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
|
# File 'lib/r10k/action/runner.rb', line 42
def setup_settings
config_settings = settings_from_config(@opts[:config])
overrides = {}
overrides[:cachedir] = @opts[:cachedir] if @opts.key?(:cachedir)
if @opts.key?(:'puppet-path') || @opts.key?(:'generate-types') || @opts.key?(:'exclude-spec') || @opts.key?(:'puppet-conf')
overrides[:deploy] = {}
overrides[:deploy][:puppet_path] = @opts[:'puppet-path'] if @opts.key?(:'puppet-path')
overrides[:deploy][:puppet_conf] = @opts[:'puppet-conf'] if @opts.key?(:'puppet-conf')
overrides[:deploy][:generate_types] = @opts[:'generate-types'] if @opts.key?(:'generate-types')
overrides[:deploy][:exclude_spec] = @opts[:'exclude-spec'] if @opts.key?(:'exclude-spec')
end
with_overrides = config_settings.merge(overrides) do |key, oldval, newval|
newval = oldval.merge(newval) if oldval.is_a? Hash
logger.debug2 _("Overriding config file setting '%{key}': '%{old_val}' -> '%{new_val}'") % {key: key, old_val: oldval, new_val: newval}
newval
end
with_overrides = add_credential_overrides(with_overrides)
@settings = R10K::Settings.global_settings.evaluate(with_overrides)
R10K::Initializers::GlobalInitializer.new(@settings).call
rescue R10K::Settings::Collection::ValidationError => e
logger.error e.format
exit(8)
end
|