bbc-cosmos-tools 0.0.7 → 0.1.0

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: ac699293cfb105c83aa421fb01338d7c29c3ceda
4
- data.tar.gz: c5a2f30919bc440a2039052991fa14fde1e7cce5
3
+ metadata.gz: 6c25993fa89a80e8a8d885830fa98979a6dd4602
4
+ data.tar.gz: 577b33a47bca5af332eb92773388b42366e45389
5
5
  SHA512:
6
- metadata.gz: 41c9cdc07e529c981d43145402395fcc9a10014b708465a798f4326c746b0007ce1e6dd50c474e571575ec74468dd1b844a695769ba986abca45374163197450
7
- data.tar.gz: 0145fff6eff60745ba45fd9a93d565960ac28af7b3ac6727afa28e378621eba7669db2bdae403a5936aa5db36dbaefeea7012c8ca297e122279a1315bac0d04a
6
+ metadata.gz: b46bd3807068a3a989aef79a1f0e6d4d1fe80fbb0472ed52fd6dc4aa17df5c744e0ec827c82d3d5a937a5ba29b0e8ed91c0038425266da0be782efd33fb5093c
7
+ data.tar.gz: 1aba13524eaed9852a5eeb16d6ee60c522d8c1fa0de64d4d49a1b02780732b6db158f3f27fb45e4557df6a32ad8192214264ead1f64d7494398809bed6f4288e
@@ -7,6 +7,14 @@ module BBC
7
7
  module Cloudformation
8
8
  class Generator
9
9
 
10
+ def self.component_exists?(component, config)
11
+ config.resources['cloudformation']['components'][component]
12
+ end
13
+
14
+ def self.stack_exists?(component, config, stack)
15
+ config.resources['cloudformation']['components'][component][stack]
16
+ end
17
+
10
18
  def self.create(component, config, options, to_json = false, &block)
11
19
 
12
20
  template = BBC::CfnDsl::CloudFormationTemplate.new
@@ -17,7 +25,7 @@ module BBC
17
25
  else
18
26
  hash = JSON.parse(template.to_json)
19
27
 
20
- if config.resources['cloudformation']['components'][component][options[:stack]]
28
+ if component_exists?(component, config) && stack_exists?(component, config, options[:stack])
21
29
  config.resources['cloudformation']['components'][component][options[:stack]]['variants'][options[:variant]].each do |key, value|
22
30
  hash['Parameters'][key]['Default'] = value if hash['Parameters'][key]
23
31
  end
@@ -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(message, response)
45
- error(message, false)
46
- error(JSON.pretty_generate(response.body))
44
+ def api_error(response)
45
+ error_message = JSON.parse(response.body)['message']
46
+ error(error_message)
47
47
  end
48
48
 
49
49
  def build_table(headers, data)
@@ -71,7 +71,7 @@ module BBC
71
71
  end
72
72
 
73
73
  def error(message, die = true)
74
- say message, :red
74
+ say "#{message}\n", :red
75
75
  exit 1 if die
76
76
  end
77
77
 
@@ -44,7 +44,7 @@ module BBC
44
44
  if response.success?
45
45
  say "Stack creation for component '#{component}' successfully started", :green
46
46
  else
47
- api_error("There was an error creating your stack", response.body)
47
+ api_error response
48
48
  end
49
49
 
50
50
  end
@@ -68,11 +68,36 @@ module BBC
68
68
  if response.success?
69
69
  say "Stack update for component '#{component}' successfully started", :green
70
70
  else
71
- api_error('There was an error updating your stack', response.body)
71
+ api_error response
72
72
  end
73
73
 
74
74
  end
75
75
 
76
+ desc "cf delete [COMPONENT]", "Deletes a stack"
77
+ def update(component)
78
+
79
+ say "#{banner(component)}\n"
80
+
81
+ reply = yes?("Are you sure you want to delete the above stack?", :yellow)
82
+ if reply || reply.nil?
83
+
84
+ stack_name = "#{options[:env]}-#{component}-#{options[:stack]}"
85
+
86
+ @api = BBC::Cosmos::Tools::Config::API.new(config.app['api'], options[:key_path])
87
+ response = @api.post sprintf(config.app['stack_delete'], options[:env], component, stack_name), JSON.pretty_generate({})
88
+
89
+ if response.success?
90
+ say "Stack delete for component '#{component}' successfully started", :green
91
+ else
92
+ api_error response
93
+ end
94
+ else
95
+ error 'Action cancelled'
96
+ end
97
+
98
+ end
99
+
100
+
76
101
  private
77
102
 
78
103
  def cloudformation(component, options, to_json = true)
@@ -73,7 +73,7 @@ module BBC
73
73
  if response.success?
