bbc-cosmos-tools 0.1.0 → 0.1.2

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: 6c25993fa89a80e8a8d885830fa98979a6dd4602
4
- data.tar.gz: 577b33a47bca5af332eb92773388b42366e45389
3
+ metadata.gz: bd2fe62898213594ae112ece7e649b43252cd876
4
+ data.tar.gz: f2d9b802382334839d5d0f4489e37f062647078f
5
5
  SHA512:
6
- metadata.gz: b46bd3807068a3a989aef79a1f0e6d4d1fe80fbb0472ed52fd6dc4aa17df5c744e0ec827c82d3d5a937a5ba29b0e8ed91c0038425266da0be782efd33fb5093c
7
- data.tar.gz: 1aba13524eaed9852a5eeb16d6ee60c522d8c1fa0de64d4d49a1b02780732b6db158f3f27fb45e4557df6a32ad8192214264ead1f64d7494398809bed6f4288e
6
+ metadata.gz: 3fe64c5242a8920e6141bfee928c8f7d136e63efad9ccfb9c2663c429c745b5b1e4df1b2d51ea9fad9ef64358732ef6fe79eaf17eea153eedfd9cdbf8682d9e5
7
+ data.tar.gz: 355b1b44c9d4ca7b4df2160c8111e39b3e1e970e4ce18f2b66a4e2405f7f9d8cc3124cf4dc7a082cefbb4d6525a661f2c5d7b55250c6702d51f79db10f14b362
@@ -1,6 +1,5 @@
1
1
  require "thor"
2
2
  require 'bbc/cosmos/tools/commands/config'
3
- require 'bbc/cosmos/tools/commands/cloud_formation'
4
3
  require 'bbc/cosmos/tools/commands/release'
5
4
  require 'bbc/cosmos/tools/commands/stack'
6
5
 
@@ -13,16 +12,12 @@ module BBC
13
12
  desc "config", "Cosmos sub commands"
14
13
  subcommand "config", Commands::Config
15
14
 
16
- desc "cf", "Cloudformation sub commands"
17
- subcommand "cf", Commands::CloudFormation
18
-
19
15
  desc "release", "Cosmos release sub commands"
20
16
  subcommand "release", Commands::Release
21
17
 
22
18
  desc "stack", "Cosmos stack sub commands"
23
19
  subcommand "stack", Commands::Stack
24
20
 
25
-
26
21
  end
27
22
  end
28
23
  end
@@ -14,10 +14,10 @@ module BBC
14
14
 
15
15
  package_name "BBC Cosmos config tool"
16
16
 
17
- class_option :key_path, :type => :string, :default => ENV['DEV_CERT_PATH'], :desc => "The path to your dev cert, by default it looks in the env variable '$DEV_CERT_PATH'"
17
+ class_option :key_path, :type => :string, :default => ENV['DEV_CERT_PATH'], :desc => "The path to your dev cert, by default the value of the env variable $DEV_CERT_PATH is used"
18
18
  class_option :env, :type => :string, :default => 'int', :desc => "The environment to target"
19
19
  class_option :base, :type => :string, :desc => "The base path for the configs repo"
20
- class_option :project, :type => :string, :default => ENV['BBC_COSMOS_TOOLS_PROJECT'], :desc => "The name of the project"
20
+ class_option :project, :type => :string, :default => ENV['BBC_COSMOS_TOOLS_PROJECT'], :desc => "The name of the project, by default the value of the env variable $BBC_COSMOS_TOOLS_PROJECT is used"
21
21
 
22
22
  def initialize(args = [], local_options = {}, config = {})
23
23
  super(args, local_options, config)
@@ -9,6 +9,8 @@ module BBC
9
9
  class Stack < Base
10
10
  attr_accessor :api
11
11
 
12
+ class_option :stack, :type => :string, :default => 'main', :desc => "The name of the stack to use"
13
+
12
14
  def initialize(args = [], local_options = {}, thor_config = {})
13
15
  super(args, local_options, thor_config)
14
16
  @api = BBC::Cosmos::Tools::API.new(config.app['api'], options[:key_path])
@@ -44,36 +46,70 @@ module BBC
44
46
 
45
47
  end
46
48
 
47
- desc "stack events [COMPONENT]", "Shows the stack events for a component"
48
- method_option :stack, :type => :string, :default => 'main', :desc => "The name of the stack to use"
49
- method_option :limit, :type => :numeric, :default => 5, :desc => "Limit how many records to show"
50
- def events(component)
49
+ method_option :variant, :type => :string, :default => 'default', :desc => "The variant to use, i.e default|scheduled"
50
+ method_option :group, :type => :string, :default => nil, :desc => "The group name to override the component id"
51
+ desc "stack generate [COMPONENT]", "Generates a cloudformation template based on a type of component, the identifier and the environment"
52
+ def generate(component)
51
53
 
