kumogata2 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1010d8128a3e5f2c9c81ad72f7ecaea602862393
4
- data.tar.gz: cd630b4ebcee5f7a4138f083b1d939b8579fa97d
3
+ metadata.gz: fb5540a3229d5f4102d1d96eb3f126e6a84a7828
4
+ data.tar.gz: 15b8e947a3be07b0b2432be90ade1f813b2072c3
5
5
  SHA512:
6
- metadata.gz: 22aa199e0c3c7a082dd6857637662628d0f75ea0199373f73d9187ca7da1d7a3069292b0f5a77e6ee4d06267321c9120a208240853d29bc313ca99ae35114905
7
- data.tar.gz: 1c4503049e67d11cbabd6dbc8f450842698c6e47c8865206fdcf6f23740be2f49b70b642f591e695a775b6b7aaa59733d40644c3345e6dc7464f7131bd96e316
6
+ metadata.gz: 56fd1a43761ac31258d23e7dce325531c517f61a63daf17d4cd60396145d5e41fbcd650a530ddd625b7be6e6910554914ea65f5a9d129afed834aea763146262
7
+ data.tar.gz: 1eeee2ea9d80d9266b68e4aef6a5d6e7cc208291b3f05d25f5a193ff6e598feb3f653c378e4ab0d9e97fb7a28420a14fd7286e74cd35ead7626d669c88316835
data/README.md CHANGED
@@ -26,18 +26,20 @@ Or install it yourself as:
26
26
  Usage: kumogata2 <command> [args] [options]
27
27
 
28
28
  Commands:
29
- create PATH_OR_URL [STACK_NAME] Create resources as specified in the template
30
- update PATH_OR_URL STACK_NAME Update a stack as specified in the template
31
- delete STACK_NAME Delete a specified stack
32
- validate PATH_OR_URL Validate a specified template
33
- list [STACK_NAME] List summary information for stacks
34
- export STACK_NAME Export a template from a specified stack
35
- convert PATH_OR_URL Convert a template format
36
- diff PATH_OR_URL1 PATH_OR_URL2 Compare templates logically (file, http://..., stack://...)
37
- dry-run PATH_OR_URL STACK_NAME Create a change set and show it
38
- show-events STACK_NAME Show events for a specified stack
39
- show-outputs STACK_NAME Show outputs for a specified stack
40
- show-resources STACK_NAME Show resources for a specified stack
29
+ describe STACK_NAME Describe a specified stack
30
+ create PATH_OR_URL [STACK_NAME] Create resources as specified in the template
31
+ update PATH_OR_URL STACK_NAME Update a stack as specified in the template
32
+ delete STACK_NAME Delete a specified stack
33
+ validate PATH_OR_URL Validate a specified template
34
+ list [STACK_NAME] List summary information for stacks
35
+ export STACK_NAME Export a template from a specified stack
36
+ convert PATH_OR_URL Convert a template format
37
+ diff PATH_OR_URL1 PATH_OR_URL2 Compare templates logically (file, http://..., stack://...)
38
+ dry-run PATH_OR_URL STACK_NAME Create a change set and show it
39
+ show-events STACK_NAME Show events for a specified stack
40
+ show-outputs STACK_NAME Show outputs for a specified stack
41
+ show-resources STACK_NAME Show resources for a specified stack
42
+ template-summary PATH_OR_URL Show template information for a specified stack
41
43
 
42
44
  Support Format:
43
45
  json, js, template
@@ -7,6 +7,10 @@ module Kumogata2::CLI
7
7
  }
8
8
 
9
9
  COMMANDS = {
10
+ describe: {
11
+ description: 'Describe a specified stack',
12
+ arguments: [:stack_name],
13
+ },
10
14
  create: {
11
15
  description: 'Create resources as specified in the template',
12
16
  arguments: [:path_or_url, :stack_name?],
@@ -59,6 +63,10 @@ module Kumogata2::CLI
59
63
  description: 'Show resources for a specified stack',
60
64
  arguments: [:stack_name],
61
65
  },
66
+ template_summary: {
67
+ description: 'Show template information for a specified stack',
68
+ arguments: [:path_or_url],
69
+ },
62
70
  }
63
71
 
64
72
  class << self
@@ -142,8 +150,9 @@ module Kumogata2::CLI
142
150
 
143
151
  orig_command = command
144
152
  command = command.gsub('-', '_').to_sym
153
+ command = find_command(command)
145
154
 
146
- unless COMMANDS.has_key?(command)
155
+ unless command
147
156
  raise "Unknown command: #{orig_command}"
148
157
  end
149
158
 
@@ -185,6 +194,16 @@ module Kumogata2::CLI
185
194
 
186
195
  private
187
196
 
197
+ def find_command(command)
198
+ selected = COMMANDS.keys.select {|i| i =~ /\A#{command}/ }
199
+
200
+ if selected.length == 1
201
+ selected.first
202
+ else
203
+ nil
204
+ end
205
+ end
206
+
188
207
  def exit_parse!(exit_code)
189
208
  exit(exit_code)
190
209
  end
@@ -8,7 +8,15 @@ class Kumogata2::Client
8
8
  @plugin_by_ext = {}
9
9
  end
10
10
 
11
+ def describe(stack_name)
12
+ stack_name = normalize_stack_name(stack_name)
13
+ validate_stack_name(stack_name)
14
+ stack = describe_stack(stack_name)
15
+ JSON.pretty_generate(stack).colorize_as(:json)
16
+ end
17
+
11
18
  def create(path_or_url, stack_name = nil)
19
+ stack_name = normalize_stack_name(stack_name)
12
20
  validate_stack_name(stack_name) if stack_name
13
21
  template = open_template(path_or_url)
14
22
  update_deletion_policy(template, delete_stack: !stack_name)
@@ -21,6 +29,7 @@ class Kumogata2::Client
21
29
  end
22
30
 
23
31
  def update(path_or_url, stack_name)
32
+ stack_name = normalize_stack_name(stack_name)
24
33
  validate_stack_name(stack_name)
25
34
  template = open_template(path_or_url)
26
35
  update_deletion_policy(template, update_metadate: true)
@@ -33,6 +42,7 @@ class Kumogata2::Client
33
42
  end
34
43
 
35
44
  def delete(stack_name)
45
+ stack_name = normalize_stack_name(stack_name)
36
46
  validate_stack_name(stack_name)
37
47
  @resource.stack(stack_name).stack_status
38
48
 
@@ -47,12 +57,14 @@ class Kumogata2::Client
47
57
  end
48
58
 
49
59
  def list(stack_name = nil)
60
+ stack_name = normalize_stack_name(stack_name)
50
61
  validate_stack_name(stack_name) if stack_name
51
62
  stacks = describe_stacks(stack_name)
52
63
  JSON.pretty_generate(stacks).colorize_as(:json)
53
64
  end
54
65
 
55
66
  def export(stack_name)
67
+ stack_name = normalize_stack_name(stack_name)
56
68
  validate_stack_name(stack_name)
57
69
  template = export_template(stack_name)
58
70
  convert0(template)
@@ -87,6 +99,7 @@ class Kumogata2::Client
87
99
  end
88
100
 
89
101
  def dry_run(path_or_url, stack_name = nil)
102
+ stack_name = normalize_stack_name(stack_name)
90
103
  validate_stack_name(stack_name) if stack_name
91
104
  template = open_template(path_or_url)
92
105
  update_deletion_policy(template, delete_stack: !stack_name)
@@ -96,25 +109,49 @@ class Kumogata2::Client
96
109
  end
97
110
 
98
111
  def show_events(stack_name)
112
+ stack_name = normalize_stack_name(stack_name)
99
113
  validate_stack_name(stack_name)
100
114
  events = describe_events(stack_name)
101
115
  JSON.pretty_generate(events).colorize_as(:json)
102
116
  end
103
117
 
104
118
  def show_outputs(stack_name)
119
+ stack_name = normalize_stack_name(stack_name)
105
120
  validate_stack_name(stack_name)
106
121
  outputs = describe_outputs(stack_name)
107
122
  JSON.pretty_generate(outputs).colorize_as(:json)
108
123
  end
109
124
 
110
125
  def show_resources(stack_name)
126
+ stack_name = normalize_stack_name(stack_name)
111
127
  validate_stack_name(stack_name)
112
128
  resources = describe_resources(stack_name)
113
129
  JSON.pretty_generate(resources).colorize_as(:json)
114
130
  end
115
131
 
132
+ def template_summary(path_or_url)
133
+ params = {}
134
+
135
+ if path_or_url =~ %r|\Astack://(.*)|
136
+ stack_name = $1 || ''
137
+ validate_stack_name(stack_name)
138
+ params[:stack_name] = stack_name
139
+ else
140
+ template = open_template(path_or_url)
141
+ params[:template_body] = JSON.pretty_generate(template)
142
+ end
143
+
144
+ summary = describe_template_summary(params)
145
+ JSON.pretty_generate(summary).colorize_as(:json)
146
+ end
147
+
116
148
  private
117
149
 
150
+ def describe_stack(stack_name)
151
+ resp = @client.describe_stacks(stack_name: stack_name)
152
+ resp.stacks.first.to_h
153
+ end
154
+
118
155
  def create_stack(template, stack_name)
119
156
  stack_will_be_deleted = !stack_name
120
157
 
@@ -325,6 +362,11 @@ class Kumogata2::Client
325
362
  resource_summaries_for(stack)
326
363
  end
327
364
 
365
+ def describe_template_summary(params)
366
+ resp = @client.get_template_summary(params)
367
+ resp.to_h
368
+ end
369
+
328
370
  def convert0(template)
329
371
  ext = @options.output_format || 'template'
330
372
  plugin = find_or_create_plugin('xxx.' + ext)
@@ -584,4 +626,12 @@ EOS
584
626
  stack_name = stack_name.join('-')
585
627
  stack_name.gsub(/[^-a-zA-Z0-9]+/, '-').gsub(/-+/, '-')
586
628
  end
629
+
630
+ def normalize_stack_name(stack_name)
631
+ if %r|\Astack://| =~ stack_name
632
+ stack_name.sub(%r|\Astack://|, '')
633
+ else
634
+ stack_name
635
+ end
636
+ end
587
637
  end
@@ -1,3 +1,3 @@
1
1
  module Kumogata2
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumogata2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara