sumomo 0.10.0 → 0.10.2

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
  SHA256:
3
- metadata.gz: 346a647def575daedb5dc3e3eba04a73024c441be3ae92740cf9edb668992e44
4
- data.tar.gz: 379cbf589f7ace6b8da717054ab71754604ed6b863808aadf3b6996a18df292f
3
+ metadata.gz: 7438e8125e7b38488797c60d301417efc9ffba234848ae101e25df6bd663d23c
4
+ data.tar.gz: 2d0fa2741b9e03230d72a56e9b29dffeedf685792423606b2ec10cbe0743822c
5
5
  SHA512:
6
- metadata.gz: a0cd59b9b12bf2ec4e1b968f37962c505e9c9e6b7e47ed8846ad7af3737c162f5947bd4e01bfa1cdddfd4d347c378803db10c25ceadf56c5d7d31e0cecbe6b26
7
- data.tar.gz: ed8757d5ca20a22791c1ded35a453ffd00f51260e6f5a96fb38adc9cc55df4617d30dbfa4a83bad353d2758bdc1232f51183e1bdbf09591c6142f6e92d98ff84
6
+ metadata.gz: 70f9ffcc5462638f922f862c7388c0347a649a2d384824438e05e7e2f4ae388c3ce521221a16b4935e80bcaaa0d1f29039eecc4ae6df77ae7468065acb1d7c51
7
+ data.tar.gz: 346d98d824627a7dd7c66a766faffa38996663945f0a8488d7465fa87f4458b42f5d081e2b9be49f73ea093de7e77be2f414536e704c531aca8bb6b3777c0203
data/exe/sumomo CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'trollop'
4
+ require 'optimist'
5
5
  require 'sumomo'
6
6
  require 'yaml'
7
7
 
8
8
  SUB_COMMANDS = %w[delete create update outputs show diff testapi].freeze
9
- global_opts = Trollop.options do
9
+ global_opts = Optimist.options do
10
10
  banner <<-USAGE
11
11
  Sumomo v#{Sumomo::VERSION}
12
12
 
@@ -26,49 +26,67 @@ p ENV['AWS_PROFILE']
26
26
 
27
27
  cmd = ARGV.shift # get the subcommand
28
28
 