52
- say "#{banner}\n"
54
+ say "#{banner(component)}\n"
55
+ say cloudformation(component, options), :white
53
56
 
54
- stack_name = "#{options[:env]}-#{component}-#{options[:stack]}"
55
- response = api.get sprintf(config.app['stack_events'], options[:env], component, stack_name)
57
+ end
58
+
59
+ method_option :variant, :type => :string, :default => 'default', :desc => "The variant to use, i.e default|scheduled"
60
+ method_option :group, :type => :string, :default => nil, :desc => "The group name to override the component id"
61
+ desc "stack create [COMPONENT, MAIN_STACK = false]", "Generates and create the cloudformation template for the specific component"
62
+ def create(component, main_stack = false)
63
+
64
+ say "#{banner(component)}\n"
65
+
66
+ data = cloudformation(component, options, false)
67
+
68
+ post_data = {
69
+ 'name_suffix' => options[:stack],
70
+ 'service_stack' => main_stack,
71
+ 'template' => data,
72
+ 'parameters' => Tools::Cloudformation::Generator.parameters(data),
73
+ }
74
+
75
+ @api = BBC::Cosmos::Tools::Config::API.new(config.app['api'], options[:key_path])
76
+ response = @api.post sprintf(config.app['stack_create_endpoint'], options[:env], component), JSON.pretty_generate(post_data)
56
77
 
57
78
  if response.success?
58
- events = JSON.parse(response.body)
79
+ say "Stack creation for component '#{component}' successfully started", :green
80
+ else
81
+ api_error response
82
+ end
59
83
 
60
- data = events.slice(0,(options[:limit])).map do |event|
61
- event.split(" ")
62
- end
84
+ end
63
85
 
64
- print_table(
65
- build_table(
66
- ['Event type', 'CF type', 'Name', 'Status'],
67
- data
68
- )
69
- )
86
+ method_option :variant, :type => :string, :default => 'default', :desc => "The variant to use, i.e default|scheduled"
87
+ method_option :group, :type => :string, :default => nil, :desc => "The group name to override the component id"
88
+ desc "stack update [COMPONENT]", "Generates and updates the cloudformation template for the specific component"
89
+ def update(component)
90
+
91
+ say "#{banner(component)}\n"
92
+
93
+ stack_name = "#{options[:env]}-#{component}-#{options[:stack]}"
94
+ data = cloudformation(component, options, false)
95
+
96
+ post_data = {
97
+ 'template' => data,
98
+ 'parameters' => Tools::Cloudformation::Generator.parameters(data)
99
+ }
100
+
101
+ @api = BBC::Cosmos::Tools::Config::API.new(config.app['api'], options[:key_path])
102
+ response = @api.post sprintf(config.app['stack_update_endpoint'], options[:env], component, stack_name), JSON.pretty_generate(post_data)
103
+
104
+ if response.success?
105
+ say "Stack update for component '#{component}' successfully started", :green
70
106
  else
71
107
  api_error response
72
108
  end
109
+
73
110
  end
74
111
 
75
112
  desc "stack delete [COMPONENT]", "Deletes a stack"
76
- method_option :stack, :type => :string, :default => 'main', :desc => "The name of the stack to use"
77
113
  def delete(component)
78
114
 
79
115
  say "#{banner(component)}\n"
@@ -97,9 +133,44 @@ module BBC
97
133
 
98
134
  end
99
135
 
136
+ desc "stack events [COMPONENT]", "Shows the stack events for a component"
137
+ method_option :stack, :type => :string, :default => 'main', :desc => "The name of the stack to use"
138
+ method_option :limit, :type => :numeric, :default => 5, :desc => "Limit how many records to show"
139
+ def events(component)
140
+
141
+ say "#{banner}\n"
142
+
143
+ stack_name = "#{options[:env]}-#{component}-#{options[:stack]}"
144
+ response = api.get sprintf(config.app['stack_events'], options[:env], component, stack_name)
145
+
146
+ if response.success?
147
+ events = JSON.parse(response.body)
148
+
149
+ data = events.slice(0,(options[:limit])).map do |event|
150
+ event.split(" ")
151
+ end
100
152
 
153
+ print_table(
154
+ build_table(
155
+ ['Event type', 'CF type', 'Name', 'Status'],
156
+ data
157
+ )
158
+ )
159
+ else
160
+ api_error response
161
+ end
162
+ end
163
+
164
+ private
101
165
 
