kumogata2 0.1.8 → 0.1.9

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: 3bdba3107a9808d3e5146c6144f4ee7dacdcdc81
4
- data.tar.gz: a7037ac8a8eb6048e0bf50ce8478444355d304f2
3
+ metadata.gz: 2f8d233adf58c553d0835355ab7c9befc443df1d
4
+ data.tar.gz: 007dcc0ccdaa8fd9870ab0f9ee74a4fab04f577f
5
5
  SHA512:
6
- metadata.gz: 3ddac5d6010f8f6877bc509395f9fb6768235453e4dcdb71e8b239f035736a4189b0ab1451ae1b33561025cee6125390a810a2dd57824c57b72cb0ac580f9bc3
7
- data.tar.gz: 4fb38679de3528e383958a7ff7cc6b6404ec86fc68075e04d57f532b1401a1746602c35d0541aa7f5b70680de00a79aed1ad95da1f0423c5c3e642e88e29190b
6
+ metadata.gz: 536c5cc9d3b2a6ab91e4ba3bde0919b249ab7f00f4e8cd4762ba2666c62de6b104bf62d4e541950a28e370dd201ee0a599c46244bfee3aad08280c47d9171204
7
+ data.tar.gz: 3676a3513ddc0b497e9812b4f362f3934b7baa4ab504e4ae200553de73c461ccbd79d07e68da79cd4dec45f6f07a49f5112501c9dc1af9ea879bd9d6571807d3
@@ -3,8 +3,8 @@ class Kumogata2::Client
3
3
 
4
4
  def initialize(options)
5
5
  @options = options.kind_of?(Hashie::Mash) ? options : Hashie::Mash.new(options)
6
- @client = Aws::CloudFormation::Client.new
7
- @resource = Aws::CloudFormation::Resource.new(client: @client)
6
+ @client = nil
7
+ @resource = nil
8
8
  @plugin_by_ext = {}
9
9
  end
10
10
 
@@ -44,7 +44,7 @@ class Kumogata2::Client
44
44
  def delete(stack_name)
45
45
  stack_name = normalize_stack_name(stack_name)
46
46
  validate_stack_name(stack_name)
47
- @resource.stack(stack_name).stack_status
47
+ get_resource.stack(stack_name).stack_status
48
48
 
49
49
  if @options.force? or agree("Are you sure you want to delete `#{stack_name}`? ".yellow)
50
50
  delete_stack(stack_name)
@@ -148,8 +148,19 @@ class Kumogata2::Client
148
148
 
149
149
  private
150
150
 
151
+ def get_client
152
+ return @client unless @client.nil?
153
+ @client = Aws::CloudFormation::Client.new
154
+ end
155
+
156
+ def get_resource
157
+ return @resource unless @resource.nil?
158
+ get_client if @client.nil?
159
+ @resource = Aws::CloudFormation::Resource.new(client: @client)
160
+ end
161
+
151
162
  def describe_stack(stack_name)
152
- resp = @client.describe_stacks(stack_name: stack_name)
163
+ resp = get_client.describe_stacks(stack_name: stack_name)
153
164
  resp.stacks.first.to_h
154
165
  end
155
166
 
@@ -179,7 +190,7 @@ class Kumogata2::Client
179
190
  :stack_policy_url)
180
191
  )
181
192
 
182
- stack = @resource.create_stack(params)
193
+ stack = get_resource.create_stack(params)
183
194
 
184
195
  return if @options.detach?
185
196
 
@@ -202,7 +213,7 @@ class Kumogata2::Client
202
213
  end
203
214
 
204
215
  def update_stack(template, stack_name)
205
- stack = @resource.stack(stack_name)
216
+ stack = get_resource.stack(stack_name)
206
217
  stack.stack_status
207
218
 
208
219
  log(:info, "Updating stack: #{stack_name}", color: :green)
@@ -230,7 +241,7 @@ class Kumogata2::Client
230
241
  return if @options.detach?
231
242
 
232
243
  # XXX: Reacquire the stack
233
- stack = @resource.stack(stack_name)
244
+ stack = get_resource.stack(stack_name)
234
245
  completed = wait(stack, 'UPDATE_COMPLETE', event_log)
235
246
 
236
247
  unless completed
@@ -246,7 +257,7 @@ class Kumogata2::Client
246
257
  end
247
258
 
248
259
  def delete_stack(stack_name)
249
- stack = @resource.stack(stack_name)
260
+ stack = get_resource.stack(stack_name)
250
261
  stack.stack_status
251
262
 
252
263
  log(:info, "Deleting stack: #{stack_name}", color: :red)
@@ -259,7 +270,7 @@ class Kumogata2::Client
259
270
 
260
271
  begin
261
272
  # XXX: Reacquire the stack
262
- stack = @resource.stack(stack_name)
273
+ stack = get_resource.stack(stack_name)
263
274
  completed = wait(stack, 'DELETE_COMPLETE', event_log)
264
275
  rescue Aws::CloudFormation::Errors::ValidationError
265
276
  # Handle `Stack does not exist`
@@ -274,7 +285,7 @@ class Kumogata2::Client
274
285
  end
