bbc-cosmos-tools 0.1.6 → 0.2.0

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: 47e4b3dcf0f4d6bc40f26a4b24c2ce5d5a055c7f
4
- data.tar.gz: 0e8120e3e97d6ca61f8f2c865b9e78f822d94dd2
3
+ metadata.gz: 3dc8be1f2f3a4a303adfe5231c6c48fa611d7fe0
4
+ data.tar.gz: 6914445689b9353b34e90c419d6dd251f4f9e26f
5
5
  SHA512:
6
- metadata.gz: 9c4ca410decc169970a7c008c6a48234699ec881dee0dda1afc89b334a42b4b312ae45a74f9e8b8915c51f074aa7c14a305ed848bf69a70fd987bc998e829b81
7
- data.tar.gz: 5e7e5ed78aa554dc6f82db54978b59ddeb75f940b275a95e40bffc466cf4c773b3b4e50acf3c5d995f89cec845af4aefd9619735fdaf302e8c38f4e2d440ab31
6
+ metadata.gz: 4f86f3cdcc8fc06c485f4f6376d29c9ab786f453a5f332e828b16b904404a25d7508b221d50cec41400d7c32b3bb44351c2ab27f0490dd4367cb931f3eff253f
7
+ data.tar.gz: 68864cabba5957372a7ad1e5b526c5618ede9462455e1cd33cd7fcb218cb81ef1834c95aed8165a5876ca17893c439978b087de62c4b257d41499af279c8b40e
@@ -41,9 +41,9 @@ module BBC
41
41
  components = component.nil? ? config.components_for(options[:tags]).keys : [component]
42
42
  end
43
43
 
44
- def api_error(response)
44
+ def api_error(response, die = true)
45
45
  error_message = JSON.parse(response.body)['message']
46
- error(error_message)
46
+ error(error_message, die)
47
47
  end
48
48
 
49
49
  def build_table(headers, data)
@@ -16,34 +16,39 @@ module BBC
16
16
  @api = BBC::Cosmos::Tools::API.new(config.app['api'], options[:key_path])
17
17
  end
18
18
 
19
- desc "stack list [COMPONENT]", "Lists stacks for a component"
20
- def list(component)
19
+ desc "stack list [COMPONENT = nil]", "Lists stacks for a component"
20
+ method_option :tags, :type => :array, :default => nil, :desc => "The tags of the components you want to deploy (i.e 'renderer')"
21
+ def list(component = nil)
21
22
 
22
23
  say "#{banner}\n"
23
- response = api.get sprintf(config.app['stacks'], options[:env], component)
24
24
 
25
- if response.success?
25
+ components(options, component).each do |id|
26
26
 
27
- data = JSON.parse(response.body).map do |stack|
28
- [
29
- stack['name'],
30
- stack['main_stack'],
31
- stack['updated_at'],
32
- stack['status']
33
- ]
34
- end
27
+ response = api.get sprintf(config.app['stacks'], options[:env], id)
28
+ say get_key_value("\nComponent", id)
29
+
30
+ if response.success?
35
31
 
