kafo 6.4.0 → 6.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4298932fae581df1967c430be034c621ed435954ac95acf7cf7b23c9b7692d40
4
- data.tar.gz: 8ce698b286d5ec94c19adfcfc23e541c8b0599cb1399e689ee00b4413668552c
3
+ metadata.gz: 674a595f056324470ff9175d38779f7ab8c153e044ab4892dc99ca0d6487b7ba
4
+ data.tar.gz: 83ffe976aa56291ebad41e0e7ba22d72908bbe299d926bb1af1aa5b1fbef0a75
5
5
  SHA512:
6
- metadata.gz: 769146a010f1007993961a0075a03b1cbf9c4055a59bd8259940379662eaa36003ad5a83b746452e8dd0b35ea47640eb1a3064516a7a776d6e8030c6403321a1
7
- data.tar.gz: dd05194e14a17c54a205b5eacc35677b78fe4f036b8ab851972a8301c59b1e327555dd065772d82476a190d878d50226ed0253afe1c5dc129496ee316555bac3
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
@@ -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
@@ -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
@@ -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
@@ -525,8 +525,8 @@ module Kafo
525
525
  @progress_bar.update(line) if @progress_bar
526
526
  end
527
527
  rescue Errno::EIO # we reach end of input
528
- exit_status = PTY.check(pid, true) if PTY.respond_to?(:check) # ruby >= 1.9.2
529
- 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
530
530
  begin
531
531
  Process.wait(pid)
532
532
  rescue Errno::ECHILD # process could exit meanwhile so we rescue
@@ -535,7 +535,7 @@ module Kafo
535
535
  end
536
536
  end
537
537
  end
538
- 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
539
539
  self.class.exit_handler.exit_code = e.status.exitstatus
540
540
  end
541
541
 
@@ -564,11 +564,7 @@ module Kafo
564
564
  end
565
565
 
566
566
  def normalize_encoding(line)
567
- if line.respond_to?(:encode) && line.respond_to?(:valid_encoding?)
568
- line.valid_encoding? ? line : line.encode('UTF-16be', :invalid => :replace, :replace => '?').encode('UTF-8')
569
- else # Ruby 1.8.7, doesn't worry about invalid encodings
570
- line
571
- end
567
+ line.valid_encoding? ? line : line.encode('UTF-16be', :invalid => :replace, :replace => '?').encode('UTF-8')
572
568
  end
573
569
  end
574
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
@@ -81,7 +81,7 @@ module Kafo
81
81
 
82
82
  self
83
83
  rescue ConfigurationException => e
84
- @logger.fatal "Unable to continue because of: #{e.message}"
84
+ @logger.fatal "Unable to parse #{manifest_path} because of: #{e.message}"
85
85
  KafoConfigure.exit(:manifest_error)
86
86
  end
87
87
 
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.4.0"
4
+ VERSION = "6.4.1"
5
5
  end
@@ -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
@@ -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.4.0
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-05-07 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
@@ -320,7 +320,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
320
320
  - !ruby/object:Gem::Version
321
321
  version: '0'
322
322
  requirements: []
323
- rubygems_version: 3.1.6
323
+ rubygems_version: 3.2.22
324
324
  signing_key:
325
325
  specification_version: 4
326
326
  summary: A gem for making installations based on puppet user friendly