29
- cmd_opts = case cmd
30
- when 'delete'
31
- Sumomo.delete_stack(name: ARGV[0], region: global_opts[:region])
32
-
33
- when 'create', 'update', 'show', 'diff'
34
- local_opts = Trollop.options do
35
- opt :filename, 'File that describes the stack', type: :string, default: 'Sumomofile'
36
- opt :changeset, 'Create a changeset instead of directly update', type: :boolean, default: false
37
- end
38
- Sumomo.manage_stack(name: ARGV[0], cmd: cmd, changeset: !!local_opts[:changeset], region: global_opts[:region]) do
39
- proc = proc {}
40
- eval File.read(local_opts[:filename]), proc.binding, local_opts[:filename]
41
- end
42
-
43
- when 'outputs'
44
- puts "Outputs for stack #{ARGV[0]}"
45
- puts Sumomo.get_stack_outputs(name: ARGV[0], region: global_opts[:region]).to_yaml
46
-
47
- when 'login'
48
- puts "Login to stack #{ARGV[0]} instance at #{ARGV[1]}"
49
- `aws s3 cp s3://#{ARGV[0]}/cloudformation/#{ARGV[0]}_master_key.pem x.txt`
50
- key = JSON.parse(File.read('x.txt'))['value'].
51
- gsub('-----BEGIN RSA PRIVATE KEY----- ', "-----BEGIN RSA PRIVATE KEY-----\n").
52
- gsub(' -----END RSA PRIVATE KEY-----', "\n-----END RSA PRIVATE KEY-----").
53
- gsub(/(.{64}) /, "\\1\n")
54
- File.write('key.pem', key)
55
- `chmod 0600 key.pem`
56
- exec "ssh -i 'key.pem' ec2-user@#{ARGV[1]} #{ARGV[2]}"
57
-
58
- when 'testapi'
59
- local_opts = Trollop.options do
60
- opt :filename, 'File that describes the stack', type: :string, default: 'Sumomofile'
61
- opt :apiname, 'Name of the API you want to test', type: :string
62
- opt :prettyprint, 'Test API outputs JSON with nice indentation', type: :boolean, default: true
63
- end
64
- puts 'API Test Mode'
65
- Sumomo.test_api(local_opts[:apiname], local_opts[:prettyprint]) do
66
- proc = proc {}
67
- eval File.read(local_opts[:filename]), proc.binding, local_opts[:filename]
68
- end
69
- exit(0)
70
- else
71
- Trollop.die "Unknown subcommand #{cmd.inspect}"
29
+ case cmd
30
+ when 'delete'
31
+ Sumomo.delete_stack(name: ARGV[0], region: global_opts[:region])
32
+
33
+ when 'rollback'
34
+ Sumomo.rollback_stack(name: ARGV[0], region: global_opts[:region])
35
+
36
+ when 'create', 'update', 'show', 'diff'
37
+ local_opts = Optimist.options do
38
+ opt :filename, 'File that describes the stack', type: :string, default: 'Sumomofile'
39
+ opt :changeset, 'Create a changeset instead of directly update', type: :boolean, default: false
40
+ opt :rollback, 'Specify whether or not to rollback. Allowed values are [enable, disable]', type: :string, default: 'unspecified'
41
+ end
42
+
43
+ changeset = !!local_opts[:changeset]
44
+ rollback = local_opts[:rollback].to_sym
45
+
46
+ if rollback == :disable && local_opts[:changeset] == false
47
+ Optimist.die "Rollback cannot be set to disable when changeset is set to false, because we will end up in an update-failed state"
48
+ end
49
+
50
+ Sumomo.manage_stack(
51
+ name: ARGV[0],
52
+ cmd: cmd,
53
+ changeset: changeset,
54
+ region: global_opts[:region],
55
+ rollback: rollback) do
56
+
57
+ proc = proc {}
58
+ eval File.read(local_opts[:filename]), proc.binding, local_opts[:filename]
59
+ end
60
+
61
+ when 'outputs'
62
+ puts "Outputs for stack #{ARGV[0]}"
63
+ puts Sumomo.get_stack_outputs(name: ARGV[0], region: global_opts[:region]).to_yaml
64
+
65
+ when 'login'
66
+ puts "Login to stack #{ARGV[0]} instance at #{ARGV[1]}"
67
+ `aws s3 cp s3://#{ARGV[0]}/cloudformation/#{ARGV[0]}_master_key.pem x.txt`
68
+ key = JSON.parse(File.read('x.txt'))['value'].
69
+ gsub('-----BEGIN RSA PRIVATE KEY----- ', "-----BEGIN RSA PRIVATE KEY-----\n").
70
+ gsub(' -----END RSA PRIVATE KEY-----', "\n-----END RSA PRIVATE KEY-----").
71
+ gsub(/(.{64}) /, "\\1\n")
72
+ File.write('key.pem', key)
73
+ `chmod 0600 key.pem`
74
+ exec "ssh -i 'key.pem' ec2-user@#{ARGV[1]} #{ARGV[2]}"
75
+
76
+ when 'testapi'
77
+ local_opts = Optimist.options do
78
+ opt :filename, 'File that describes the stack', type: :string, default: 'Sumomofile'
79
+ opt :apiname, 'Name of the API you want to test', type: :string
80
+ opt :prettyprint, 'Test API outputs JSON with nice indentation', type: :boolean, default: true
81
+ end
82
+ puts 'API Test Mode'
83
+ Sumomo.test_api(local_opts[:apiname], local_opts[:prettyprint]) do
84
+ proc = proc {}
85
+ eval File.read(local_opts[:filename]), proc.binding, local_opts[:filename]
86
+ end
87
+ exit(0)
88
+ else
89
+ Optimist.die "Unknown subcommand #{cmd.inspect}"
72
90
  end
73
91
 
74
92
  unless %w[show diff].include?(cmd)