275
286
 
276
287
  def validate_template(template)
277
- @client.validate_template(template_body: template.to_json)
288
+ get_client.validate_template(template_body: template.to_json)
278
289
  log(:info, 'Template validated successfully', color: :green)
279
290
  end
280
291
 
@@ -282,7 +293,7 @@ class Kumogata2::Client
282
293
  params = {}
283
294
  params[:stack_name] = stack_name if stack_name
284
295
 
285
- @resource.stacks(params).map do |stack|
296
+ get_resource.stacks(params).map do |stack|
286
297
  {
287
298
  'StackName' => stack.name,
288
299
  'CreationTime' => stack.creation_time,
@@ -293,7 +304,7 @@ class Kumogata2::Client
293
304
  end
294
305
 
295
306
  def export_template(stack_name)
296
- stack = @resource.stack(stack_name)
307
+ stack = get_resource.stack(stack_name)
297
308
  stack.stack_status
298
309
  template = stack.client.get_template(stack_name: stack_name).template_body
299
310
  JSON.parse(template)
@@ -319,7 +330,7 @@ class Kumogata2::Client
319
330
  :resource_types)
320
331
  )
321
332
 
322
- resp = @client.create_change_set(params)
333
+ resp = get_client.create_change_set(params)
323
334
  change_set_arn = resp.id
324
335
 
325
336
  completed, change_set = wait_change_set(change_set_arn, 'CREATE_COMPLETE')
@@ -332,7 +343,7 @@ class Kumogata2::Client
332
343
 
333
344
  log(:info, "Deleting ChangeSet: #{change_set_name}", color: :red)
334
345
 
335
- @client.delete_change_set(change_set_name: change_set_arn)
346
+ get_client.delete_change_set(change_set_name: change_set_arn)
336
347
 
337
348
  begin
338
349
  completed, _ = wait_change_set(change_set_arn, 'DELETE_COMPLETE')
@@ -349,25 +360,25 @@ class Kumogata2::Client
349
360
  end
350
361
 
351
362
  def describe_events(stack_name)
352
- stack = @resource.stack(stack_name)
363
+ stack = get_resource.stack(stack_name)
353
364
  stack.stack_status
354
365
  events_for(stack)
355
366
  end
356
367
 
357
368
  def describe_outputs(stack_name)
358
- stack = @resource.stack(stack_name)
369
+ stack = get_resource.stack(stack_name)
359
370
  stack.stack_status
360
371
  outputs_for(stack)
361
372
  end
362
373
 
363
374
  def describe_resources(stack_name)
364
- stack = @resource.stack(stack_name)
375
+ stack = get_resource.stack(stack_name)
365
376
  stack.stack_status
366
377
  resource_summaries_for(stack)
367
378
  end
368
379
 
369
380
  def describe_template_summary(params)
370
- resp = @client.get_template_summary(params)
381
+ resp = get_client.get_template_summary(params)
371
382
  resp.to_h
372
383
  end
373
384
 
@@ -460,7 +471,7 @@ class Kumogata2::Client
460
471
  change_set = nil
461
472
 
462
473
  loop do
463
- change_set = @client.describe_change_set(change_set_name: change_set_name)
474
+ change_set = get_client.describe_change_set(change_set_name: change_set_name)
464
475
 
465
476
  if change_set.status !~ /(_PENDING|_IN_PROGRESS)\z/
466
477
  break
@@ -0,0 +1,16 @@
1
+ require 'yaml'
2
+ class Kumogata2::Plugin::YAML
3
+ Kumogata2::Plugin.register(:yaml, ['yaml', 'yml'], self)
4
+
5
+ def initialize(options)
6
+ @options = options
7
+ end
8
+
9
+ def parse(str)
10
+ YAML.load(str)
11
+ end
12
+
13
+ def dump(hash)
14
+ YAML.dump(hash).colorize_as(:yaml)
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Kumogata2
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
data/lib/kumogata2.rb CHANGED
@@ -19,5 +19,6 @@ require 'kumogata2/utils'
19
19
 
20
20
  require 'kumogata2/plugin'
21
21
  require 'kumogata2/plugin/json'
22
+ require 'kumogata2/plugin/yaml'
22
23
 
23
24
  require 'kumogata2/client'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumogata2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-08 00:00:00.000000000 Z
11
+ date: 2017-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -177,6 +177,7 @@ files:
177
177
  - lib/kumogata2/logger.rb
178
178
  - lib/kumogata2/plugin.rb
179
179
  - lib/kumogata2/plugin/json.rb
180
+ - lib/kumogata2/plugin/yaml.rb
180
181
  - lib/kumogata2/utils.rb
181
182
  - lib/kumogata2/version.rb
182
183
  homepage: https://github.com/winebarrel/kumogata2
@@ -199,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
200
  version: '0'
200
201
  requirements: []
201
202
  rubyforge_project:
202
- rubygems_version: 2.4.5.1
203
+ rubygems_version: 2.5.2
203
204
  signing_key:
204
205
  specification_version: 4
205
206
  summary: Kumogata2 is a tool for AWS CloudFormation.