kafo 6.2.1 → 6.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03c5d65cf1a7ca3fa3676c6a36a7d0c374f24d06c16cebcb4be5f307f1a39695
4
- data.tar.gz: 295369c378adab5c4587f1177ac87eed3b7c5c8f829118ac7c3e7593e43c4d89
3
+ metadata.gz: 674a595f056324470ff9175d38779f7ab8c153e044ab4892dc99ca0d6487b7ba
4
+ data.tar.gz: 83ffe976aa56291ebad41e0e7ba22d72908bbe299d926bb1af1aa5b1fbef0a75
5
5
  SHA512:
6
- metadata.gz: 02e645d54f620a69ff7be17bea01af6d05496a92d1a26e60956d671c7342ccce5382db92552860a908452e00107dae2a0813e960d42b0789d834130528f3e03e
7
- data.tar.gz: 527eef2b88081ca1084a8e11646c7066060be65ccaa795559d40351f337768fa06e8d67d636e5180d822c31962322e258a64938d4b28ec6bd59643b2e1cfd809
6
+ metadata.gz: a8b66a8f86409186fbf2ed5fde7b6b7eb9f6e2fadf4ab33234df205fa4702cadae85021ef043ea096f5450e8735d6b81fade0d81530f2aae43a929dfa2ac8866
7
+ data.tar.gz: bc3475cace0ec33b3ffb983f8d5921e75b1695908b6f5386b716c3e90434e9ba69f18e38af2c8c0c35372887cec1cfa167ac45c9edb10294fe55cd1384d50ab8
data/README.md CHANGED
@@ -493,6 +493,39 @@ as key:value.
493
493
  When parsing the value, the first colon divides key and value. All other
494
494
  colons are ignored.
495
495
 
