kitchen-pulumi 0.1.0 → 0.1.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: d6c0ce9de8379c66a261cbc65cf916a72cc46f44b1dd1fa75351807a9a38d828
4
- data.tar.gz: 7e346277daebaa03ca622ca61a694004d412d6a0b6f2fc1badea8d8f752b33f9
3
+ metadata.gz: bef54f1efc387dfe35e325959ecccb66b21d8e8c5073b3d29b6d525f22c4ffd1
4
+ data.tar.gz: b2452427f21971500e1c1a426b59c5ba079c2ca03694b5d2cd10753e9c788112
5
5
  SHA512:
6
- metadata.gz: 88631c7633e26c60539e22deefb778bf44e5f438d2af53101ea5645a02d3633997358ef04747f85f3f12a405ad797e76a96b469eceb262850bd0b4e275eec0d5
7
- data.tar.gz: b1ec83259b24dad3c038c77f471655ee34ead9b3478cbf5db9942f5c8db4c264d801fae99e14bc889e9f13a4a0b1d9eaeaebb820a1de779d4b13d1b7f8719fd9
6
+ metadata.gz: cf7d2e24412bbff79c4405d5bf1c2d0e377c7bb2e16ba273c053bbd93403094930a6179e7482fa22ebb9f506990670a3ce379ec41999c2e28219e40266f55cc6
7
+ data.tar.gz: d0d04b21f872eb55305c728d11682913d69673ed163e73f2d84e050a3c7ce8a340ffc1e2b672710f37fafe0e4e622ae1e3a1b8e621e462f7417e4df8f0d9910f
@@ -3,19 +3,19 @@
3
3
  require 'kitchen/pulumi/error'
4
4
  require 'kitchen/pulumi/inspec_with_hosts'
5
5
  require 'kitchen/pulumi/inspec_without_hosts'
6
- require 'kitchen/pulumi/system_attrs_resolver'
6
+ require 'kitchen/pulumi/system_inputs_resolver'
7
7
  require 'kitchen/pulumi/system_hosts_resolver'
8
8
 
9
9
  module Kitchen
10
10
  module Pulumi
11
11
  # System is the class of objects which are verified by the Pulumi Verifier.
12
12
  class System
13
- # #add_attrs adds attributes to the system.
13
+ # #add_inputs adds Inspec Inputs to the system.
14
14
  #
15
- # @param attrs [#to_hash] the attributes to be added.
15
+ # @param inputs [#to_hash] the inputs to be added.
16
16
  # @return [self]
17
- def add_attrs(attrs:)
18
- @attributes = @attributes.merge Hash attrs
17
+ def add_inputs(inputs:)
18
+ @inputs = @inputs.merge Hash inputs
19
19
 
20
20
  self
21
21
  end
@@ -51,15 +51,15 @@ module Kitchen
51
51
 
52
52
  # #verify verifies the system by executing InSpec.
53
53
  #
54
- # @param inputs [::Hash] the Pulumi input values to be utilized as
55
- # InSpec profile attributes.
54
+ # @param pulumi_inputs [::Hash] the Pulumi input values to be utilized as
55
+ # InSpec profile Input.
56
+ # @param pulumi_outputs [::Hash] the Pulumi output values to be utilized as
57
+ # InSpec profile Input.
56
58
  # @param inspec_options [::Hash] the options to be passed to InSpec.
57
- # @param outputs [::Hash] the Pulumi output values to be utilized as
58
- # InSpec profile attributes.
59
59
  # @return [self]
60
- def verify(inputs:, inspec_options:, outputs:)
61
- resolve inputs: inputs, outputs: outputs
62
- execute_inspec options: inspec_options
60
+ def verify(pulumi_inputs:, pulumi_outputs:, inspec_options:)
61
+ resolve(pulumi_inputs: pulumi_inputs, pulumi_outputs: pulumi_outputs)
62
+ execute_inspec(options: inspec_options)
63
63
 
64
64
  self
65
65
  rescue StandardError => e
@@ -70,16 +70,13 @@ module Kitchen
70
70
 
71
71
  def execute_inspec(options:)
72
72
  inspec.new(
73
- options: options_with_attributes(options: options),
73
+ options: options_with_inputs(options: options),
74
74
  profile_locations: @mapping.fetch(:profile_locations),
75
75
  ).exec(system: self)
76
76
  end
77
77
 
78
78
  def initialize(mapping:)
79
- @attributes = {}
80
- @attrs_outputs = mapping.fetch :attrs_outputs do
81
- {}
82
- end
79
+ @inputs = {}
83
80
  @hosts = mapping.fetch :hosts do
84
81
  []
85
82
  end
@@ -94,31 +91,27 @@ module Kitchen
94
91
  end
95
92
  end
96
93
 
97
- def options_with_attributes(options:)
98
- options.merge attributes: @attributes
94
+ def options_with_inputs(options:)
95
+ options.merge(inputs: @inputs)
99
96
  end
100
97
 