36
- print_table(
37
- build_table(
38
- ['Name', 'Main stack', 'Updated at', 'Status'],
39
- data
32
+ data = JSON.parse(response.body).map do |stack|
33
+ [
34
+ stack['name'].split('-').last,
35
+ stack['main_stack'],
36
+ stack['updated_at'],
37
+ stack['status']
38
+ ]
39
+ end
40
+
41
+ print_table(
42
+ build_table(
43
+ ['Name', 'Main stack', 'Updated at', 'Status'],
44
+ data
45
+ )
40
46
  )
41
- )
42
47
 
43
- else
44
- api_error response
48
+ else
49
+ api_error(response, false)
50
+ end
45
51
  end
46
-
47
52
  end
48
53
 
49
54
  method_option :variant, :type => :string, :default => 'default', :desc => "The variant to use, i.e default|scheduled"
@@ -58,55 +63,63 @@ module BBC
58
63
 
59
64
  method_option :variant, :type => :string, :default => 'default', :desc => "The variant to use, i.e default|scheduled"
60
65
  method_option :group, :type => :string, :default => nil, :desc => "The group name to override the component id"
66
+ method_option :tags, :type => :array, :default => nil, :desc => "The tags of the components you want to deploy (i.e 'renderer')"
61
67
  desc "stack create [COMPONENT, MAIN_STACK = false]", "Generates and create the cloudformation template for the specific component"
62
- def create(component, main_stack = false)
68
+ def create(component = nil, main_stack = 'false')
63
69
  begin
64
- say "#{banner(component)}\n"
70
+ say "#{banner}\n"
65
71
 
66
- data = cloudformation(component, options, false)
72
+ components(options, component).each do |id|
73
+ say get_key_value("\nComponent", id)
67
74
 
68
- post_data = {
69
- 'name_suffix' => options[:stack],
70
- 'service_stack' => main_stack,
71
- 'template' => data,
72
- 'parameters' => Tools::Cloudformation::Generator.parameters(data),
73
- }
75
+ data = cloudformation(id, options, false)
74
76
 
75
- response = api.post sprintf(config.app['stack_create_endpoint'], options[:env], component), JSON.pretty_generate(post_data)
77
+ post_data = {
78
+ 'name_suffix' => options[:stack],
79
+ 'service_stack' => main_stack.match(/(true|t|yes|y|1)$/i) != nil,
80
+ 'template' => data,
81
+ 'parameters' => Tools::Cloudformation::Generator.parameters(data),
82
+ }
76
83
 
77
- if response.success?
78
- say "Stack creation for component '#{component}' successfully started", :green
79
- else
80
- api_error response
81
- end
84
+ response = api.post sprintf(config.app['stack_create_endpoint'], options[:env], id), JSON.pretty_generate(post_data)
85
+
86
+ if response.success?
87
+ say "Stack creation for component '#{component}' successfully started", :green
88
+ else
89
+ api_error(response, false)
90
+ end
91
+ end
82
92
  rescue Exception => e
83
- puts e.backtrace
84
93
  error e.message
85
94
  end
86
-
87
95
  end
88
96
 
89
97
  method_option :variant, :type => :string, :default => 'default', :desc => "The variant to use, i.e default|scheduled"
90
98
  method_option :group, :type => :string, :default => nil, :desc => "The group name to override the component id"
91
- desc "stack update [COMPONENT]", "Generates and updates the cloudformation template for the specific component"
92
- def update(component)
99
+ method_option :tags, :type => :array, :default => nil, :desc => "The tags of the components you want to deploy (i.e 'renderer')"
100
+ desc "stack update [COMPONENT = nil]", "Generates and updates the cloudformation template for the specific component"
101
+ def update(component = nil)
93
102
 
94
- say "#{banner(component)}\n"
103
+ say "#{banner}\n"
95
104
 
96
- stack_name = "#{options[:env]}-#{component}-#{options[:stack]}"
97
- data = cloudformation(component, options, false)
105
+ components(options, component).each do |id|
106
+ say get_key_value("\nComponent", id)
98
107
 
99
- post_data = {
100
- 'template' => data,
101
- 'parameters' => Tools::Cloudformation::Generator.parameters(data)
102
- }
108
+ stack_name = "#{options[:env]}-#{id}-#{options[:stack]}"
109
+ data = cloudformation(id, options, false)
103
110
 
104
- response = api.post sprintf(config.app['stack_update_endpoint'], options[:env], component, stack_name), JSON.pretty_generate(post_data)
111
+ post_data = {
112
+ 'template' => data,
113
+ 'parameters' => Tools::Cloudformation::Generator.parameters(data)
114
+ }
105
115
 
106
- if response.success?
107
- say "Stack update for component '#{component}' successfully started", :green
108
- else
109
- api_error response
116
+ response = api.post sprintf(config.app['stack_update_endpoint'], options[:env], id, stack_name), JSON.pretty_generate(post_data)
117
+
118
+ if response.success?
119
+ say "Stack update for component '#{id}' successfully started", :green
120
+ else
121
+ api_error(response, false)
122
+ end
110
123
  end
111
124
 
112
125
  end
@@ -134,31 +147,36 @@ module BBC
134
147
 
135
148
  end
136
149
 
137
- desc "stack events [COMPONENT]", "Shows the stack events for a component"
150
+ desc "stack events [COMPONENT = nil]", "Shows the stack events for a component"
138
151
  method_option :stack, :type => :string, :default => 'main', :desc => "The name of the stack to use"
139
152
  method_option :limit, :type => :numeric, :default => 5, :desc => "Limit how many records to show"
140
- def events(component)
153
+ method_option :tags, :type => :array, :default => nil, :desc => "The tags of the components you want to deploy (i.e 'renderer')"
154
+ def events(component = nil)
141
155
 
142
156
  say "#{banner}\n"
143
157
 
144
- stack_name = "#{options[:env]}-#{component}-#{options[:stack]}"
145
- response = api.get sprintf(config.app['stack_events'], options[:env], component, stack_name)
158
+ components(options, component).each do |id|
159
+ say get_key_value("\nComponent", id)
146
160
 
147
- if response.success?
148
- events = JSON.parse(response.body)
161
+ stack_name = "#{options[:env]}-#{id}-#{options[:stack]}"
162
+ response = api.get sprintf(config.app['stack_events'], options[:env], id, stack_name)
149
163
 
150
- data = events.slice(0,(options[:limit])).map do |event|
151
- event.split(" ")
152
- end
164
+ if response.success?
165
+ events = JSON.parse(response.body)
166
+
167
+ data = events.slice(0,(options[:limit])).map do |event|
168
+ event.split(" ")
169
+ end
153
170
 
154
- print_table(
155
- build_table(
156
- ['Event type', 'CF type', 'Name', 'Status'],
157
- data
171
+ print_table(
172
+ build_table(
173
+ ['Event type', 'CF type', 'Name', 'Status'],
174
+ data
175
+ )
158
176
  )
159
- )
160
- else
161
- api_error response
177
+ else
178
+ api_error(response, false)
179
+ end
162
180
  end
163
181
  end
164
182
 
@@ -1,7 +1,7 @@
1
1
  module BBC
2
2
  module Cosmos
3
3
  module Tools
4
- VERSION = "0.1.6"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbc-cosmos-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Jack