Class: R10K::Action::Runner
- Inherits:
-
Object
- Object
- R10K::Action::Runner
- Includes:
- Logging
- Defined in:
- lib/r10k/action/runner.rb
Constant Summary
Constants included from Logging
Logging::LOG_LEVELS, Logging::SYSLOG_LEVELS_MAP
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(opts, argv, klass) ⇒ Runner
constructor
A new instance of Runner.
- #instance ⇒ Object
-
#setup_authorization ⇒ Object
Set up authorization from license file if it wasn’t already set via the config.
- #setup_logging ⇒ Object
- #setup_settings ⇒ Object
Methods included from Logging
add_outputters, 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 # @todo check arguments 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
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/r10k/action/runner.rb', line 81 def if PuppetForge::Connection..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. = license. end rescue R10K::Error => e logger.warn e. 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 72 73 74 75 76 77 |
# 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 # If the log level has been given as an argument, ensure that output happens on stderr if @opts.key?(:loglevel) overrides[:logging] = {} overrides[:logging][:level] = @opts[:loglevel] overrides[:logging][:disable_default_stderr] = false 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 # Credentials from the CLI override both the global and per-repo # credentials from the config, and so need to be handled specially 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 |