sfn 3.0.8 → 3.0.10

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: 0dc69ba2982a6dd188d39c830c050bdc877942a3
4
- data.tar.gz: 2a835394a2fafaf917c5353f2e8c7a167af54f6e
3
+ metadata.gz: 1dbf7d97959e1120a0d7b1194371c15b7a483ebd
4
+ data.tar.gz: beaddca76c30c1d453449939de41693a6ec84554
5
5
  SHA512:
6
- metadata.gz: 63ce93e5bb1786bf4bb8d5bfd54a639df2abf612a64af60396be84a4df318a00099a98445eb5d92237335c9c00dbfdee8e43a33549e3b0b37f122daaa05ab3cb
7
- data.tar.gz: abb69c136be4c74c3bcb51de4d8b4d0496ceb05faed8933d79b244ec4b2a48c82c97fbb44bb10ce32b6358e08795568016a0a7fd19a809ca7f09bc2008719f49
6
+ metadata.gz: ab20f19b50ed8db52d845c51a2194720b875627225d2a44574124b8a06e5a87ebc55382520e4368e068776703d3649738f99e6bfc41b0f074735a5eb33152496
7
+ data.tar.gz: 5bce247327ec8b0cbd793c3b28a9b4a994dda012f9f5fb0031e48e17a1306826ff8678c90a7255ffada556c9d35af4677ce577c7fa9b3679b3fd08fff0ea529a
@@ -1,3 +1,7 @@
1
+ # v3.0.10
2
+ * [fix] Template prompting within collections (#204)
3
+ * [enhancement] Stack parameter matching via configuration (#203)
4
+
1
5
  # v3.0.8
2
6
  * [fix] Apply stack name construction (#200)
3
7
 
@@ -99,16 +99,12 @@ module Sfn
99
99
  true
100
100
  end
101
101
 
102
- # Prompt for parameter values and store result
102
+ # Generate name prefix for config parameter based on location and
103
+ # extract template parameters
103
104
  #
104
- # @param sparkle [SparkleFormation, Hash]
105
- # @param opts [Hash]
106
- # @option opts [Hash] :current_parameters current stack parameter values
107
- # @option opts [Miasma::Models::Orchestration::Stack] :stack existing stack
108
- # @return [Hash]
109
- def populate_parameters!(sparkle, opts={})
110
- current_parameters = opts.fetch(:current_parameters, {})
111
- current_stack = opts[:stack]
105
+ # @param sparkle [SparkleFormation, Hash] template instance
106
+ # @return [Array<Array<String>, Smash>] prefix value, parameters
107
+ def prefix_parameters_setup(sparkle)
112
108
  if(sparkle.is_a?(SparkleFormation))
113
109
  parameter_prefix = sparkle.root? ? [] : (sparkle.root_path - [sparkle.root]).map do |s|
114
110
  Bogo::Utility.camel(s.name)
@@ -121,80 +117,136 @@ module Sfn
121
117
  sparkle[loc_key]
122
118
  end.compact.first || Smash.new
123
119
  end
124
- unless(stack_parameters.empty?)
125
- if(config.get(:parameter).is_a?(Array))
126
- config[:parameter] = Smash[
127
- *config.get(:parameter).map(&:to_a).flatten
128
- ]
120
+ [parameter_prefix, stack_parameters]
121
+ end
122
+
123
+ # Format config defined parameters to ensure expected layout
124
+ def format_config_parameters!
125
+ if(config.get(:parameter).is_a?(Array))
126
+ config[:parameter] = Smash[
127
+ *config.get(:parameter).map(&:to_a).flatten
128
+ ]
129
+ end
130
+ if(config.get(:parameters))
131
+ config.set(:parameters,
132
+ config.get(:parameters).merge(config.fetch(:parameter, Smash.new))
133
+ )
134
+ else
135
+ config.set(:parameters, config.fetch(:parameter, Smash.new))
136
+ end
137
+ end
138
+
139
+ # Determine correct configuration parameter key
140
+ #
141
+ # @param parameter_prefix [Array<String>] nesting prefix names
142
+ # @param parameter_name [String] parameter name
143
+ # @return [Array<String>] [expected_template_key, configuration_used_key]
144
+ def locate_config_parameter_key(parameter_prefix, parameter_name)
145
+ check_name = parameter_name.downcase.tr('-_', '')
146
+ check_prefix = parameter_prefix.map{|i| i.downcase.tr('-_', '') }
147
+ key_match = config[:parameters].keys.detect do |cp_key|
148
+ cp_key = cp_key.to_s.downcase.split('__').map{|i| i.tr('-_', '') }.join('__')
149
+ cp_key.start_with?(check_prefix.join('__')) &&
150
+ cp_key.split('__').last == check_name
151
+ end
152
+ actual_key = (parameter_prefix + [parameter_name]).compact.join('__')
153
+ if(key_match)
154
+ config[:parameters][actual_key] = config[:parameters].delete(key_match)
155
+ end
156
+ actual_key
157
+ end
158
+
159
+ # Populate stack parameter value via user interaction
160
+ #
161
+ # @param sparkle [SparkleFormation, Hash] template
162
+ # @param ns_key [String] configuration parameter key name
163
+ # @param param_name [String] template parameter name
164
+ # @param param_value [Hash] template parameter value
165
+ # @param current_parameters [Hash] currently set stack parameters
166
+ # @param param_banner [TrueClass, FalseClass] parameter banner has been printed
167
+ # @return [TrueClass, FalseClass] parameter banner has been printed
168
+ def set_parameter(sparkle, ns_key, param_name, param_value, current_parameters, param_banner)
169
+ valid = false
170
+ attempt = 0
171
+ if(!valid && !param_banner)
172
+ if(sparkle.is_a?(SparkleFormation))
173
+ ui.info "#{ui.color('Stack runtime parameters:', :bold)} - template: #{ui.color(sparkle.root_path.map(&:name).map(&:to_s).join(' > '), :green, :bold)}"
174
+ else
175
+ ui.info ui.color('Stack runtime parameters:', :bold)
129
176
  end
130
- if(config.get(:parameters))
131
- config.set(:parameters,
132
- config.get(:parameters).merge(config.fetch(:parameter, Smash.new))
177
+ param_banner = true
178
+ end
179
+ until(valid)
180
+ attempt += 1
181
+ default = config[:parameters].fetch(
182
+ ns_key, current_parameters.fetch(
183
+ param_name, TEMPLATE_PARAMETER_DEFAULTS.map{|loc_key| param_value[loc_key]}.compact.first
133
184
  )
185
+ )
186
+ if(config[:interactive_parameters])
187
+ answer = ui.ask_question("#{param_name.split(/([A-Z]+[^A-Z]*)/).find_all{|s|!s.empty?}.join(' ')}", :default => default)
188
+ else
189
+ answer = default
190
+ end
191
+ validation = validate_parameter(answer, param_value)
192
+ if(validation == true)
193
+ config[:parameters][ns_key] = answer
194
+ valid = true
134
195
  else
135
- config.set(:parameters, config.fetch(:parameter, Smash.new))
196
+ validation.each do |validation_error|
197
+ ui.error validation_error.last
198
+ end
136
199
  end
200
+ if(attempt > MAX_PARAMETER_ATTEMPTS)
201
+ ui.fatal 'Failed to receive allowed parameter!'
202
+ exit 1
203
+ end
204
+ end
205
+ param_banner
206
+ end
207
+
208
+ # Prompt for parameter values and store result
209
+ #
210
+ # @param sparkle [SparkleFormation, Hash]
211
+ # @param opts [Hash]
212
+ # @option opts [Hash] :current_parameters current stack parameter values
213
+ # @option opts [Miasma::Models::Orchestration::Stack] :stack existing stack
214
+ # @return [Hash]
215
+ def populate_parameters!(sparkle, opts={})
216
+ current_parameters = opts.fetch(:current_parameters, {})
217
+ current_stack = opts[:stack]
218
+ parameter_prefix, stack_parameters = prefix_parameters_setup(sparkle)
219
+ unless(stack_parameters.empty?)
220
+ format_config_parameters!
137
221
  param_banner = false
138
- stack_parameters.each do |k,v|
139
- ns_k = (parameter_prefix + [k]).compact.join('__')
140
- next if config[:parameters][ns_k]
141
- valid = false
222
+ stack_parameters.each do |param_name, param_value|
223
+ ns_key = locate_config_parameter_key(parameter_prefix, param_name)
142
224
  # When parameter is a hash type, it is being set via
143
225
  # intrinsic function and we don't modify
144
- if(function_set_parameter?(current_parameters[k]))
226
+ if(function_set_parameter?(current_parameters[param_name]))
145
227
  if(current_stack)
146
- enable_set = validate_stack_parameter(current_stack, k, ns_k, current_parameters[k])
228
+ enable_set = validate_stack_parameter(current_stack, param_name, ns_key, current_parameters[param_name])
147
229
  else
148
230
  enable_set = true
149
231
  end
150
232
  if(enable_set)
151
233
  # NOTE: direct set dumps the stack (nfi). Smash will
152
234
  # auto dup it, and works, so yay i guess.
153
- config[:parameters][ns_k] = current_parameters[k].is_a?(Hash) ? Smash.new(current_parameters[k]) : current_parameters[k].dup
235
+ config[:parameters][ns_key] = current_parameters[param_name].is_a?(Hash) ?
236
+ Smash.new(current_parameters[param_name]) :
237
+ current_parameters[param_name].dup
154
238
  valid = true
155
239
  end
156
240
  else
157
241
  if(current_stack && current_stack.data[:parent_stack])
158
- use_expected = validate_stack_parameter(current_stack, k, ns_k, current_parameters[k])
242
+ use_expected = validate_stack_parameter(current_stack, param_name, ns_key, current_parameters[param_name])
159
243
  unless(use_expected)
160
- current_parameters[k] = current_stack.parameters[k]
244
+ current_parameters[param_name] = current_stack.parameters[param_name]
161
245
  end
162
246
  end
163
247
  end
164
- attempt = 0
165
- if(!valid && !param_banner)
166
- if(sparkle.is_a?(SparkleFormation))
167
- ui.info "#{ui.color('Stack runtime parameters:', :bold)} - template: #{ui.color(sparkle.root_path.map(&:name).map(&:to_s).join(' > '), :green, :bold)}"
168
- else
169
- ui.info ui.color('Stack runtime parameters:', :bold)
170
- end
171
- param_banner = true
172
- end
173
- until(valid)
174
- attempt += 1
175
- default = config[:parameters].fetch(
176
- ns_k, current_parameters.fetch(
177
- k, TEMPLATE_PARAMETER_DEFAULTS.map{|loc_key| v[loc_key]}.compact.first
178
- )
179
- )
180
- if(config[:interactive_parameters])
181
- answer = ui.ask_question("#{k.split(/([A-Z]+[^A-Z]*)/).find_all{|s|!s.empty?}.join(' ')}", :default => default)
182
- else
183
- answer = default
184
- end
185
- validation = validate_parameter(answer, v)
186
- if(validation == true)
187
- config[:parameters][ns_k] = answer
188
- valid = true
189
- else
190
- validation.each do |validation_error|
191
- ui.error validation_error.last
192
- end
193
- end
194
- if(attempt > MAX_PARAMETER_ATTEMPTS)
195
- ui.fatal 'Failed to receive allowed parameter!'
196
- exit 1
197
- end
248
+ unless(valid)
249
+ param_banner = set_parameter(sparkle, ns_key, param_name, param_value, current_parameters, param_banner)
198
250
  end
199
251
  end
200
252
  end
@@ -490,7 +490,7 @@ module Sfn
490
490
  c_name.split('_').map(&:capitalize).join(' ')
491
491
  end.join(' / ')
492
492
  ui.info "Viewing collection: #{ui.color(collection_name, :bold)}"
493
- template_names = sparkle_collection.templates.keys.find_all do |t_name|
493
+ template_names = sparkle_collection.templates.fetch(provider.connection.provider, {}).keys.find_all do |t_name|
494
494
  t_name.to_s.start_with?(prefix.to_s)
495
495
  end
496
496
  else
@@ -1,4 +1,4 @@
1
1
  module Sfn
2
2
  # Current library version
3
- VERSION = Gem::Version.new('3.0.8')
3
+ VERSION = Gem::Version.new('3.0.10')
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.8
4
+ version: 3.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-17 00:00:00.000000000 Z
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bogo-cli