496
+ ## Sensitive arguments
497
+
498
+ Puppet's `Sensitive` data type can be used as long as it's configured in Hiera
499
+ too. Given the following manifest:
500
+
501
+ ```puppet
502
+ class example (
503
+ Sensitive[String[1]] $password,
504
+ ) {
505
+ ```
506
+
507
+ Here the following Hiera configuration is needed:
508
+ ```yaml
509
+ lookup_options:
510
+ example::password:
511
+ convert_to: "Sensitive"
512
+ ```
513
+
514
+ This is based on [Puppet's documentation](https://puppet.com/docs/puppet/6/securing-sensitive-data.html).
515
+
516
+ Note that to provide a default inside the manifest inheritance must be used.
517
+
518
+ ```puppet
519
+ class example (
520
+ Sensitive[String[1]] $password = $example::params::password,
521
+ ) inherits example::params {
522
+ }
523
+
524
+ class example::params {
525
+ $password = Sensitive('supersecret')
526
+ }
527
+ ```
528
+
496
529
  ## Default values
497
530
 
498
531
  Default values for parameters are read from the class definitions in the
@@ -816,6 +849,32 @@ if app_value(:reset_foreman_db) && !app_value(:noop)
816
849
  end
817
850
  ```
818
851
 
852
+ Hooks can additionally be defined by combining all related stages into a single file
853
+ known as a Multi-stage hook. Multi-stage hooks live in a special directory inside
854
+ the hooks directory: ```$installer_dir/hooks/multi```. Taking the previous example:
855
+
856
+ ```ruby
857
+ # hooks/multi/10-reset_option_feature.rb
858
+ boot do
859
+ app_option '--reset-foreman-db', :flag, 'Drop foreman database first? You will lose all data!', :default => false
860
+ end
861
+
862
+ pre do
863
+ if app_value(:reset_foreman_db) && !app_value(:noop)
864
+ `which foreman-rake > /dev/null 2>&1`
865
+ if $?.success?
866
+ logger.info 'Dropping database!'
867
+ output = `foreman-rake db:drop 2>&1`
868
+ logger.debug output.to_s
869
+ unless $?.success?
870
+ logger.warn "Unable to drop DB, ignoring since it's not fatal, output was: '#{output}''"
871
+ end
872
+ else
873
+ logger.warn 'Foreman not installed yet, can not drop database!'
874
+ end
875
+ end
876
+ end
877
+ ```
819
878
 
820
879
  If you want to add more directories to be search you can use the "hook_dirs" option
821
880
  in the installer configuration file.
@@ -5,43 +5,44 @@ require 'kafo/puppet_module'
5
5
  require 'kafo/color_scheme'
6
6
  require 'kafo/data_type_parser'
7
7
  require 'kafo/execution_environment'
8
+ require 'kafo/scenario_option'
8
9
 
9
10
  module Kafo
10
11
  class Configuration
11
12
  attr_reader :config_file, :answer_file, :scenario_id
12
13
 
13
14
  DEFAULT = {
14
- :name => '',
15
- :description => '',
16
- :enabled => true,
17
- :log_dir => '/var/log/kafo',
18
- :log_owner => nil,
19
- :log_group => nil,
20
- :store_dir => '',
21
- :log_name => 'configuration.log',
22
- :log_level => 'notice',
23
- :no_prefix => false,
24
- :mapping => {},
25
- :answer_file => './config/answers.yaml',
26
- :installer_dir => '.',
27
- :module_dirs => ['./modules'],
28
- :colors => Kafo::ColorScheme.colors_possible?,
29
- :color_of_background => :dark,
30
- :hook_dirs => [],
31
- :check_dirs => nil,
32
- :custom => {},
33
- :facts => {},
34
- :low_priority_modules => [],
35
- :verbose => false,
36
- :verbose_log_level => 'notice',
37
- :skip_puppet_version_check => false,
38
- :parser_cache_path => nil,
39
- :ignore_undocumented => nil,
40
- :order => nil,
41
- :hiera_config => nil,
42
- :kafo_modules_dir => nil,
43
- :config_header_file => nil,
44
- :dont_save_answers => nil,
15
+ ScenarioOption::NAME => '',
16
+ ScenarioOption::DESCRIPTION => '',
17
+ ScenarioOption::ENABLED => true,
18
+ ScenarioOption::LOG_DIR => '/var/log/kafo',
19
+ ScenarioOption::LOG_OWNER => nil,
20
+ ScenarioOption::LOG_GROUP => nil,
21
+ ScenarioOption::STORE_DIR => '',
22
+ ScenarioOption::LOG_NAME => 'configuration.log',
23
+ ScenarioOption::LOG_LEVEL => 'notice',
24
+ ScenarioOption::NO_PREFIX => false,
25
+ ScenarioOption::MAPPING => {},
26
+ ScenarioOption::ANSWER_FILE => './config/answers.yaml',
27
+ ScenarioOption::INSTALLER_DIR => '.',
28
+ ScenarioOption::MODULE_DIRS => ['./modules'],
29
+ ScenarioOption::COLORS => Kafo::ColorScheme.colors_possible?,
30
+ ScenarioOption::COLOR_OF_BACKGROUND => :dark,
31
+ ScenarioOption::HOOK_DIRS => [],
32
+ ScenarioOption::CHECK_DIRS => nil,
33
+ ScenarioOption::CUSTOM => {},
34
+ ScenarioOption::FACTS => {},
35
+ ScenarioOption::LOW_PRIORITY_MODULES => [],
36
+ ScenarioOption::VERBOSE => false,
37
+ ScenarioOption::VERBOSE_LOG_LEVEL => 'notice',
38
+ ScenarioOption::SKIP_PUPPET_VERSION_CHECK => false,
39
+ ScenarioOption::PARSER_CACHE_PATH => nil,
40
+ ScenarioOption::IGNORE_UNDOCUMENTED => nil,
41
+ ScenarioOption::ORDER => nil,
42
+ ScenarioOption::HIERA_CONFIG => nil,
43
+ ScenarioOption::KAFO_MODULES_DIR => nil,
44
+ ScenarioOption::CONFIG_HEADER_FILE => nil,
45
+ ScenarioOption::DONT_SAVE_ANSWERS => nil,
45
46
  }
46
47
 
47
48
  def self.get_scenario_id(filename)
@@ -129,7 +130,7 @@ module Kafo
129
130
  def modules
130
131
  @modules ||= begin
131
132
  register_data_types
132
- @data.keys.map { |mod| PuppetModule.new(mod, PuppetModule.find_parser, self).parse }.sort
133
+ @data.keys.map { |mod| PuppetModule.new(mod, configuration: self).parse }.sort
133
134
  end
134
135
  end
135
136
 
@@ -158,7 +159,7 @@ module Kafo
158
159
  end
159
160
 
160
161
  def add_module(name)
161
- mod = PuppetModule.new(name, PuppetModule.find_parser, self).parse
162
+ mod = PuppetModule.new(name, configuration: self).parse
162
163
  unless modules.map(&:name).include?(mod.name)
163
164
  mod.enable
164
165
  @modules << mod
@@ -197,7 +198,7 @@ module Kafo
197
198
  }
198
199
  EOS
199
200
 
200
- @logger.notice 'Loading default values from puppet modules...'
201
+ @logger.info "Loading default values from puppet modules..."
201
202
  command = PuppetCommand.new(dump_manifest, [], puppetconf, self).command
202
203
  stdout, stderr, status = Open3.capture3(*PuppetCommand.format_command(command))
203
204
 
@@ -222,7 +223,7 @@ EOS
222
223
  end
223
224
  end
224
225
 
225
- @logger.notice "... finished"
226
+ @logger.info "... finished loading default values from puppet modules."
226
227
 
227
228
  load_yaml_from_output(stdout.split($/))
228
229
  end
@@ -130,4 +130,4 @@ require 'kafo/data_types/struct'
130
130
  require 'kafo/data_types/tuple'
131
131
  require 'kafo/data_types/type_reference'
132
132
  require 'kafo/data_types/undef'
133
- require 'kafo/data_types/variant'
133
+ require 'kafo/data_types/wrapped_data_type'
@@ -10,7 +10,7 @@ module Kafo
10
10
  @logger = KafoConfigure.logger
11
11
  @types = {}
12
12
  manifest.each_line do |line|
13
- if (type = TYPE_DEFINITION.match(line))
13
+ if (type = TYPE_DEFINITION.match(line.force_encoding("UTF-8")))
14
14
  @types[type[1]] = type[2]
15
15
  end
16
16
  end
@@ -19,7 +19,9 @@ module Kafo
19
19
  end
20
20
 
21
21
  def typecast(value)
22
- value =~ /\d+/ ? value.to_i : value
22
+ Integer(value)
23
+ rescue TypeError, ArgumentError
24
+ value
23
25
  end
24
26
 
25
27
  def valid?(input, errors = [])
@@ -2,7 +2,9 @@ module Kafo
2
2
  module DataTypes
3
3
  class Numeric < DataType
4
4
  def typecast(value)
5
- value =~ /\d+/ ? value.to_f : value
5
+ Float(value)
6
+ rescue TypeError, ArgumentError
7
+ value
6
8
  end
7
9
 
8
10
  def valid?(input, errors = [])
@@ -7,7 +7,7 @@ module Kafo
7
7
  def_delegators :@inner_type, :condition_value, :dump_default, :multivalued?, :typecast, :valid?
8
8
 
9
9
  def initialize
10
- @inner_type = DataTypes::Variant.new('Integer', 'Float', 'String', 'Boolean', 'Regexp')
10
+ @inner_type = DataTypes::WrappedDataType.new('Integer', 'Float', 'String', 'Boolean', 'Regexp')
11
11
  end
12
12
  end
13
13
 
@@ -1,6 +1,6 @@
1
1
  module Kafo
2
2
  module DataTypes
3
- class Variant < DataType
3
+ class WrappedDataType < DataType
4
4
  def initialize(*inner_types)
5
5
  @inner_types = inner_types.map { |t| DataType.new_from_string(t) }
6
6
  end
@@ -16,7 +16,7 @@ module Kafo
16
16
  end
17
17
 
18
18
  def multivalued?
19
- @inner_types.any? { |t| t.multivalued? }
19
+ @inner_types.any?(&:multivalued?)
20
20
  end
21
21
 
22
22
  def to_s
@@ -33,7 +33,7 @@ module Kafo
33
33
  if type
34
34
  type.valid?(value, errors)
35
35
  else
36
- errors << "#{value} is not one of #{to_s}"
36
+ errors << "#{value} is not one of #{self}"
37
37
  false
38
38
  end
39
39
  end
@@ -45,6 +45,7 @@ module Kafo
45
45
  end
46
46
  end
47
47
 
48
- DataType.register_type('Variant', Variant)
48
+ DataType.register_type('Sensitive', WrappedDataType)
49
+ DataType.register_type('Variant', WrappedDataType)
49
50
  end
50
51
  end
@@ -8,7 +8,4 @@ module Kafo
8
8
 
9
9
  class ParserError < StandardError
10
10
  end
11
-
12
- class TypeError < StandardError
13
- end
14
11
  end
@@ -14,10 +14,9 @@ module Kafo
14
14
  end
15
15
 
16
16
  def self.wrapper
17
- # Ruby 2.0 doesn't have <<~ heredocs
18
- <<-WRAPPER
19
- require 'yaml'
20
- Facter.add(:kafo) { setcode { YAML.load_file(File.join(__dir__, '#{DATA_FILENAME}')) } }
17
+ <<~WRAPPER
18
+ require 'yaml'
19
+ Facter.add(:kafo) { setcode { YAML.load_file(File.join(__dir__, '#{DATA_FILENAME}')) } }
21
20
  WRAPPER
22
21
  end
23
22
  end
@@ -34,8 +34,8 @@ module Kafo
34
34
  #
35
35
  # @example
36
36
  # app_option ['-n', '--noop'], :flag, 'Run puppet in noop mode?', :default => false
37
- def app_option(*args)
38
- self.kafo.class.app_option(*args)
37
+ def app_option(*args, &block)
38
+ self.kafo.class.app_option(*args, &block)
39
39
  end
40
40
 
41
41
  # Returns whether the given app option exists. This is useful when there's a conditional option that is
data/lib/kafo/hooking.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'kafo/hook_context'
2
+ require 'kafo/multi_stage_hook'
2
3
 
3
4
  module Kafo
4
5
  class Hooking
@@ -36,6 +37,14 @@ module Kafo
36
37
  register(hook_type, file, &hook_block)
37
38
  end
38
39
  end
40
+
41
+ # Multi stage hooks are special
42
+ Dir.glob(File.join(base_dir, 'multi', '*.rb')).sort.each do |file|
43
+ logger.debug "Loading multi stage hook #{file}"
44
+ hook = File.read(file)
45
+ MultiStageHook.new(file, self, TYPES).instance_eval(hook, file, 1)
46
+ end
47
+
39
48
  @loaded = true
40
49
  end
41
50
  self
@@ -143,7 +143,14 @@ module Kafo
143
143
  # so we limit parsing only to app config options (because of --help and later defined params)
144
144
  parse clamp_app_arguments
145
145
  parse_app_arguments # set values from ARGS to config.app
146
- Logging.setup(verbose: config.app[:verbose]) unless ARGV.any? { |option| ['--help', '--full-help'].include? option }
146
+
147
+ if ARGV.any? { |option| ['--help', '--full-help'].include? option }
148
+ Logging.setup_verbose(level: :error)
149
+ else
150
+ Logging.setup(verbose: config.app[:verbose])
151
+ end
152
+
153
+ logger.notice("Loading installer configuration. This will take some time.")
147
154
  self.class.set_color_scheme
148
155
 
149
156
  self.class.hooking.execute(:init)
@@ -166,6 +173,10 @@ module Kafo
166
173
  def run(*args)
167
174
  started_at = Time.now
168
175
  logger.debug("Running installer with args #{args.inspect}")
176
+ if config.app[:verbose]
177
+ logger.notice("Running installer with log based terminal output at level #{config.app[:verbose_log_level].upcase}.")
178
+ logger.notice("Use -l to set the terminal output log level to ERROR, WARN, NOTICE, INFO, or DEBUG. See --full-help for definitions.")
179
+ end
169
180
  super
170
181
  ensure
171
182
  logger.debug("Installer finished in #{Time.now - started_at} seconds")
@@ -311,6 +322,25 @@ module Kafo
311
322
  self.class.app_option(*args, &block)
312
323
  end
313
324
 
325
+ def terminal_log_levels_message
326
+ if ARGV.include?('--full-help')
327
+ <<~HEREDOC.chomp
328
+ Log level for log based terminal output.
329
+ The available levels are
330
+ ERROR - Only show errors which prevented the installer from completing successfully.
331
+ WARN - Deprecation warnings and other information users may want to be aware of.
332
+ NOTICE - High level information about installer execution and progress.
333
+ INFO - More detailed information about execution and progress. Also shows when the installer makes a change to system configuration.
334
+ DEBUG - Show all information about execution, including configuration items where no change was needed.
335
+ HEREDOC
336
+ else
337
+ <<~HEREDOC.chomp
338
+ Log level for log based terminal output.
339
+ The available levels are ERROR, WARN, NOTICE, INFO, DEBUG. See --full-help for definitions.
340
+ HEREDOC
341
+ end
342
+ end
343
+
314
344
  def set_app_options
315
345
  app_option ['--[no-]colors'], :flag, 'Use color output on STDOUT',
316
346
  :default => config.app[:colors], :advanced => true
@@ -333,7 +363,7 @@ module Kafo
333
363
  :default => false, :advanced => true
334
364
  app_option ['-v', '--[no-]verbose'], :flag, 'Display log on STDOUT instead of progressbar',
335
365
  :default => config.app[:verbose]
336
- app_option ['-l', '--verbose-log-level'], 'LEVEL', 'Log level for verbose mode output',
366
+ app_option ['-l', '--verbose-log-level'], 'LEVEL', terminal_log_levels_message,
337
367
  :default => 'notice'
338
368
  app_option ['-S', '--scenario'], 'SCENARIO', 'Use installation scenario'
339
369
  app_option ['--disable-scenario'], 'SCENARIO', 'Disable installation scenario',
@@ -440,7 +470,7 @@ module Kafo
440
470
  end
441
471
 
442
472
  def validate_all(logging = true)
443
- logger.notice 'Running validation checks'
473
+ logger.info "Running validation checks."
444
474
  results = enabled_params.map do |param|
445
475
  result = param.valid?
446
476
  errors = param.validation_errors.join(', ')
@@ -477,13 +507,7 @@ module Kafo
477
507
  log_parser = PuppetLogParser.new
478
508
  logger = Logger.new('configure')
479
509
 
480
- start_message = <<-HEREDOC
481
- Starting system configuration.
482
- The total number of configuration tasks may increase during the run.
483
- Observe logs or specify --verbose-log-level to see individual configuration tasks.
484
- HEREDOC
485
-
486
- logger.notice(start_message.chomp)
510
+ logger.notice("Starting system configuration.")
487
511
 
488
512
  PTY.spawn(*PuppetCommand.format_command(command)) do |stdin, stdout, pid|
489
513
  begin
@@ -492,17 +516,17 @@ HEREDOC
492
516
  method, message = log_parser.parse(line)
493
517
  progress_log(method, message, logger)
494
518
 
495
- if (output = line.match(%r{(.+\]): Starting to evaluate the resource( \((?<count>\d+) of (?<total>\d+)\))?}))
496
- if (output[:count].to_i % 100) == 1 && output[:count].to_i != 1
497
- logger.notice("#{output[:count].to_i - 1} out of #{output[:total]} done.")
519
+ if (output = line.match(/(.+\]): Starting to evaluate the resource( \((?<count>\d+) of (?<total>\d+)\))?/))
520
+ if (output[:count].to_i % 250) == 1 && output[:count].to_i != 1
521
+ logger.notice("#{output[:count].to_i - 1} configuration steps out of #{output[:total]} steps complete.")
498
522
  end
499
523
  end
500
524
 
501
525
  @progress_bar.update(line) if @progress_bar
502
526
  end
503
527
  rescue Errno::EIO # we reach end of input
504
- exit_status = PTY.check(pid, true) if PTY.respond_to?(:check) # ruby >= 1.9.2
505
- if exit_status.nil? # process is still running or we have old ruby so we don't know
528
+ exit_status = PTY.check(pid, true)
529
+ if exit_status.nil? # process is still running
506
530
  begin
507
531
  Process.wait(pid)
508
532
  rescue Errno::ECHILD # process could exit meanwhile so we rescue
@@ -511,7 +535,7 @@ HEREDOC
511
535
  end
512
536
  end
513
537
  end
514
- rescue PTY::ChildExited => e # could be raised by Process.wait on older ruby or by PTY.check
538
+ rescue PTY::ChildExited => e # could be raised by PTY.check
515
539
  self.class.exit_handler.exit_code = e.status.exitstatus
516
540
  end
517
541
 
@@ -540,11 +564,7 @@ HEREDOC
540
564
  end
541
565
 
542
566
  def normalize_encoding(line)
543
- if line.respond_to?(:encode) && line.respond_to?(:valid_encoding?)
544
- line.valid_encoding? ? line : line.encode('UTF-16be', :invalid => :replace, :replace => '?').encode('UTF-8')
545
- else # Ruby 1.8.7, doesn't worry about invalid encodings
546
- line
547
- end
567
+ line.valid_encoding? ? line : line.encode('UTF-16be', :invalid => :replace, :replace => '?').encode('UTF-8')
548
568
  end
549
569
  end
550
570
  end
data/lib/kafo/logger.rb CHANGED
@@ -13,7 +13,13 @@ module Kafo
13
13
 
14
14
  def log(level, *args, &block)
15
15
  if Logging.buffering?
16
- Logging.to_buffer(@name, level, args, &block)
16
+ if block_given?
17
+ data = yield
18
+ else
19
+ data = args
20
+ end
21
+
22
+ Logging.to_buffer(@name, ::Logging::LogEvent.new(@name, ::Logging::LEVELS[level.to_s], data, false))
17
23
  else
18
24
  Logging.dump_buffer if Logging.dump_needed?
19
25
  @logger.send(level, *args, &block)
data/lib/kafo/logging.rb CHANGED
@@ -118,7 +118,7 @@ module Kafo
118
118
 
119
119
  def dump_buffer
120
120
  @buffer.each do |log|
121
- ::Logging.logger[log[0]].send(log[1], *([log[2]].flatten(2)), &log[3])
121
+ ::Logging.logger[log[0]].send(:log_event, log[1])
122
122
  end
123
123
  @buffer.clear
124
124
  end
@@ -0,0 +1,13 @@
1
+ module Kafo
2
+ class MultiStageHook
3
+ def initialize(name, registry, types)
4
+ default_name = name
5
+
6
+ types.each do |hook_type|
7
+ self.class.send(:define_method, hook_type) do |name=nil, &block|
8
+ registry.send(:register, hook_type, name || default_name, &block)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -25,7 +25,7 @@ module Kafo
25
25
  end
26
26
  end
27
27
 
28
- def initialize(identifier, parser = self.class.find_parser, configuration = KafoConfigure.config)
28
+ def initialize(identifier, parser: nil, configuration: KafoConfigure.config)
29
29
  @identifier = identifier
30
30
  @configuration = configuration
31
31
  @name = get_name
@@ -65,6 +65,7 @@ module Kafo
65
65
  def parse(builder_klass = ParamBuilder)
66
66
  @raw_data = @parser_cache.get(identifier, manifest_path) if @parser_cache
67
67
  if @raw_data.nil?
68
+ @parser = self.class.find_parser if @parser.nil?
68
69
  if @parser.nil? || @parser == :none
69
70
  raise ParserError.new("No Puppet module parser is installed and no cache of the file #{manifest_path} is available. Please check debug logs and install optional dependencies for the parser.")
70
71
  else
@@ -80,7 +81,7 @@ module Kafo
80
81
 
81
82
  self
82
83
  rescue ConfigurationException => e
83
- @logger.fatal "Unable to continue because of: #{e.message}"
84
+ @logger.fatal "Unable to parse #{manifest_path} because of: #{e.message}"
84
85
  KafoConfigure.exit(:manifest_error)
85
86
  end
86
87
 
@@ -0,0 +1,92 @@
1
+ module Kafo
2
+ # A class containing constants for all scenario options
3
+ class ScenarioOption
4
+ # @group Basic
5
+
6
+ # Human readable scenario name
7
+ NAME = :name
8
+
9
+ # Description of the installer scenario and its purpose
10
+ DESCRIPTION = :description
11
+
12
+ # Path to answer file, if the file does not exist a $pwd/config/answers.yaml is used as a fallback
13
+ ANSWER_FILE = :answer_file
14
+
15
+ # Enable colors? If you don't touch this, we'll autodetect terminal capabilities
16
+ COLORS = :colors
17
+ # Color scheme, we support :bright and :dark (first is better for white background, dark for black background)
18
+ COLOR_OF_BACKGROUND = :color_of_background
19
+
20
+ # @group Logging
21
+
22
+ # Destination for the log files
23
+ LOG_DIR = :log_dir
24
+ LOG_NAME = :log_name
25
+ LOG_LEVEL = :log_level
26
+ LOG_OWNER = :log_owner
27
+ LOG_GROUP = :log_group
28
+
29
+ # Whether verbose logging is enabled
30
+ VERBOSE = :verbose
31
+
32
+ # When verbose logging is enabled, which level (and up) is shown.
33
+ VERBOSE_LOG_LEVEL = :verbose_log_level
34
+
35
+ # @group State
36
+
37
+ # Custom storage is handy if you use hooks and you must store some
38
+ # configuration which should persist among installer runs. It can be also
39
+ # used for passing value from one hook to another.
40
+ CUSTOM = :custom
41
+
42
+ FACTS = :facts
43
+
44
+ # @group Advanced
45
+
46
+ # Checks, implemented as executable files, are loaded from the listed
47
+ # directories.
48
+ CHECK_DIRS = :check_dirs
49
+
50
+ # Hooks in these extra directories will be loaded, by default they are
51
+ # loaded from $installer_dir/hooks/$type when you specify your directory,
52
+ # it will be search for $yourdir/$type/*.rb
53
+ HOOK_DIRS = :hook_dirs
54
+
55
+ # Option to load puppet modules from a specific path. Optional and
56
+ # $pwd/modules is used by default, multiple dirs are allowed
57
+ MODULE_DIRS = :module_dirs
58
+
59
+ # Kafo has a cache for information parsed from Puppet modules. This
60
+ # determines the location where that information is stored.
61
+ PARSER_CACHE_PATH = :parser_cache_path
62
+
63
+ # By default all module parameters must be documented or an error is
64
+ # raised. This can be used to not raise an error when undocumented
65
+ # parameters are found.
66
+ IGNORE_UNDOCUMENTED = :ignore_undocumented
67
+
68
+ # Kafo tuning, customization of core functionality
69
+
70
+ # An optional mapping of classes
71
+ MAPPING = :mapping
72
+ NO_PREFIX = :no_prefix
73
+ ORDER = :order
74
+ LOW_PRIORITY_MODULES = :low_priority_modules
75
+ HIERA_CONFIG = :hiera_config
76
+ KAFO_MODULES_DIR = :kafo_modules_dir
77
+ CONFIG_HEADER_FILE = :config_header_file
78
+ DONT_SAVE_ANSWERS = :dont_save_answers
79
+
80
+ # These options are in DEFAULT but not in kafo.yaml.example
81
+
82
+ # Whether the scenario is enabled or not
83
+ ENABLED = :enabled
84
+ STORE_DIR = :store_dir
85
+ INSTALLER_DIR = :installer_dir
86
+
87
+ # Puppet modules declare the Puppet version they're compatible with. Kafo
88
+ # implements checks to verify this is correct with the Puppet version
89
+ # that's running. This can be used to bypass the checks
90
+ SKIP_PUPPET_VERSION_CHECK = :skip_puppet_version_check
91
+ end
92
+ end
data/lib/kafo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
  module Kafo
3
3
  PARSER_CACHE_VERSION = 1
4
- VERSION = "6.2.1"
4
+ VERSION = "6.4.1"
5
5
  end
data/lib/kafo/wizard.rb CHANGED
@@ -15,7 +15,7 @@ module Kafo
15
15
  OK = utf_support? ? '✓' : 'y'
16
16
  NO = utf_support? ? '✗' : 'n'
17
17
 
18
- def initialize(kafo, input=$stdin, output=$stdout)
18
+ def initialize(kafo, input = $stdin, output = $stdout)
19
19
  @kafo = kafo
20
20
  @config = kafo.config
21
21
  @name = @config.app[:name] || 'Kafo'
@@ -10,6 +10,13 @@ Puppet::Functions.create_function(:'kafo_configure::dump_lookups') do
10
10
  end
11
11
 
12
12
  def dump_lookups(parameters)
13
- Hash[parameters.map { |param| [param, call_function('lookup', [param], 'default_value' => nil)] }]
13
+ Hash[parameters.map { |param| [param, lookup(param)] }]
14
+ end
15
+
16
+ private
17
+
18
+ def lookup(param)
19
+ value = call_function('lookup', [param], 'default_value' => nil)
20
+ value.respond_to?(:unwrap) ? value.unwrap : value
14
21
  end
15
22
  end
@@ -8,6 +8,12 @@ Puppet::Functions.create_function(:'kafo_configure::dump_variables') do
8
8
 
9
9
  def dump_variables(variables)
10
10
  scope = closure_scope
11
- Hash[variables.map { |var| [var, scope[var]] }]
11
+ Hash[variables.map { |var| [var, unwrap(scope[var])] }]
12
+ end
13
+
14
+ private
15
+
16
+ def unwrap(value)
17
+ value.respond_to?(:unwrap) ? value.unwrap : value
12
18
  end
13
19
  end
@@ -9,7 +9,7 @@
9
9
  "requirements": [
10
10
  {
11
11
  "name": "puppet",
12
- "version_requirement": ">= 4.5.0 < 7.0.0"
12
+ "version_requirement": ">= 4.5.0 < 8.0.0"
13
13
  }
14
14
  ]
15
15
  }
@@ -2,3 +2,8 @@
2
2
  classes:
3
3
  - dummy
4
4
  my_module::param: override
5
+ my_module::password: batteryhorsestaple
6
+
7
+ lookup_options:
8
+ my_module::password:
9
+ convert_to: "Sensitive"
@@ -1,5 +1,6 @@
1
1
  class dummy (
2
2
  String $first = $dummy::params::first,
3
3
  Optional[Integer] $second = undef,
4
+ Sensitive[String[1]] $password = $dummy::params::password,
4
5
  ) inherits dummy::params {
5
6
  }
@@ -1,3 +1,4 @@
1
1
  class dummy::params {
2
2
  $first = 'foo'
3
+ $password = Sensitive('supersecret')
3
4
  }
@@ -4,4 +4,5 @@ describe 'kafo_configure::dump_lookups' do
4
4
  let(:hiera_config) { 'spec/fixtures/hiera/hiera.yaml' }
5
5
  it { is_expected.to run.with_params([]).and_return({}) }
6
6
  it { is_expected.to run.with_params(['my_module::param']).and_return({'my_module::param' => 'override'}) }
7
+ it { is_expected.to run.with_params(['my_module::password']).and_return({'my_module::password' => 'batteryhorsestaple'}) }
7
8
  end
@@ -6,5 +6,6 @@ describe 'kafo_configure::dump_variables' do
6
6
  context 'with values' do
7
7
  let(:pre_condition) { 'include dummy' }
8
8
  it { is_expected.to run.with_params(['dummy::first']).and_return({'dummy::first' => 'foo'}) }
9
+ it { is_expected.to run.with_params(['dummy::password']).and_return({'dummy::password' => 'supersecret'}) }
9
10
  end
10
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kafo
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.2.1
4
+ version: 6.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Hulan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-22 00:00:00.000000000 Z
11
+ date: 2022-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -245,7 +245,7 @@ files:
245
245
  - lib/kafo/data_types/tuple.rb
246
246
  - lib/kafo/data_types/type_reference.rb
247
247
  - lib/kafo/data_types/undef.rb
248
- - lib/kafo/data_types/variant.rb
248
+ - lib/kafo/data_types/wrapped_data_type.rb
249
249
  - lib/kafo/exceptions.rb
250
250
  - lib/kafo/execution_environment.rb
251
251
  - lib/kafo/exit_handler.rb
@@ -262,6 +262,7 @@ files:
262
262
  - lib/kafo/logging.rb
263
263
  - lib/kafo/migration_context.rb
264
264
  - lib/kafo/migrations.rb
265
+ - lib/kafo/multi_stage_hook.rb
265
266
  - lib/kafo/param.rb
266
267
  - lib/kafo/param_builder.rb
267
268
  - lib/kafo/param_group.rb
@@ -275,6 +276,7 @@ files:
275
276
  - lib/kafo/puppet_log_parser.rb
276
277
  - lib/kafo/puppet_module.rb
277
278
  - lib/kafo/scenario_manager.rb
279
+ - lib/kafo/scenario_option.rb
278
280
  - lib/kafo/store.rb
279
281
  - lib/kafo/string_helper.rb
280
282
  - lib/kafo/system_checker.rb
@@ -318,7 +320,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
318
320
  - !ruby/object:Gem::Version
319
321
  version: '0'
320
322
  requirements: []
321
- rubygems_version: 3.1.4
323
+ rubygems_version: 3.2.22
322
324
  signing_key:
323
325
  specification_version: 4
324
326
  summary: A gem for making installations based on puppet user friendly