101
- def resolve(inputs:, outputs:)
102
- resolve_attrs inputs: inputs, outputs: outputs
103
- resolve_hosts outputs: outputs
98
+ def resolve(pulumi_inputs:, pulumi_outputs:)
99
+ resolve_inputs(pulumi_inputs: pulumi_inputs, pulumi_outputs: pulumi_outputs)
100
+ resolve_hosts(pulumi_outputs: pulumi_outputs)
104
101
  end
105
102
 
106
- def resolve_attrs(inputs:, outputs:)
107
- ::Kitchen::Pulumi::SystemAttrsResolver.new(
108
- inputs: inputs, outputs: outputs,
109
- ).resolve(
110
- attrs_outputs_keys: @attrs_outputs.keys,
111
- attrs_outputs_values: @attrs_outputs.values,
112
- system: self,
113
- )
103
+ def resolve_inputs(pulumi_inputs:, pulumi_outputs:)
104
+ ::Kitchen::Pulumi::SystemInputsResolver.new(
105
+ pulumi_inputs: pulumi_inputs, pulumi_outputs: pulumi_outputs, system: self,
106
+ ).resolve
114
107
 
115
108
  self
116
109
  end
117
110
 
118
- def resolve_hosts(outputs:)
119
- return self unless @mapping.key? :hosts_output
111
+ def resolve_hosts(pulumi_outputs:)
112
+ return self unless @mapping.key?(:hosts_output)
120
113
 
121
- ::Kitchen::Pulumi::SystemHostsResolver.new(outputs: outputs).resolve(
114
+ ::Kitchen::Pulumi::SystemHostsResolver.new(outputs: pulumi_outputs).resolve(
122
115
  hosts_output: @mapping.fetch(:hosts_output),
123
116
  system: self,
124
117
  )
@@ -27,7 +27,7 @@ module Kitchen
27
27
  #
28
28
  # @param outputs [#to_hash] the outputs of the Pulumi stack under test.
29
29
  def initialize(outputs:)
30
- @outputs = Hash[outputs]
30
+ @outputs = outputs.to_h
31
31
  end
32
32
  end
33
33
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kitchen/pulumi'
4
+ require 'kitchen/pulumi/error'
5
+
6
+ module Kitchen
7
+ module Pulumi
8
+ # SystemInputssResolver is the class for resolving Pulumi stack inputs and
9
+ # outputs to provide them as Inspec Inputs.
10
+ class SystemInputsResolver
11
+ # #resolve resolves the inputs.
12
+ #
13
+ # @raise [::Kitchen::Pulumi::Error] if the fetching the value of the
14
+ # output fails.
15
+ def resolve
16
+ @system.add_inputs(inputs: @pulumi_inputs.merge(@pulumi_outputs))
17
+ self
18
+ rescue ::KeyError => e
19
+ raise ::Kitchen::Pulumi::Error, "Resolving inputs failed\n#{e}"
20
+ end
21
+
22
+ private
23
+
24
+ # #initialize prepares the instance to be used.
25
+ #
26
+ # @param pulumi_inputs [#to_hash] the config inputs provided to a Pulumi stack
27
+ # @param pulumi_outputs [#to_hash] the outputs of the Pulumi stack under test.
28
+ # @param system [::Kitchen::Pulumi::System] the system.
29
+ def initialize(pulumi_inputs:, pulumi_outputs:, system:)
30
+ @system = system
31
+ @pulumi_inputs = pulumi_inputs.transform_values do |value|
32
+ value.fetch('value', nil)
33
+ end
34
+ @pulumi_inputs.merge!(@pulumi_inputs.transform_keys { |key| "input_#{key}" })
35
+
36
+ @pulumi_outputs = pulumi_outputs.to_h.map do |key, value|
37
+ [key, value]
38
+ end.to_h
39
+ @pulumi_outputs.merge!(@pulumi_outputs.transform_keys { |key| "output_#{key}" })
40
+ rescue ::KeyError => e
41
+ raise ::Kitchen::Pulumi::Error, "System input resolution failed\n#{e}"
42
+ end
43
+ end
44
+ end
45
+ end
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'kitchen/pulumi'
4
4
 
5
- ::Kitchen::Pulumi::VERSION = '0.1.0'
5
+ ::Kitchen::Pulumi::VERSION = '0.1.1'
@@ -72,14 +72,14 @@ module Kitchen
72
72
  include ::Kitchen::Pulumi::Configurable
73
73
  @api_version = 2
74
74
 
75
- attr_reader :inputs, :outputs
75
+ attr_reader :pulumi_inputs, :pulumi_outputs
76
76
 
77
77
  def initialize(configuration = {})
78
78
  super(configuration)
79
- self.inspec_options_mapper = ::Kitchen::Pulumi::InSpecOptionsMapper.new
80
- self.error_messages = []
81
- self.inputs = {}
82
- self.outputs = {}
79
+ @inspec_options_mapper = ::Kitchen::Pulumi::InSpecOptionsMapper.new
80
+ @error_messages = []
81
+ @pulumi_inputs = {}
82
+ @pulumi_outputs = {}
83
83
  end
84
84
 
85
85
  # The verifier enumerates through each host of each system and verifies
@@ -112,7 +112,7 @@ module Kitchen
112
112
  private
113
113
 
114
114
  attr_accessor :inspec_options_mapper, :error_messages
115
- attr_writer :inputs, :outputs
115
+ attr_writer :pulumi_inputs, :pulumi_outputs
116
116
 
117
117
  # Raises an error immediately if the `fail_fast` config attribute is set on the
118
118
  # or collects all errors until execution has ended verifier
@@ -131,11 +131,11 @@ module Kitchen
131
131
  # @return [void]
132
132
  def load_variables
133
133
  instance.driver.stack_outputs do |outputs:|
134
- self.outputs.replace(outputs)
134
+ @pulumi_outputs.replace(outputs)
135
135
  end
136
136
 
137
137
  instance.driver.stack_inputs do |inputs:|
138
- self.inputs.replace(inputs)
138
+ @pulumi_inputs.replace(inputs)
139
139
  end
140
140
  end
141
141
 
@@ -171,9 +171,9 @@ module Kitchen
171
171
  ],