166
+ def cloudformation(component, options, to_json = true)
167
+ config_data = config
102
168
 
169
+ Tools::Cloudformation::Generator.create(component, config, options, to_json) do
170
+ component_identifier = options[:group].nil? ? component : options[:group]
171
+ instance_eval config_data.cf_templates(component_identifier, options[:stack])
172
+ end
173
+ end
103
174
  end
104
175
  end
105
176
  end
@@ -1,7 +1,7 @@
1
1
  module BBC
2
2
  module Cosmos
3
3
  module Tools
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
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.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Jack
@@ -100,7 +100,6 @@ files:
100
100
  - lib/bbc/cosmos/tools/app.rb
101
101
  - lib/bbc/cosmos/tools/cloudformation/generator.rb
102
102
  - lib/bbc/cosmos/tools/commands/base.rb
103
- - lib/bbc/cosmos/tools/commands/cloud_formation.rb
104
103
  - lib/bbc/cosmos/tools/commands/config.rb
105
104
  - lib/bbc/cosmos/tools/commands/release.rb
106
105
  - lib/bbc/cosmos/tools/commands/stack.rb
@@ -1,116 +0,0 @@
1
- require "bbc/cosmos/tools/config"
2
- require 'bbc/cosmos/tools/commands/base'
3
- require 'bbc/cosmos/tools/cloudformation/generator'
4
-
5
- module BBC
6
- module Cosmos
7
- module Tools
8
- module Commands
9
- class CloudFormation < Base
10
-
11
- class_option :stack, :type => :string, :default => 'main', :desc => "The name of the stack to use"
12
- class_option :variant, :type => :string, :default => 'default', :desc => "The variant to use, i.e default|scheduled|"
13
- class_option :group, :type => :string, :default => nil, :desc => "The group name to override the component id"
14
-
15
- def initialize(args = [], local_options = {}, config = {})
16
- super(args, local_options, config)
17
- end
18
-
19
- desc "cf generate [COMPONENT]", "Generates a cloudformation template based on a type of component, the identifier and the environment"
20
- def generate(component)
21
-
22
- say "#{banner(component)}\n"
23
- say cloudformation(component, options), :white
24
-
25
- end
26
-
27
- desc "cf create [COMPONENT, STACK_NAME = 'main', MAIN_STACK = false]", "Generates and create the cloudformation template for the specific component"
28
- def create(component, main_stack = false)
29
-
30
- say "#{banner(component)}\n"
31
-
32
- data = cloudformation(component, options, false)
33
-
34
- post_data = {
35
- 'name_suffix' => options[:stack],
36
- 'service_stack' => main_stack,
37
- 'template' => data,
38
- 'parameters' => Tools::Cloudformation::Generator.parameters(data),
39
- }
40
-
41
- @api = BBC::Cosmos::Tools::Config::API.new(config.app['api'], options[:key_path])
42
- response = @api.post sprintf(config.app['stack_create_endpoint'], options[:env], component), JSON.pretty_generate(post_data)
43
-
44
- if response.success?
45
- say "Stack creation for component '#{component}' successfully started", :green
46
- else
47
- api_error response
48
- end
49
-
50
- end
51
-
52
- desc "cf update [COMPONENT]", "Generates and updates the cloudformation template for the specific component"
53
- def update(component)
54
-
55
- say "#{banner(component)}\n"
56
-
57
- stack_name = "#{options[:env]}-#{component}-#{options[:stack]}"
58
- data = cloudformation(component, options, false)
59
-
60
- post_data = {
61
- 'template' => data,
62
- 'parameters' => Tools::Cloudformation::Generator.parameters(data)
63
- }
64
-
65
- @api = BBC::Cosmos::Tools::Config::API.new(config.app['api'], options[:key_path])
66
- response = @api.post sprintf(config.app['stack_update_endpoint'], options[:env], component, stack_name), JSON.pretty_generate(post_data)
67
-
68
- if response.success?
69
- say "Stack update for component '#{component}' successfully started", :green
70
- else
71
- api_error response
72
- end
73
-
74
- end
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
-
101
- private
102
-
103
- def cloudformation(component, options, to_json = true)
104
- config_data = config
105
-
106
- Tools::Cloudformation::Generator.create(component, config, options, to_json) do
107
- component_identifier = options[:group].nil? ? component : options[:group]
108
- instance_eval config_data.cf_templates(component_identifier, options[:stack])
109
- end
110
- end
111
-
112
- end
113
- end
114
- end
115
- end
116
- end