bora 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bora/cfn/stack.rb +4 -30
- data/lib/bora/stack.rb +74 -34
- data/lib/bora/tasks.rb +4 -1
- data/lib/bora/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: a0e4a8a4f46e58395bd724d7b5b43e47682aa4ad
|
4
|
+
data.tar.gz: 9f457db9cd67e8b64d6c23d2424491f69cd8977f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 000fe250f567e4e7e9ad734fdab2f3c8d0783e0d688492163690849cb60c1111e9932267393edce64c7bf856ec7bf1b4b03e925eb4cd9559f6280f0ff6b0dea2
|
7
|
+
data.tar.gz: db0d0bde5699eff9255cf38e98419ca46805b0d57f84505e6568ef42568f7294f82238fd66a28f52109559a8248a946de025ad33b84928ccb08aa454268ea5e6
|
data/lib/bora/cfn/stack.rb
CHANGED
@@ -55,26 +55,13 @@ class Bora
|
|
55
55
|
underlying_stack.parameters.map { |parameter| Parameter.new(parameter) }
|
56
56
|
end
|
57
57
|
|
58
|
-
def template
|
58
|
+
def template
|
59
59
|
return if !exists?
|
60
|
-
|
61
|
-
template = JSON.pretty_generate(JSON.parse(template)) if pretty
|
62
|
-
template
|
63
|
-
end
|
64
|
-
|
65
|
-
def new_template(options, pretty = true)
|
66
|
-
options = resolve_options(options, true)
|
67
|
-
template = options[:template_body]
|
68
|
-
if template
|
69
|
-
template = JSON.pretty_generate(JSON.parse(template)) if pretty
|
70
|
-
template
|
71
|
-
else
|
72
|
-
raise "new_template not yet implemented for URL #{options[:template_url]}"
|
73
|
-
end
|
60
|
+
cloudformation.get_template({stack_name: @stack_name}).template_body
|
74
61
|
end
|
75
62
|
|
76
63
|
def validate(options)
|
77
|
-
cloudformation.validate_template(
|
64
|
+
cloudformation.validate_template(options.select { |k| [:template_body, :template_url].include?(k) })
|
78
65
|
end
|
79
66
|
|
80
67
|
def status
|
@@ -104,7 +91,7 @@ class Bora
|
|
104
91
|
return true if action == :delete && !exists?
|
105
92
|
@previous_event_time = last_event_time
|
106
93
|
begin
|
107
|
-
action_options = {stack_name: @stack_name}.merge(
|
94
|
+
action_options = {stack_name: @stack_name}.merge(options)
|
108
95
|
cloudformation.method("#{action.to_s.downcase}_stack").call(action_options)
|
109
96
|
wait_for_completion(&block)
|
110
97
|
rescue Aws::CloudFormation::Errors::ValidationError => e
|
@@ -114,19 +101,6 @@ class Bora
|
|
114
101
|
(action == :delete && !underlying_stack) || status.success?
|
115
102
|
end
|
116
103
|
|
117
|
-
def resolve_options(options, load_all = false)
|
118
|
-
return options if options[:template_body] || !options[:template_url]
|
119
|
-
uri = URI(options[:template_url])
|
120
|
-
if uri.scheme != "s3" || load_all
|
121
|
-
resolved_options = options.clone
|
122
|
-
resolved_options[:template_body] = open(options[:template_url]).read
|
123
|
-
resolved_options.delete(:template_url)
|
124
|
-
resolved_options
|
125
|
-
else
|
126
|
-
options
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
104
|
def wait_for_completion
|
131
105
|
begin
|
132
106
|
events = unprocessed_events
|
data/lib/bora/stack.rb
CHANGED
@@ -29,7 +29,6 @@ class Bora
|
|
29
29
|
@template_file = template_file
|
30
30
|
@stack_config = stack_config
|
31
31
|
@region = @stack_config['default_region'] || Aws::CloudFormation::Client.new.config[:region]
|
32
|
-
@cfn_options = extract_cfn_options(stack_config)
|
33
32
|
@cfn_stack = Cfn::Stack.new(@cfn_stack_name, @region)
|
34
33
|
@resolver = ParameterResolver.new(self)
|
35
34
|
end
|
@@ -41,8 +40,8 @@ class Bora
|
|
41
40
|
end
|
42
41
|
|
43
42
|
def apply(override_params = {}, pretty_json = false)
|
44
|
-
generate(override_params, pretty_json)
|
45
|
-
success = invoke_action(@cfn_stack.exists? ? "update" : "create",
|
43
|
+
cfn_options = generate(override_params, pretty_json)
|
44
|
+
success = invoke_action(@cfn_stack.exists? ? "update" : "create", cfn_options)
|
46
45
|
if success
|
47
46
|
outputs = @cfn_stack.outputs
|
48
47
|
if outputs && outputs.length > 0
|
@@ -58,9 +57,9 @@ class Bora
|
|
58
57
|
end
|
59
58
|
|
60
59
|
def diff(override_params = {}, context_lines = 3)
|
61
|
-
generate(override_params)
|
62
|
-
diff_parameters
|
63
|
-
diff_template(override_params, context_lines)
|
60
|
+
cfn_options = generate(override_params)
|
61
|
+
diff_parameters(cfn_options)
|
62
|
+
diff_template(override_params, context_lines, cfn_options)
|
64
63
|
end
|
65
64
|
|
66
65
|
def events
|
@@ -109,17 +108,17 @@ class Bora
|
|
109
108
|
end
|
110
109
|
|
111
110
|
def recreate(override_params = {})
|
112
|
-
generate(override_params)
|
113
|
-
invoke_action("recreate",
|
111
|
+
cfn_options = generate(override_params)
|
112
|
+
invoke_action("recreate", cfn_options)
|
114
113
|
end
|
115
114
|
|
116
115
|
def show(override_params = {})
|
117
|
-
generate(override_params)
|
118
|
-
puts
|
116
|
+
cfn_options = generate(override_params)
|
117
|
+
puts get_new_template(cfn_options)
|
119
118
|
end
|
120
119
|
|
121
120
|
def show_current
|
122
|
-
template =
|
121
|
+
template = get_current_template
|
123
122
|
puts template ? template : (STACK_DOES_NOT_EXIST_MESSAGE % @cfn_stack_name)
|
124
123
|
end
|
125
124
|
|
@@ -128,8 +127,8 @@ class Bora
|
|
128
127
|
end
|
129
128
|
|
130
129
|
def validate(override_params = {})
|
131
|
-
generate(override_params)
|
132
|
-
is_valid = @cfn_stack.validate(
|
130
|
+
cfn_options = generate(override_params)
|
131
|
+
is_valid = @cfn_stack.validate(cfn_options)
|
133
132
|
puts STACK_VALIDATE_SUCCESS_MESSAGE % @cfn_stack_name if is_valid
|
134
133
|
is_valid
|
135
134
|
end
|
@@ -143,29 +142,58 @@ class Bora
|
|
143
142
|
|
144
143
|
protected
|
145
144
|
|
146
|
-
def diff_parameters
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
new_params = @cfn_options[:parameters].sort { |a, b|
|
152
|
-
a[:parameter_key] <=> b[:parameter_key]
|
153
|
-
}.map { |p|
|
154
|
-
"#{p[:parameter_key] } - #{p[:parameter_value]}"
|
155
|
-
}.join("\n") + "\n"
|
156
|
-
end
|
145
|
+
def diff_parameters(cfn_options)
|
146
|
+
current_params = current_cfn_parameters
|
147
|
+
new_params = new_bora_parameters(cfn_options)
|
148
|
+
default_params = template_default_parameters(cfn_options)
|
149
|
+
new_params = default_params.merge(new_params || {}) if default_params
|
157
150
|
|
158
|
-
|
151
|
+
current_params_str = params_as_string(current_params)
|
152
|
+
new_params_str = params_as_string(new_params)
|
153
|
+
if current_params_str || new_params_str
|
159
154
|
puts "Parameters".colorize(mode: :bold)
|
160
155
|
puts "----------"
|
161
|
-
diff = Diffy::Diff.new(
|
156
|
+
diff = Diffy::Diff.new(current_params_str, new_params_str).to_s(String.disable_colorization ? :text : :color).chomp
|
162
157
|
puts diff && !diff.empty? ? diff : STACK_DIFF_PARAMETERS_UNCHANGED_MESSAGE
|
163
158
|
puts
|
164
159
|
end
|
165
160
|
end
|
166
161
|
|
167
|
-
def
|
168
|
-
|
162
|
+
def params_as_string(params)
|
163
|
+
params ? params.sort.map {|k, v| "#{k} - #{v}" }.join("\n") + "\n" : nil
|
164
|
+
end
|
165
|
+
|
166
|
+
def template_default_parameters(cfn_options)
|
167
|
+
params = nil
|
168
|
+
template = JSON.parse(cfn_options[:template_body])
|
169
|
+
if template["Parameters"]
|
170
|
+
params_with_defaults = template["Parameters"].select { |_, v| v["Default"] }
|
171
|
+
if !params_with_defaults.empty?
|
172
|
+
params = params_with_defaults.map { |k, v| [k, v["Default"]] }.to_h
|
173
|
+
end
|
174
|
+
end
|
175
|
+
params
|
176
|
+
end
|
177
|
+
|
178
|
+
def current_cfn_parameters
|
179
|
+
params = nil
|
180
|
+
if @cfn_stack.parameters && !@cfn_stack.parameters.empty?
|
181
|
+
params = @cfn_stack.parameters.map { |p| [p.key, p.value] }.to_h
|
182
|
+
end
|
183
|
+
params
|
184
|
+
end
|
185
|
+
|
186
|
+
def new_bora_parameters(cfn_options)
|
187
|
+
params = nil
|
188
|
+
cfn_parameters = cfn_options[:parameters]
|
189
|
+
if cfn_parameters && !cfn_parameters.empty?
|
190
|
+
params = cfn_parameters.map { |p| [p[:parameter_key], p[:parameter_value]] }.to_h
|
191
|
+
end
|
192
|
+
params
|
193
|
+
end
|
194
|
+
|
195
|
+
def diff_template(override_params, context_lines, cfn_options)
|
196
|
+
diff = Diffy::Diff.new(get_current_template, get_new_template(cfn_options),
|
169
197
|
context: context_lines,
|
170
198
|
include_diff_info: true)
|
171
199
|
diff = diff.reject { |line| line =~ /^(---|\+\+\+|\\\\)/ }
|
@@ -190,6 +218,7 @@ class Bora
|
|
190
218
|
end
|
191
219
|
|
192
220
|
def generate(override_params = {}, pretty_json = false)
|
221
|
+
cfn_options = cfn_options_from_stack_config
|
193
222
|
params = resolved_params(override_params)
|
194
223
|
if File.extname(@template_file) == ".rb"
|
195
224
|
template_body = run_cfndsl(@template_file, params, pretty_json)
|
@@ -199,17 +228,18 @@ class Bora
|
|
199
228
|
cfn_params = params.select { |k, v| cfn_param_keys.include?(k) }.map do |k, v|
|
200
229
|
{ parameter_key: k, parameter_value: v }
|
201
230
|
end
|
202
|
-
|
231
|
+
cfn_options[:parameters] = cfn_params if !cfn_params.empty?
|
203
232
|
end
|
204
|
-
|
233
|
+
cfn_options[:template_body] = template_body
|
205
234
|
else
|
206
|
-
|
235
|
+
cfn_options[:template_body] = File.read(@template_file)
|
207
236
|
if !params.empty?
|
208
|
-
|
237
|
+
cfn_options[:parameters] = params.map do |k, v|
|
209
238
|
{ parameter_key: k, parameter_value: v }
|
210
239
|
end
|
211
240
|
end
|
212
241
|
end
|
242
|
+
cfn_options
|
213
243
|
end
|
214
244
|
|
215
245
|
def invoke_action(action, *args)
|
@@ -237,9 +267,19 @@ class Bora
|
|
237
267
|
template_body
|
238
268
|
end
|
239
269
|
|
240
|
-
def
|
270
|
+
def cfn_options_from_stack_config
|
241
271
|
valid_options = ["capabilities"]
|
242
|
-
|
272
|
+
@stack_config.select { |k| valid_options.include?(k) }
|
273
|
+
end
|
274
|
+
|
275
|
+
def get_new_template(cfn_options)
|
276
|
+
template = cfn_options[:template_body]
|
277
|
+
JSON.pretty_generate(JSON.parse(template))
|
278
|
+
end
|
279
|
+
|
280
|
+
def get_current_template
|
281
|
+
template = @cfn_stack.template
|
282
|
+
template ? JSON.pretty_generate(JSON.parse(template)) : nil
|
243
283
|
end
|
244
284
|
|
245
285
|
end
|
data/lib/bora/tasks.rb
CHANGED
@@ -20,8 +20,11 @@ class Bora
|
|
20
20
|
if @stack_options[:template_body] || @stack_options[:template_url]
|
21
21
|
raise "You cannot specify a template in the constructor as well as in the stack_options"
|
22
22
|
else
|
23
|
-
@stack_options[:
|
23
|
+
@stack_options[:template_body] = File.read(template_uri)
|
24
24
|
end
|
25
|
+
elsif @stack_options[:template_url]
|
26
|
+
@stack_options[:template_body] = File.read(@stack_options[:template_url])
|
27
|
+
@stack_options.delete(:template_url)
|
25
28
|
end
|
26
29
|
|
27
30
|
define_tasks
|
data/lib/bora/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charles Blaxland
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|