172
172
  }.merge(system),
173
173
  ).verify(
174
- inputs: inputs,
174
+ pulumi_inputs: @pulumi_inputs,
175
+ pulumi_outputs: @pulumi_outputs,
175
176
  inspec_options: system_inspec_options(system: system),
176
- outputs: outputs,
177
177
  )
178
178
  rescue StandardError => e
179
179
  handle_error message: e.message
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-pulumi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Learned
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-31 00:00:00.000000000 Z
11
+ date: 2021-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '1.9'
131
+ version: '1.10'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '1.9'
138
+ version: '1.10'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rubocop-rake
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -263,7 +263,7 @@ dependencies:
263
263
  version: '2.1'
264
264
  - - "<"
265
265
  - !ruby/object:Gem::Version
266
- version: '2.4'
266
+ version: '2.6'
267
267
  type: :runtime
268
268
  prerelease: false
269
269
  version_requirements: !ruby/object:Gem::Requirement
@@ -273,7 +273,7 @@ dependencies:
273
273
  version: '2.1'
274
274
  - - "<"
275
275
  - !ruby/object:Gem::Version
276
- version: '2.4'
276
+ version: '2.6'
277
277
  - !ruby/object:Gem::Dependency
278
278
  name: mixlib-shellout
279
279
  requirement: !ruby/object:Gem::Requirement
@@ -370,8 +370,8 @@ files:
370
370
  - lib/kitchen/pulumi/kitchen_instance.rb
371
371
  - lib/kitchen/pulumi/shell_out.rb
372
372
  - lib/kitchen/pulumi/system.rb
373
- - lib/kitchen/pulumi/system_attrs_resolver.rb
374
373
  - lib/kitchen/pulumi/system_hosts_resolver.rb
374
+ - lib/kitchen/pulumi/system_inputs_resolver.rb
375
375
  - lib/kitchen/pulumi/version.rb
376
376
  - lib/kitchen/verifier/pulumi.rb
377
377
  homepage: https://github.com/jacoblearned/kitchen-pulumi
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'kitchen/pulumi'
4
- require 'kitchen/pulumi/error'
5
-
6
- module Kitchen
7
- module Pulumi
8
- # SystemAttrsResolver is the class of objects which resolve for systems the
9
- # attrs which are contained in outputs.
10
- class SystemAttrsResolver
11
- # #resolve resolves the attrs.
12
- #
13
- # @param attrs_outputs_keys [::Array<::String>] the names of the InSpec
14
- # attributes.
15
- # @param attrs_outputs_values [::Array<::String>] the names of the Pulumi
16
- # outputs.
17
- # @param system [::Kitchen::Pulumi::System] the system.
18
- # @raise [::Kitchen::Pulumi::Error] if the fetching the value of the
19
- # output fails.
20
- def resolve(attrs_outputs_keys:, attrs_outputs_values:, system:)
21
- system.add_attrs(attrs: @inputs.merge(
22
- @outputs.merge(
23
- attrs_outputs_keys.lazy.map(&:to_s).zip(
24
- @outputs.fetch_values(*attrs_outputs_values),
25
- ).to_h,
26
- ),
27
- ))
28
-
29
- self
30
- rescue ::KeyError => e
31
- raise ::Kitchen::Pulumi::Error, "Resolving attrs failed\n#{e}"
32
- end
33
-
34
- private
35
-
36
- # #initialize prepares the instance to be used.
37
- #
38
- # @param inputs [#to_hash] the config inputs provided to a stack
39
- # @param outputs [#to_hash] the outputs of the Pulumi stack under test.
40
- def initialize(inputs:, outputs:)
41
- @inputs = inputs.transform_values do |value|
42
- value.fetch('value', nil)
43
- end
44
- @inputs.merge!(@inputs.transform_keys { |key| "input_#{key}" })
45
-
46
- @outputs = Hash[outputs].map do |key, value|
47
- [key, value]
48
- end.to_h
49
- @outputs.merge!(@outputs.transform_keys { |key| "output_#{key}" })
50
- rescue ::KeyError => e
51
- raise ::Kitchen::Pulumi::Error, "System attrs resolution failed\n#{e}"
52
- end
53
- end
54
- end
55
- end