data/lib/sumomo/stack.rb CHANGED
@@ -203,7 +203,7 @@ module Sumomo
203
203
  statements: [
204
204
  {
205
205
  'Effect' => 'Allow',
206
- 'Action' => ['logs:CreateLogStream', 'logs:PutLogEvents'],
206
+ 'Action' => ['logs:CreateLogGroup', 'logs:CreateLogStream', 'logs:PutLogEvents'],
207
207
  'Resource' => 'arn:aws:logs:*:*:*'
208
208
  },
209
209
  {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sumomo
4
- VERSION = '0.10.0'
4
+ VERSION = '0.10.2'
5
5
  end
data/lib/sumomo.rb CHANGED
@@ -26,7 +26,14 @@ module Sumomo
26
26
  "cloudformation/#{make_master_key_name(name: name)}.pem"
27
27
  end
28
28
 
29
- def self.manage_stack(name:, region:, cmd:'update', sns_arn: nil, changeset: false, &block)
29
+ def self.manage_stack(
30
+ name:,
31
+ region:,
32
+ cmd:'update',
33
+ sns_arn: nil,
34
+ rollback: :unspecified,
35
+ changeset: false, &block)
36
+
30
37
  cf = Aws::CloudFormation::Client.new(region: region)
31
38
  s3 = Aws::S3::Client.new(region: region)
32
39
  ec2 = Aws::EC2::Client.new(region: region)
@@ -35,6 +42,8 @@ module Sumomo
35
42
  s3.head_bucket(bucket: name)
36
43
  rescue Aws::S3::Errors::NotFound => e
37
44
  s3.create_bucket(bucket: name)
45
+ rescue => e
46
+ exit 1
38
47
  end
39
48
 
40
49
  store = S3Cabinet::S3Cabinet.new(nil, nil, name, region)
@@ -167,8 +176,6 @@ module Sumomo
167
176
  capabilities: ['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM']
168
177
  }
169
178
 
170
- update_options[:disable_rollback] = false if !changeset
171
-
172
179
  begin
173
180
  if changeset
174
181
  cf.create_change_set(
@@ -176,7 +183,10 @@ module Sumomo
176
183
  change_set_name: "Change#{curtimestr}"
177
184
  )
178
185
  else
179
- cf.update_stack(update_options)
186
+ cf.update_stack({
187
+ disable_rollback: rollback == :disable,
188
+ **update_options
189
+ })
180
190
  end
181
191
 
182
192
  rescue StandardError => e
@@ -185,7 +195,7 @@ module Sumomo
185
195
  update_options[:notification_arns] = sns_arn if sns_arn
186
196
  cf.create_stack(update_options)
187
197
  else
188
- p e
198
+ p update_options
189
199
  puts "Error: #{e.message}"
190
200
  end
191
201
  end
@@ -448,6 +458,12 @@ module Sumomo
448
458
  end
449
459
  end
450
460
 
461
+ def self.rollback_stack(name:, region:)
462
+ cf = Aws::CloudFormation::Client.new(region: region)
463
+
464
+ cf.rollback_stack(stack_name: name)
465
+ end
466
+
451
467
  def self.get_stack_outputs(name:, region:)
452
468
  cf = Aws::CloudFormation::Client.new(region: region)
453
469
 
data/sumomo.gemspec CHANGED
@@ -38,6 +38,6 @@ Gem::Specification.new do |spec|
38
38
  spec.add_dependency 'momo', '0.4.1'
39
39
  spec.add_dependency 'rubyzip'
40
40
  spec.add_dependency 's3cabinet'
41
- spec.add_dependency 'trollop'
41
+ spec.add_dependency 'optimist'
42
42
  spec.add_dependency 'webrick'
43
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sumomo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Siaw
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-08 00:00:00.000000000 Z
11
+ date: 2023-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -151,7 +151,7 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: trollop
154
+ name: optimist
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
@@ -2593,7 +2593,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
2593
2593
  - !ruby/object:Gem::Version
2594
2594
  version: '0'
2595
2595
  requirements: []
2596
- rubygems_version: 3.1.2
2596
+ rubygems_version: 3.2.33
2597
2597
  signing_key:
2598
2598
  specification_version: 4
2599
2599
  summary: An advanced infrastructure description language for AWS