cfndk 0.0.5 → 0.0.6
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 +4 -4
- data/bin/cfndk +2 -131
- data/cfndk.gemspec +1 -1
- data/lib/cfndk.rb +1 -0
- data/lib/cfndk/command.rb +136 -0
- data/lib/cfndk/stack.rb +10 -10
- data/lib/cfndk/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19325cb7304add2725fc19d27eaf72dbd4c4576c
|
4
|
+
data.tar.gz: 7f237af4102d774bf24ea009cfb3a77428271e0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec6bbe3c622e319a5f9d06527bc0117908db0803f966ac7c657b2f101484e7d39c953f0ed9ff561903908d375b7227e96d0990fc529da00eeb27f2c78351eaf6
|
7
|
+
data.tar.gz: 71e19e30a2342f2c9aa4ebeaee61e8d16d96a3993ed7e5f16e963427dc2cd26e648ad770e9cb5cea8f9fa0c296cd640b57f8940b0957bf591dc9a79456c68b21
|
data/bin/cfndk
CHANGED
@@ -16,136 +16,7 @@ require 'logger'
|
|
16
16
|
|
17
17
|
require 'cfndk.rb'
|
18
18
|
|
19
|
-
def do_destroy(option)
|
20
|
-
return true if option[:force]
|
21
|
-
loop do
|
22
|
-
print 'destroy? [yes|no]:'
|
23
|
-
res = STDIN.gets
|
24
|
-
case res
|
25
|
-
when /^yes/
|
26
|
-
return true
|
27
|
-
when /^no/, /^$/
|
28
|
-
return false
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
19
|
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
34
20
|
|
35
|
-
|
36
|
-
|
37
|
-
option = {
|
38
|
-
config_path: "#{cur_dir}/cfndk.yml",
|
39
|
-
uuid: ENV['CFNDK_UUID'] || nil,
|
40
|
-
properties: {},
|
41
|
-
stack_names: nil,
|
42
|
-
force: false,
|
43
|
-
}
|
44
|
-
|
45
|
-
opt = OptionParser.new do |o|
|
46
|
-
o.version = CFnDK::VERSION
|
47
|
-
o.summary_indent = ' ' * 4
|
48
|
-
o.banner = "Version: #{CFnDK::VERSION} \nUsage: cfndk [cmd] [options]"
|
49
|
-
o.on_head('[cmd]',
|
50
|
-
' init create config YAML file',
|
51
|
-
' create create stacks',
|
52
|
-
' update update stacks',
|
53
|
-
' create-or-changeset create stacks or create changeset',
|
54
|
-
' destroy destroy stacks',
|
55
|
-
' generate-uuid generate UUID',
|
56
|
-
' report-event report stack event',
|
57
|
-
' report-stack report stack',
|
58
|
-
' report-stack-resource report stack resource',
|
59
|
-
'[enviroment variables]',
|
60
|
-
" AWS_PROFILE: #{ENV['AWS_PROFILE']}",
|
61
|
-
" AWS_DEFAULT_REGION: #{ENV['AWS_DEFAULT_REGION']}",
|
62
|
-
" AWS_REGION: #{ENV['AWS_REGION']}",
|
63
|
-
" AWS_ACCESS_KEY_ID: #{ENV['AWS_ACCESS_KEY_ID']}",
|
64
|
-
" AWS_SECRET_ACCESS_KEY: #{ENV['AWS_SECRET_ACCESS_KEY']}",
|
65
|
-
" AWS_SESSION_TOKEN: #{ENV['AWS_SECRET_ACCESS_KEY']}",
|
66
|
-
" AWS_CONTAINER_CREDENTIALS_RELATIVE_URI: #{ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI']}",
|
67
|
-
'[options]')
|
68
|
-
o.on('-v', '--verbose', 'verbose mode') { |v| option[:v] = v }
|
69
|
-
o.on('-c', '--config_path cfndi.yml', "config path (default: #{option[:config_path]})") { |v| option[:config_path] = v }
|
70
|
-
o.on('-p', '--properties name=value', 'properties') do |v|
|
71
|
-
md = v.match(/^([a-zA-Z_]+[a-zA-Z0-9_]*)=(.*)$/)
|
72
|
-
if md
|
73
|
-
option[:properties][md[0]] = md[1]
|
74
|
-
else
|
75
|
-
raise "invalid properties: '#{v}'" unless md
|
76
|
-
end
|
77
|
-
end
|
78
|
-
o.on('-a', '--auto-uuid') { option[:uuid] = SecureRandom.uuid }
|
79
|
-
o.on('-u', '--uuid uuid') { |v| option[:uuid] = v }
|
80
|
-
o.on('-n', '--stack-names name1,name2') { |v| option[:stack_names] = v.split(/\s*,\s*/) }
|
81
|
-
o.on('--no-color') { |b| Rainbow.enabled = false }
|
82
|
-
o.on('-f', '--force') { |b| option[:force] = true }
|
83
|
-
o.permute!(ARGV)
|
84
|
-
end
|
85
|
-
|
86
|
-
logger = CFnDK::Logger.new(option)
|
87
|
-
|
88
|
-
if ARGV.length != 1
|
89
|
-
puts opt.help
|
90
|
-
exit 1
|
91
|
-
elsif ARGV[0] == 'generate-uuid'
|
92
|
-
puts SecureRandom.uuid
|
93
|
-
exit 0
|
94
|
-
elsif ARGV[0] == 'init'
|
95
|
-
if File.file?(option[:config_path])
|
96
|
-
logger.error "File exist. #{option[:config_path]}".color(:red)
|
97
|
-
exit 1
|
98
|
-
end
|
99
|
-
logger.info 'init...'.color(:green)
|
100
|
-
FileUtils.cp_r(Dir.glob(File.dirname(__FILE__) + '/../skel/*'), './')
|
101
|
-
logger.info "create #{option[:config_path]}".color(:green)
|
102
|
-
exit 0
|
103
|
-
end
|
104
|
-
|
105
|
-
unless File.file?(option[:config_path])
|
106
|
-
logger.error "File does not exist. #{option[:config_path]}".color(:red)
|
107
|
-
exit 1
|
108
|
-
end
|
109
|
-
|
110
|
-
data = open(option[:config_path], 'r') { |f| YAML.load(f) } if File.file?(option[:config_path])
|
111
|
-
credentials = CFnDK::CredentialProviderChain.new.resolve
|
112
|
-
stacks = CFnDK::Stacks.new(data, option, credentials)
|
113
|
-
keypairs = CFnDK::KeyPairs.new(data, option, credentials)
|
114
|
-
|
115
|
-
if ARGV[0] == 'create'
|
116
|
-
logger.info 'create...'.color(:green)
|
117
|
-
stacks.validate
|
118
|
-
keypairs.create
|
119
|
-
stacks.create
|
120
|
-
elsif ARGV[0] == 'update'
|
121
|
-
logger.info 'update...'.color(:green)
|
122
|
-
stacks.validate
|
123
|
-
stacks.update
|
124
|
-
elsif ARGV[0] == 'create-or-changeset'
|
125
|
-
logger.info 'create or changeset...'.color(:green)
|
126
|
-
stacks.validate
|
127
|
-
stacks.create_or_changeset
|
128
|
-
elsif ARGV[0] == 'destroy'
|
129
|
-
logger.info 'destroy...'.color(:green)
|
130
|
-
if do_destroy(option)
|
131
|
-
stacks.destroy
|
132
|
-
keypairs.destroy
|
133
|
-
end
|
134
|
-
elsif ARGV[0] == 'validate'
|
135
|
-
logger.info 'validate...'.color(:green)
|
136
|
-
stacks.validate
|
137
|
-
elsif ARGV[0] == 'report-event'
|
138
|
-
logger.info 'report event...'.color(:green)
|
139
|
-
stacks.report_event
|
140
|
-
elsif ARGV[0] == 'report-stack'
|
141
|
-
logger.info 'report stack...'.color(:green)
|
142
|
-
stacks.report_stack
|
143
|
-
elsif ARGV[0] == 'report-stack-resource'
|
144
|
-
logger.info 'report stack resource...'.color(:green)
|
145
|
-
stacks.report_stack_resource
|
146
|
-
else
|
147
|
-
puts opt.help
|
148
|
-
exit 1
|
149
|
-
end
|
150
|
-
|
151
|
-
exit 0
|
21
|
+
c = CFnDK::Command.new
|
22
|
+
exit c.execute
|
data/cfndk.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
22
|
spec.add_development_dependency 'rake', '~> 11.1.2'
|
23
23
|
|
24
|
-
spec.add_dependency 'rainbow', '~>
|
24
|
+
spec.add_dependency 'rainbow', '~> 3.0.0'
|
25
25
|
spec.add_dependency 'aws-sdk', '~> 3'
|
26
26
|
spec.add_dependency 'camelizable', '~> 0.0.3'
|
27
27
|
spec.add_dependency 'terminal-table', '~> 1'
|
data/lib/cfndk.rb
CHANGED
@@ -0,0 +1,136 @@
|
|
1
|
+
module CFnDK
|
2
|
+
class Command
|
3
|
+
def initialize
|
4
|
+
@cur_dir = Dir.getwd
|
5
|
+
@option = {
|
6
|
+
config_path: "#{@cur_dir}/cfndk.yml",
|
7
|
+
uuid: ENV['CFNDK_UUID'] || nil,
|
8
|
+
properties: {},
|
9
|
+
stack_names: nil,
|
10
|
+
force: false,
|
11
|
+
}
|
12
|
+
|
13
|
+
@opt = OptionParser.new do |o|
|
14
|
+
o.version = CFnDK::VERSION
|
15
|
+
o.summary_indent = ' ' * 4
|
16
|
+
o.banner = "Version: #{CFnDK::VERSION} \nUsage: cfndk [cmd] [options]"
|
17
|
+
o.on_head('[cmd]',
|
18
|
+
' init create config YAML file',
|
19
|
+
' create create stacks',
|
20
|
+
' update update stacks',
|
21
|
+
' create-or-changeset create stacks or create changeset',
|
22
|
+
' destroy destroy stacks',
|
23
|
+
' generate-uuid generate UUID',
|
24
|
+
' report-event report stack event',
|
25
|
+
' report-stack report stack',
|
26
|
+
' report-stack-resource report stack resource',
|
27
|
+
'[enviroment variables]',
|
28
|
+
" AWS_PROFILE: #{ENV['AWS_PROFILE']}",
|
29
|
+
" AWS_DEFAULT_REGION: #{ENV['AWS_DEFAULT_REGION']}",
|
30
|
+
" AWS_REGION: #{ENV['AWS_REGION']}",
|
31
|
+
" AWS_ACCESS_KEY_ID: #{ENV['AWS_ACCESS_KEY_ID']}",
|
32
|
+
" AWS_SECRET_ACCESS_KEY: #{ENV['AWS_SECRET_ACCESS_KEY']}",
|
33
|
+
" AWS_SESSION_TOKEN: #{ENV['AWS_SECRET_ACCESS_KEY']}",
|
34
|
+
" AWS_CONTAINER_CREDENTIALS_RELATIVE_URI: #{ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI']}",
|
35
|
+
'[options]')
|
36
|
+
o.on('-v', '--verbose', 'verbose mode') { |v| @option[:v] = v }
|
37
|
+
o.on('-c', '--config_path cfndi.yml', "config path (default: #{@option[:config_path]})") { |v| @option[:config_path] = v }
|
38
|
+
o.on('-p', '--properties name=value', 'properties') do |v|
|
39
|
+
md = v.match(/^([a-zA-Z_]+[a-zA-Z0-9_]*)=(.*)$/)
|
40
|
+
if md
|
41
|
+
@option[:properties][md[0]] = md[1]
|
42
|
+
else
|
43
|
+
raise "invalid properties: '#{v}'" unless md
|
44
|
+
end
|
45
|
+
end
|
46
|
+
o.on('-a', '--auto-uuid') { @option[:uuid] = SecureRandom.uuid }
|
47
|
+
o.on('-u', '--uuid uuid') { |v| @option[:uuid] = v }
|
48
|
+
o.on('-n', '--stack-names name1,name2') { |v| @option[:stack_names] = v.split(/\s*,\s*/) }
|
49
|
+
o.on('--no-color') { |b| Rainbow.enabled = false }
|
50
|
+
o.on('-f', '--force') { |b| @option[:force] = true }
|
51
|
+
o.permute!(ARGV)
|
52
|
+
end
|
53
|
+
@logger = CFnDK::Logger.new(@option)
|
54
|
+
end
|
55
|
+
|
56
|
+
def execute
|
57
|
+
if ARGV.length != 1
|
58
|
+
puts @opt.help
|
59
|
+
return 2
|
60
|
+
elsif ARGV[0] == 'generate-uuid'
|
61
|
+
puts SecureRandom.uuid
|
62
|
+
return 0
|
63
|
+
elsif ARGV[0] == 'init'
|
64
|
+
if File.file?(@option[:config_path])
|
65
|
+
@logger.error "File exist. #{@option[:config_path]}".color(:red)
|
66
|
+
return 1
|
67
|
+
end
|
68
|
+
@logger.info 'init...'.color(:green)
|
69
|
+
FileUtils.cp_r(Dir.glob(File.dirname(__FILE__) + '/../skel/*'), './')
|
70
|
+
@logger.info "create #{@option[:config_path]}".color(:green)
|
71
|
+
return 0
|
72
|
+
end
|
73
|
+
|
74
|
+
unless File.file?(@option[:config_path])
|
75
|
+
@logger.error "File does not exist. #{@option[:config_path]}".color(:red)
|
76
|
+
return 1
|
77
|
+
end
|
78
|
+
|
79
|
+
data = open(@option[:config_path], 'r') { |f| YAML.load(f) } if File.file?(@option[:config_path])
|
80
|
+
credentials = CFnDK::CredentialProviderChain.new.resolve
|
81
|
+
stacks = CFnDK::Stacks.new(data, @option, credentials)
|
82
|
+
keypairs = CFnDK::KeyPairs.new(data, @option, credentials)
|
83
|
+
|
84
|
+
if ARGV[0] == 'create'
|
85
|
+
@logger.info 'create...'.color(:green)
|
86
|
+
stacks.validate
|
87
|
+
keypairs.create
|
88
|
+
stacks.create
|
89
|
+
elsif ARGV[0] == 'update'
|
90
|
+
@logger.info 'update...'.color(:green)
|
91
|
+
stacks.validate
|
92
|
+
stacks.update
|
93
|
+
elsif ARGV[0] == 'create-or-changeset'
|
94
|
+
@logger.info 'create or changeset...'.color(:green)
|
95
|
+
stacks.validate
|
96
|
+
stacks.create_or_changeset
|
97
|
+
elsif ARGV[0] == 'destroy'
|
98
|
+
@logger.info 'destroy...'.color(:green)
|
99
|
+
if destroy?
|
100
|
+
stacks.destroy
|
101
|
+
keypairs.destroy
|
102
|
+
end
|
103
|
+
elsif ARGV[0] == 'validate'
|
104
|
+
@logger.info 'validate...'.color(:green)
|
105
|
+
stacks.validate
|
106
|
+
elsif ARGV[0] == 'report-event'
|
107
|
+
@logger.info 'report event...'.color(:green)
|
108
|
+
stacks.report_event
|
109
|
+
elsif ARGV[0] == 'report-stack'
|
110
|
+
@logger.info 'report stack...'.color(:green)
|
111
|
+
stacks.report_stack
|
112
|
+
elsif ARGV[0] == 'report-stack-resource'
|
113
|
+
@logger.info 'report stack resource...'.color(:green)
|
114
|
+
stacks.report_stack_resource
|
115
|
+
else
|
116
|
+
puts @opt.help
|
117
|
+
return 2
|
118
|
+
end
|
119
|
+
0
|
120
|
+
end
|
121
|
+
|
122
|
+
def destroy?
|
123
|
+
return true if @option[:force]
|
124
|
+
loop do
|
125
|
+
print 'destroy? [yes|no]:'
|
126
|
+
res = STDIN.gets
|
127
|
+
case res
|
128
|
+
when /^yes/
|
129
|
+
return true
|
130
|
+
when /^no/, /^$/
|
131
|
+
return false
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
data/lib/cfndk/stack.rb
CHANGED
@@ -167,7 +167,7 @@ module CFnDK
|
|
167
167
|
item.stack_name,
|
168
168
|
item.creation_time,
|
169
169
|
item.deletion_time,
|
170
|
-
|
170
|
+
colored_status(item.stack_status),
|
171
171
|
item.stack_status_reason]
|
172
172
|
end
|
173
173
|
table = Terminal::Table.new headings: %w(Name Creation Deletion Status Reason), rows: rows
|
@@ -188,7 +188,7 @@ module CFnDK
|
|
188
188
|
[
|
189
189
|
item.resource_type,
|
190
190
|
item.timestamp,
|
191
|
-
|
191
|
+
colored_status(item.resource_status),
|
192
192
|
item.resource_status_reason]
|
193
193
|
end
|
194
194
|
table = Terminal::Table.new headings: %w(Type Time Status Reason), rows: rows
|
@@ -211,7 +211,7 @@ module CFnDK
|
|
211
211
|
item.physical_resource_id,
|
212
212
|
item.resource_type,
|
213
213
|
item.timestamp,
|
214
|
-
|
214
|
+
colored_status(item.resource_status),
|
215
215
|
item.resource_status_reason,
|
216
216
|
item.description,
|
217
217
|
]
|
@@ -244,20 +244,20 @@ module CFnDK
|
|
244
244
|
|
245
245
|
private
|
246
246
|
|
247
|
-
def
|
247
|
+
def colored_status(str)
|
248
248
|
case str
|
249
249
|
when 'CREATE_FAILED' then
|
250
|
-
|
250
|
+
str.color :red
|
251
251
|
when 'ROLLBACK_IN_PROGRESS' then
|
252
|
-
|
252
|
+
str.color :red
|
253
253
|
when 'ROLLBACK_COMPLETE' then
|
254
|
-
|
254
|
+
str.color :red
|
255
255
|
when 'CREATE_COMPLETE' then
|
256
|
-
|
256
|
+
str.color :green
|
257
257
|
when 'DELETE_COMPLETE' then
|
258
|
-
|
258
|
+
str.color :gray
|
259
259
|
else
|
260
|
-
|
260
|
+
str.color :orange
|
261
261
|
end
|
262
262
|
end
|
263
263
|
|
data/lib/cfndk/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfndk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshihisa AMAKATA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.0.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.0.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: aws-sdk
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- bin/cfndk
|
112
112
|
- cfndk.gemspec
|
113
113
|
- lib/cfndk.rb
|
114
|
+
- lib/cfndk/command.rb
|
114
115
|
- lib/cfndk/credential_provider_chain.rb
|
115
116
|
- lib/cfndk/erb_string.rb
|
116
117
|
- lib/cfndk/key_pair.rb
|