74
74
  say 'Successfully saved', :green
75
75
  else
76
- api_error('Error pusing config', response.body)
76
+ api_error response
77
77
  end
78
78
  end
79
79
 
@@ -41,7 +41,7 @@ module BBC
41
41
  )
42
42
  say "\n"
43
43
  else
44
- api_error('There was a problem retrieving the releases for this component', response)
44
+ api_error response
45
45
  end
46
46
  end
47
47
 
@@ -62,6 +62,7 @@ module BBC
62
62
  component_release = release_id
63
63
  if release_id.nil?
64
64
  response = api.get sprintf(config.app['release'], id)
65
+ api_error response unless response.success?
65
66
  component_release = JSON.parse(response.body)['releases'].first['version']
66
67
  end
67
68
 
@@ -77,7 +78,7 @@ module BBC
77
78
  say "Deployment started successfully: #{config.app['api']}#{data['url']}\n", :green
78
79
 
79
80
  else
80
- api_error("There was a problem deploying this component", response)
81
+ api_error response
81
82
  end
82
83
 
83
84
  end
@@ -124,7 +125,7 @@ module BBC
124
125
  say "\n"
125
126
  end
126
127
  else
127
- api_error('There was a problem retrieving the releases for this component', response)
128
+ api_error response
128
129
  end
129
130
  end
130
131
 
@@ -20,21 +20,27 @@ module BBC
20
20
  say "#{banner}\n"
21
21
  response = api.get sprintf(config.app['stacks'], options[:env], component)
22
22
 
23
- data = JSON.parse(response.body).map do |stack|
24
- [
25
- stack['name'],
26
- stack['main_stack'],
27
- stack['updated_at'],
28
- stack['status']
29
- ]
30
- end
23
+ if response.success?
24
+
25
+ data = JSON.parse(response.body).map do |stack|
26
+ [
27
+ stack['name'],
28
+ stack['main_stack'],
29
+ stack['updated_at'],
30
+ stack['status']
31
+ ]
32
+ end
31
33
 
32
- print_table(
33
- build_table(
34
- ['Name', 'Main stack', 'Updated at', 'Status'],
35
- data
34
+ print_table(
35
+ build_table(
36
+ ['Name', 'Main stack', 'Updated at', 'Status'],
37
+ data
38
+ )
36
39
  )
37
- )
40
+
41
+ else
42
+ api_error response
43
+ end
38
44
 
39
45
  end
40
46
 
@@ -47,20 +53,53 @@ module BBC
47
53
 
48
54
  stack_name = "#{options[:env]}-#{component}-#{options[:stack]}"
49
55
  response = api.get sprintf(config.app['stack_events'], options[:env], component, stack_name)
50
- events = JSON.parse(response.body)
51
56
 
52
- data = events.slice(0,(options[:limit])).map do |event|
53
- event.split(" ")
54
- end
57
+ if response.success?
58
+ events = JSON.parse(response.body)
55
59
 
56
- print_table(
57
- build_table(
58
- ['Event type', 'CF type', 'Name', 'Status'],
59
- data
60
+ data = events.slice(0,(options[:limit])).map do |event|
61
+ event.split(" ")
62
+ end
63
+
64
+ print_table(
65
+ build_table(
66
+ ['Event type', 'CF type', 'Name', 'Status'],
67
+ data
68
+ )
60
69
  )
61
- )
70
+ else
71
+ api_error response
72
+ end
73
+ end
74
+
75
+ desc "stack delete [COMPONENT]", "Deletes a stack"
76
+ method_option :stack, :type => :string, :default => 'main', :desc => "The name of the stack to use"
77
+ def delete(component)
78
+
79
+ say "#{banner(component)}\n"
80
+
81
+ reply = yes?("Are you sure you want to delete the above stack?", :yellow)
82
+ if reply || reply.nil?
83
+
84
+ stack_name = "#{options[:env]}-#{component}-#{options[:stack]}"
85
+
86
+ @api = BBC::Cosmos::Tools::Config::API.new(config.app['api'], options[:key_path])
87
+ response = @api.post sprintf(config.app['stack_delete'], options[:env], component, stack_name), JSON.pretty_generate({})
88
+
89
+ if response.success?
90
+ say "Stack delete for component '#{component}' successfully started", :green
91
+ else
92
+ api_error response
93
+ end
94
+ else
95
+ error 'Action cancelled'
96
+ end
97
+
62
98
  end
63
99
 
100
+
101
+
102
+
64
103
  end
65
104
  end
66
105
  end
@@ -1,7 +1,7 @@
1
1
  module BBC
2
2
  module Cosmos
3
3
  module Tools
4
- VERSION = "0.0.7"
4
+ VERSION = "0.1.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.0.7
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Jack