sfn 3.0.24 → 3.0.26

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
  SHA1:
3
- metadata.gz: 4c7a832bd18a4660d0184280dc1818f2fe13aeaa
4
- data.tar.gz: 6fd33f44b62ac8c3ca7836963e9c22ba355d5e9a
3
+ metadata.gz: 1000514f95a36a106dc13fd6eaf7a38a9e716776
4
+ data.tar.gz: fc0d733bafcd09198a2a56252c574956ded1ae22
5
5
  SHA512:
6
- metadata.gz: 7a2392c1bbfe0bd9f7a1c5bebf5f1c9ec316a262286757cecbdfd9b56df3c8bc1bb7e79b606f993149f3f5994fa31d8bc4a69644f0f9ab7dcc1d1978da247eec
7
- data.tar.gz: f66df1b8a616ed132f51a2ec06d7495fc3eb93499d79171b16f38a4346fe7f67900a0e76d70eb99c57ba1e768f070985c9cae112f45020f2a8a7327b0b854d5c
6
+ metadata.gz: 7ef25e6f6722a338b428d5707dde1912d0c94a8c3adab30a297fe9ad830f0cbc415eff1130e3f824bcc0d46bd2f6e423259595f6093486dd3efe51d50e8d801c
7
+ data.tar.gz: a179f76dd94173102a5e6d07fb20e91a4f689b21a02a6d79024d09bc10c373dee37403f8e15e7152692642de738c457039d76523c9a5c693408e195df8e2b4dc
@@ -1,3 +1,11 @@
1
+ # v3.0.26
2
+ * [fix] Properly support compile time parameter setting with/without stack name (#261)
3
+ * [fix] Default stack name when storing policy internally if no name provided
4
+ * [fix] Apply stack parameters via accessor on update so changes are detected properly
5
+ * [fix] Prevent planner from splitting non-String values
6
+ * [fix] Process template through grapher as dumped Hash, error on non-AWS providers
7
+ * [enhancement] Support processing complex compile time parameter types
8
+
1
9
  # v3.0.24
2
10
  * [fix] Quieter print only output (#258)
3
11
  * [fix] Require all modules for lint (#248)
@@ -63,7 +63,7 @@ module Sfn
63
63
  # @param info [Hash]
64
64
  def template(info)
65
65
  if(info[:sparkle_stack])
66
- @policies.set(info[:stack_name],
66
+ @policies.set(info.fetch(:stack_name, 'unknown'),
67
67
  info[:sparkle_stack].generate_policy
68
68
  )
69
69
  end
@@ -21,34 +21,40 @@ module Sfn
21
21
  config[:print_only] = true
22
22
  validate_graph_style!
23
23
  file = load_template_file
24
- @outputs = Smash.new
25
- ui.info "Template resource graph generation - Style: #{ui.color(config[:graph_style], :bold)}"
26
- if(config[:file])
27
- ui.puts " -> path: #{config[:file]}"
28
- end
29
- run_action 'Pre-processing template for graphing' do
30
- output_discovery(file, @outputs, nil, nil)
31
- ui.debug 'Output remapping results from pre-processing:'
32
- @outputs.each_pair do |o_key, o_value|
33
- ui.debug "#{o_key} -> #{o_value}"
24
+ if(file.provider == :aws)
25
+ @outputs = Smash.new
26
+ ui.info "Template resource graph generation - Style: #{ui.color(config[:graph_style], :bold)}"
27
+ if(config[:file])
28
+ ui.puts " -> path: #{config[:file]}"
34
29
  end
35
- nil
36
- end
37
- graph = nil
38
- run_action 'Generating resource graph' do
39
- graph = generate_graph(file)
40
- nil
41
- end
42
- run_action 'Writing graph result' do
43
- FileUtils.mkdir_p(File.dirname(config[:output_file]))
44
- if(config[:output_type] == 'dot')
45
- File.open("#{config[:output_file]}.dot", 'w') do |o_file|
46
- o_file.puts graph.to_s
30
+ template_dump = file.compile.dump!.to_smash
31
+ run_action 'Pre-processing template for graphing' do
32
+ output_discovery(template_dump, @outputs, nil, nil)
33
+ ui.debug 'Output remapping results from pre-processing:'
34
+ @outputs.each_pair do |o_key, o_value|
35
+ ui.debug "#{o_key} -> #{o_value}"
47
36
  end
48
- else
49
- graph.save config[:output_file], config[:output_type]
37
+ nil
38
+ end
39
+ graph = nil
40
+ run_action 'Generating resource graph' do
41
+ graph = generate_graph(template_dump)
42
+ nil
50
43
  end
51
- nil
44
+ run_action 'Writing graph result' do
45
+ FileUtils.mkdir_p(File.dirname(config[:output_file]))
46
+ if(config[:output_type] == 'dot')
47
+ File.open("#{config[:output_file]}.dot", 'w') do |o_file|
48
+ o_file.puts graph.to_s
49
+ end
50
+ else
51
+ graph.save config[:output_file], config[:output_type]
52
+ end
53
+ nil
54
+ end
55
+ else
56
+ ui.error "Graphing for provider `#{file.provider}` not currently supported."
57
+ ui.error "Currently supported providers: `aws`."
52
58
  end
53
59
  end
54
60
 
@@ -72,11 +78,11 @@ module Sfn
72
78
  end
73
79
 
74
80
  def output_discovery(template, outputs, resource_name, parent_template, name='')
75
- unless(template.resources.nil?)
76
- template.resources.keys!.each do |r_name|
77
- r_info = template.resources[r_name]
78
- if(r_info.type == template._self.stack_resource_name)
79
- output_discovery(r_info.properties.stack, outputs, r_name, template, r_name)
81
+ if(template['Resources'])
82
+ template['Resources'].keys.each do |r_name|
83
+ r_info = template['Resources'][r_name]
84
+ if(r_info['Type'] == 'AWS::CloudFormation::Stack')
85
+ output_discovery(r_info['Properties']['Stack'], outputs, r_name, template, r_name)
80
86
  end
81
87
  end
82
88
  end
@@ -51,6 +51,8 @@ module Sfn
51
51
  ui.debug "Compile parameters - #{config[:compile_parameters]}"
52
52
  file = load_template_file(:stack => stack)
53
53
  stack_info << " #{ui.color('Path:', :bold)} #{config[:file]}"
54
+ else
55
+ file = stack.template.dup if config[:plan]
54
56
  end
55
57
 
56
58
  unless(stack)
@@ -114,20 +116,20 @@ module Sfn
114
116
  end
115
117
  end
116
118
  stack.parameters = config_root_parameters
119
+
120
+ if(config[:upload_root_template])
121
+ upload_result = store_template(name, file, Smash.new)
122
+ stack.template_url = upload_result[:url]
123
+ else
124
+ stack.template = parameter_scrub!(template_content(file, :scrub))
125
+ end
117
126
  else
118
127
  apply_stacks!(stack)
119
128
  original_parameters = stack.parameters
120
- populate_parameters!(file, :current_parameters => stack.root_parameters)
129
+ populate_parameters!(stack.template, :current_parameters => stack.root_parameters)
121
130
  stack.parameters = config_root_parameters
122
131
  end
123
132
 
124
- if(config[:upload_root_template])
125
- upload_result = store_template(name, file, Smash.new)
126
- stack.template_url = upload_result[:url]
127
- else
128
- stack.template = parameter_scrub!(template_content(file, :scrub))
129
- end
130
-
131
133
  # Set options defined within config into stack instance for update request
132
134
  if(config[:merge_api_options])
133
135
  config.fetch(:options, Smash.new).each_pair do |key, value|
@@ -48,57 +48,67 @@ module Sfn
48
48
  def request_compile_parameter(p_name, p_config, cur_val, nested=false)
49
49
  result = nil
50
50
  attempts = 0
51
- unless(cur_val || p_config[:default].nil?)
52
- cur_val = p_config[:default]
53
- end
54
- if(cur_val.is_a?(Array))
55
- cur_val = cur_val.map(&:to_s).join(',')
56
- end
57
- until(result && (!result.respond_to?(:empty?) || !result.empty?))
58
- attempts += 1
59
- if(config[:interactive_parameters] && (!nested || !p_config.key?(:prompt_when_nested) || p_config[:prompt_when_nested] == true))
60
- result = ui.ask_question(
61
- p_name.to_s.split('_').map(&:capitalize).join,
62
- :default => cur_val.to_s.empty? ? nil : cur_val.to_s
63
- )
51
+ parameter_type = p_config.fetch(:type, 'string').to_s.downcase.to_sym
52
+ if(parameter_type == :complex)
53
+ ui.debug "Compile time parameter `#{p_name}` is a complex type. Not requesting value from user."
54
+ if(cur_val.nil?)
55
+ raise ArgumentError.new "No value provided for `#{p_name}` parameter (Complex data type)"
64
56
  else
65
- result = cur_val.to_s
57
+ cur_val
58
+ end
59
+ else
60
+ unless(cur_val || p_config[:default].nil?)
61
+ cur_val = p_config[:default]
62
+ end
63
+ if(cur_val.is_a?(Array))
64
+ cur_val = cur_val.map(&:to_s).join(',')
66
65
  end
67
- case p_config.fetch(:type, 'string').to_s.downcase.to_sym
68
- when :string
69
- if(p_config[:multiple])
70
- result = result.split(',').map(&:strip)
66
+ until(result && (!result.respond_to?(:empty?) || !result.empty?))
67
+ attempts += 1
68
+ if(config[:interactive_parameters] && (!nested || !p_config.key?(:prompt_when_nested) || p_config[:prompt_when_nested] == true))
69
+ result = ui.ask_question(
70
+ p_name.to_s.split('_').map(&:capitalize).join,
71
+ :default => cur_val.to_s.empty? ? nil : cur_val.to_s
72
+ )
73
+ else
74
+ result = cur_val.to_s
71
75
  end
72
- when :number
73
- if(p_config[:multiple])
74
- result = result.split(',').map(&:strip)
75
- new_result = result.map do |item|
76
- new_item = item.to_i
77
- new_item if new_item.to_s == item
76
+ case parameter_type
77
+ when :string
78
+ if(p_config[:multiple])
79
+ result = result.split(',').map(&:strip)
80
+ end
81
+ when :number
82
+ if(p_config[:multiple])
83
+ result = result.split(',').map(&:strip)
84
+ new_result = result.map do |item|
85
+ new_item = item.to_i
86
+ new_item if new_item.to_s == item
87
+ end
88
+ result = new_result.size == result.size ? new_result : []
89
+ else
90
+ new_result = result.to_i
91
+ result = new_result.to_s == result ? new_result : nil
78
92
  end
79
- result = new_result.size == result.size ? new_result : []
80
93
  else
81
- new_result = result.to_i
82
- result = new_result.to_s == result ? new_result : nil
94
+ raise ArgumentError.new "Unknown compile time parameter type provided: `#{p_config[:type].inspect}` (Parameter: #{p_name})"
83
95
  end
84
- else
85
- raise ArgumentError.new "Unknown compile time parameter type provided: `#{p_config[:type].inspect}` (Parameter: #{p_name})"
86
- end
87
- valid = validate_parameter(result, p_config.to_smash)
88
- unless(valid == true)
89
- result = nil
90
- valid.each do |invalid_msg|
91
- ui.error invalid_msg.last
96
+ valid = validate_parameter(result, p_config.to_smash)
97
+ unless(valid == true)
98
+ result = nil
99
+ valid.each do |invalid_msg|
100
+ ui.error invalid_msg.last
101
+ end
92
102
  end
93
- end
94
- if(result.nil? || (result.respond_to?(:empty?) && result.empty?))
95
- if(attempts > MAX_PARAMETER_ATTEMPTS)
96
- ui.fatal "Failed to receive allowed parameter! (Parameter: #{p_name})"
97
- exit 1
103
+ if(result.nil? || (result.respond_to?(:empty?) && result.empty?))
104
+ if(attempts > MAX_PARAMETER_ATTEMPTS)
105
+ ui.fatal "Failed to receive allowed parameter! (Parameter: #{p_name})"
106
+ exit 1
107
+ end
98
108
  end
99
109
  end
110
+ result
100
111
  end
101
- result
102
112
  end
103
113
 
104
114
  # @return [Array<SparkleFormation::SparklePack>]
@@ -253,7 +263,7 @@ module Sfn
253
263
  ui.debug "Initial compile parameters - #{compile_state}"
254
264
  compile_state.keys.each do |cs_key|
255
265
  unless(cs_key.to_s.start_with?("#{arguments.first}__"))
256
- named_cs_key = "#{arguments.first}__#{cs_key}"
266
+ named_cs_key = [arguments.first, cs_key].compact.join('__')
257
267
  non_named = compile_state.delete(cs_key)
258
268
  if(non_named && !compile_state.key?(named_cs_key))
259
269
  ui.debug "Setting non-named compile parameter `#{cs_key}` into `#{named_cs_key}`"
@@ -213,7 +213,7 @@ module Sfn
213
213
  end
214
214
  end
215
215
  if(p_key)
216
- parameters.merge!(p_key => output.value)
216
+ self.parameters = parameters.merge(p_key => output.value)
217
217
  end
218
218
  end
219
219
  end
@@ -169,7 +169,12 @@ module Sfn
169
169
  # @param value [Array<String,Array<String>>]
170
170
  # @return [String]
171
171
  def fn_join(value)
172
- value.last.join(value.first)
172
+ unless(value.last.is_a?(Array))
173
+ val = value.last.to_s.split(',')
174
+ else
175
+ val = value.last
176
+ end
177
+ val.join(value.first)
173
178
  end
174
179
 
175
180
  # Lookup value in mappings
@@ -1,4 +1,4 @@
1
1
  module Sfn
2
2
  # Current library version
3
- VERSION = Gem::Version.new('3.0.24')
3
+ VERSION = Gem::Version.new('3.0.26')
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sfn
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.24
4
+ version: 3.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-14 00:00:00.000000000 Z
11
+ date: 2017-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bogo-cli