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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/sfn/command_module/stack.rb +113 -61
- data/lib/sfn/command_module/template.rb +1 -1
- data/lib/sfn/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dbf7d97959e1120a0d7b1194371c15b7a483ebd
|
4
|
+
data.tar.gz: beaddca76c30c1d453449939de41693a6ec84554
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab20f19b50ed8db52d845c51a2194720b875627225d2a44574124b8a06e5a87ebc55382520e4368e068776703d3649738f99e6bfc41b0f074735a5eb33152496
|
7
|
+
data.tar.gz: 5bce247327ec8b0cbd793c3b28a9b4a994dda012f9f5fb0031e48e17a1306826ff8678c90a7255ffada556c9d35af4677ce577c7fa9b3679b3fd08fff0ea529a
|
data/CHANGELOG.md
CHANGED
@@ -99,16 +99,12 @@ module Sfn
|
|
99
99
|
true
|
100
100
|
end
|
101
101
|
|
102
|
-
#
|
102
|
+
# Generate name prefix for config parameter based on location and
|
103
|
+
# extract template parameters
|
103
104
|
#
|
104
|
-
# @param sparkle [SparkleFormation, Hash]
|
105
|
-
# @
|
106
|
-
|
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
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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
|
-
|
131
|
-
|
132
|
-
|
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
|
-
|
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 |
|
139
|
-
|
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[
|
226
|
+
if(function_set_parameter?(current_parameters[param_name]))
|
145
227
|
if(current_stack)
|
146
|
-
enable_set = validate_stack_parameter(current_stack,
|
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][
|
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,
|
242
|
+
use_expected = validate_stack_parameter(current_stack, param_name, ns_key, current_parameters[param_name])
|
159
243
|
unless(use_expected)
|
160
|
-
current_parameters[
|
244
|
+
current_parameters[param_name] = current_stack.parameters[param_name]
|
161
245
|
end
|
162
246
|
end
|
163
247
|
end
|
164
|
-
|
165
|
-
|
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
|
data/lib/sfn/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2016-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bogo-cli
|