seiton 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 5b1ae9a2d6899c5b2b5017f9cef164d078472d35491c6adf80aae8fb78792ca3
4
- data.tar.gz: 56fbc87ba41e92a0f4995fda8a6637e653d65f207b21909da6c5a6648af3e9d9
3
+ metadata.gz: 68c2eabf63161a231cb8de12a3836e3dbc0e66e73410978fe0f08600c4f916dd
4
+ data.tar.gz: 38e22caf6a46b10b8e5a133015da577b7c619801a8609f7a22ba7f8cdbbd042b
5
5
  SHA512:
6
- metadata.gz: a06cb2f21b274762fa470f2157adb23df042aeea89ad5ff041129d23b69f3c27035d03a9383f39dd59c174c547c3345c8d415fe794deab0a81fd73987f3d6a38
7
- data.tar.gz: b51d138e4141d4ff0c94d814a4afcab6d98ab3a9d3cd908b4adfd1b94219d64af67e6a208fa890972d0fd2e38c825d1e4ffadce364e1c2daf25d2f519e6f903a
6
+ metadata.gz: b99b0b5a3abe2d580c487c854a4d773f4e4dfa0ca19e01f484d36741a9b79df626dcee82ff17b3847dbee953cc52c8f9ea90e09cf52a2f3f3750e93dd320aa3f
7
+ data.tar.gz: 0d156ec83984ad4e0786824beeec9d7ebd5d6e6f56ec9d638af3ee09b6400a327ee3ceba4b4d626ae701a0175efd80c3e3e44d6390617582a325576a4f6caf98
data/README.md CHANGED
@@ -30,7 +30,7 @@ $ gem install seiton
30
30
  $ bundle exec seiton --help
31
31
  Commands:
32
32
  seiton ami # Delete the EC2 AMI.
33
- seiton ec2_snapshot # Delete the EC2 Snapshot.
33
+ seiton ebs_snapshot # Delete the EC2 Snapshot.
34
34
  seiton eip # Delete the Elastic IP.
35
35
  seiton help [COMMAND] # Describe available commands or one specific command
36
36
  seiton init # Initialize seiton.
@@ -38,6 +38,12 @@ Commands:
38
38
  seiton rds_snapshot # Delete the RDS Snapshot.
39
39
  seiton sqs_queue # Delete the SQS Queue.
40
40
  seiton version # Print the version number.
41
+
42
+ Options:
43
+ -b, [--before-datetime=BEFORE_DATETIME] # Specify the date and time for deletion (delete resources before the specified date and time.)
44
+ -i, [--ignores=one two three] # Specify resources to be undeleted (you can specify multiple resources).
45
+ [--ignores-file=IGNORES_FILE] # Specify file name for resources list to be undeleted.
46
+ -c, [--check], [--no-check] # Check the resources to be deleted.
41
47
  ```
42
48
 
43
49
  ### Init
@@ -2,12 +2,12 @@ require 'seiton/cli'
2
2
  require 'seiton/client'
3
3
  require 'seiton/common'
4
4
  require 'seiton/ext'
5
- require 'seiton/ec2_check'
5
+ require 'seiton/checks/ec2'
6
6
  require 'seiton/ec2'
7
7
  require 'seiton/ignores'
8
- require 'seiton/rds_check'
8
+ require 'seiton/checks/rds'
9
9
  require 'seiton/rds'
10
- require 'seiton/sqs_check'
10
+ require 'seiton/checks/sqs'
11
11
  require 'seiton/sqs'
12
12
  require 'seiton/version'
13
13
 
@@ -60,13 +60,13 @@ EOF
60
60
  end
61
61
  end
62
62
 
63
- def generator_ec2_snapshots_check(delete_resources)
63
+ def generator_ebs_snapshots_check(delete_resources)
64
64
  template = <<-'EOF'
65
65
  <% delete_resources.each do |resource| %>
66
66
  <%= resource.snapshot_id %>
67
67
  <% end %>
68
68
  EOF
69
- File.open("spec/" + "ec2_snapshots_list.txt", "w") do |file|
69
+ File.open("spec/" + "ebs_snapshots_list.txt", "w") do |file|
70
70
  file.puts ERB.new(template, nil, "-").result(binding).gsub(/^\n/, "")
71
71
  end
72
72
  end
@@ -10,6 +10,10 @@ require 'erb'
10
10
  module Seiton
11
11
  class CLI < Thor
12
12
  default_command :version
13
+ class_option :before_datetime, type: :string, aliases: '-b', desc: 'Specify the date and time for deletion (delete resources before the specified date and time.)'
14
+ class_option :ignores, type: :array, aliases: '-i', desc: 'Specify resources to be undeleted (you can specify multiple resources).'
15
+ class_option :ignores_file, type: :string, aliases: nil, desc: 'Specify file name for resources list to be undeleted.'
16
+ class_option :check, type: :boolean, aliases: '-c', desc: 'Check the resources to be deleted.'
13
17
 
14
18
  desc 'version', 'Print the version number.'
15
19
  def version
@@ -23,10 +27,6 @@ module Seiton
23
27
  end
24
28
 
25
29
  desc 'ami', 'Delete the EC2 AMI.'
26
- option :before_datetime, type: :string, aliases: '-b', desc: 'Specify the date and time for deletion (delete resources before the specified date and time.)'
27
- option :ignores, type: :array, aliases: '-i', desc: 'Specify resources to be undeleted (you can specify multiple resources).'
28
- option :ignores_file, type: :string, aliases: nil, desc: 'Specify file name for resources list to be undeleted.'
29
- option :check, type: :boolean, aliases: '-c', desc: 'Check the resources to be deleted.'
30
30
  def ami
31
31
  unless options[:before_datetime] then
32
32
  puts '--before-datetime must be specified. (--before-datetime=YYYY/MM/DD)'
@@ -38,12 +38,8 @@ module Seiton
38
38
  seiton.ec2_image(options[:check], options[:before_datetime], ignores)
39
39
  end
40
40
 
41
- desc 'ec2_snapshot', 'Delete the EC2 Snapshot.'
42
- option :before_datetime, type: :string, aliases: '-b', desc: 'Specify the date and time for deletion (delete resources before the specified date and time.)'
43
- option :ignores, type: :array, aliases: '-i', desc: 'Specify resources to be undeleted (you can specify multiple resources).'
44
- option :ignores_file, type: :string, aliases: nil, desc: 'Specify file name for resources list to be undeleted.'
45
- option :check, type: :boolean, aliases: '-c', desc: 'Check the resources to be deleted.'
46
- def ec2_snapshot
41
+ desc 'ebs_snapshot', 'Delete the EC2 Snapshot.'
42
+ def ebs_snapshot
47
43
  unless options[:before_datetime] then
48
44
  puts '--before-datetime must be specified. (--before-datetime=YYYY/MM/DD)'
49
45
  exit 1
@@ -51,15 +47,11 @@ module Seiton
51
47
 
52
48
  ignores = Seiton::Ignores.new(options[:ignores_file], options[:ignores]).generate
53
49
  seiton = Seiton::Ec2.new
54
- seiton.ec2_snapshots(options[:check],
50
+ seiton.ebs_snapshots(options[:check],
55
51
  options[:before_datetime], ignores)
56
52
  end
57
53
 
58
54
  desc 'instance', 'Delete the EC2 Instance.'
59
- option :before_datetime, type: :string, aliases: '-b', desc: 'Specify the date and time for deletion (delete resources before the specified date and time.)'
60
- option :ignores, type: :array, aliases: '-i', desc: 'Specify resources to be undeleted (you can specify multiple resources).'
61
- option :ignores_file, type: :string, aliases: nil, desc: 'Specify file name for resources list to be undeleted.'
62
- option :check, type: :boolean, aliases: '-c', desc: 'Check the resources to be deleted.'
63
55
  def instance
64
56
  unless options[:before_datetime] then
65
57
  puts '--before-datetime must be specified. (--before-datetime=YYYY/MM/DD)'
@@ -72,10 +64,6 @@ module Seiton
72
64
  end
73
65
 
74
66
  desc 'rds_snapshot', 'Delete the RDS Snapshot.'
75
- option :before_datetime, type: :string, aliases: '-b', desc: 'Specify the date and time for deletion (delete resources before the specified date and time.)'
76
- option :ignores, type: :array, aliases: '-i', desc: 'Specify resources to be undeleted (you can specify multiple resources).'
77
- option :ignores_file, type: :string, aliases: nil, desc: 'Specify file name for resources list to be undeleted.'
78
- option :check, type: :boolean, aliases: '-c', desc: 'Check the resources to be deleted.'
79
67
  def rds_snapshot
80
68
  unless options[:before_datetime] then
81
69
  puts '--before-datetime must be specified. (--before-datetime=YYYY/MM/DD)'
@@ -88,9 +76,6 @@ module Seiton
88
76
  end
89
77
 
90
78
  desc 'eip', 'Delete the Elastic IP.'
91
- option :ignores, type: :array, aliases: '-i', desc: 'Specify resources to be undeleted (you can specify multiple resources).'
92
- option :ignores_file, type: :string, aliases: nil, desc: 'Specify file name for resources list to be undeleted.'
93
- option :check, type: :boolean, aliases: '-c', desc: 'Check the resources to be deleted.'
94
79
  def eip
95
80
  ignores = Seiton::Ignores.new(options[:ignores_file], options[:ignores]).generate
96
81
  seiton = Seiton::Ec2.new
@@ -98,9 +83,6 @@ module Seiton
98
83
  end
99
84
 
100
85
  desc 'sqs_queue', 'Delete the SQS Queue.'
101
- option :ignores, type: :array, aliases: '-i', desc: 'Specify resources to be undeleted (you can specify multiple resources).'
102
- option :ignores_file, type: :string, aliases: nil, desc: 'Specify file name for resources list to be undeleted.'
103
- option :check, type: :boolean, aliases: '-c', desc: 'Check the resources to be deleted.'
104
86
  def sqs_queue
105
87
  ignores = Seiton::Ignores.new(options[:ignores_file], options[:ignores]).generate
106
88
  seiton = Seiton::Sqs.new
@@ -38,25 +38,5 @@ module Seiton
38
38
  end
39
39
  volume_ids
40
40
  end
41
-
42
- def ignores(ignores_file, ignore_list)
43
- ignores = nil
44
- begin
45
- File.open(ignores_file) do |file|
46
- file.read.split("\n").each do |ignore|
47
- ignores << ignore
48
- end
49
- end
50
- rescue SystemCallError => e
51
- puts e.message
52
- exit 1
53
- rescue IOError => e
54
- puts e.message
55
- exit 1
56
- end unless ignore_file.nil?
57
- ignores.concat(ignore_list) unless ignore_list.nil?
58
-
59
- ignores
60
- end
61
41
  end
62
42
  end
@@ -156,10 +156,10 @@ module Seiton
156
156
  exit 0
157
157
  end
158
158
 
159
- ec2_snapshot(delete_image_ids)
159
+ ebs_snapshot(delete_image_ids)
160
160
  end
161
161
 
162
- def ec2_snapshots(check = false, dt, ignores)
162
+ def ebs_snapshots(check = false, dt, ignores)
163
163
  if check
164
164
  log.info('List up the resources to be removed.')
165
165
  else
@@ -202,7 +202,7 @@ module Seiton
202
202
  end
203
203
 
204
204
  puts display_snapshot_resources(delete_snapshots)
205
- generator_ec2_snapshots_check(delete_snapshots)
205
+ generator_ebs_snapshots_check(delete_snapshots)
206
206
  exit 0 if check
207
207
 
208
208
  delete_snapshot_ids = []
@@ -219,10 +219,10 @@ module Seiton
219
219
  exit 0
220
220
  end
221
221
 
222
- ec2_snapshot(delete_image_ids)
222
+ ebs_snapshot(delete_image_ids)
223
223
  end
224
224
 
225
- def ec2_snapshot(delete_image_ids)
225
+ def ebs_snapshot(delete_image_ids)
226
226
  log.info('Start EC2 Snapshot deleting.')
227
227
  res = ec2_client.describe_snapshots(owner_ids: [iam_user.arn.split(':')[4]])
228
228
  delete_snapshots = []
@@ -238,7 +238,7 @@ module Seiton
238
238
  end
239
239
 
240
240
  puts display_snapshot_resources(delete_snapshots)
241
- generator_ec2_snapshots_check(delete_snapshots)
241
+ generator_ebs_snapshots_check(delete_snapshots)
242
242
 
243
243
  if process_ok?
244
244
  begin
@@ -1,3 +1,3 @@
1
1
  module Seiton
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seiton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - inokappa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-15 00:00:00.000000000 Z
11
+ date: 2020-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -125,18 +125,18 @@ files:
125
125
  - bin/setup
126
126
  - exe/seiton
127
127
  - lib/seiton.rb
128
+ - lib/seiton/checks/ec2.rb
129
+ - lib/seiton/checks/rds.rb
130
+ - lib/seiton/checks/sqs.rb
128
131
  - lib/seiton/cli.rb
129
132
  - lib/seiton/client.rb
130
133
  - lib/seiton/common.rb
131
134
  - lib/seiton/ec2.rb
132
- - lib/seiton/ec2_check.rb
133
135
  - lib/seiton/ext.rb
134
136
  - lib/seiton/ignores.rb
135
137
  - lib/seiton/init.rb
136
138
  - lib/seiton/rds.rb
137
- - lib/seiton/rds_check.rb
138
139
  - lib/seiton/sqs.rb
139
- - lib/seiton/sqs_check.rb
140
140
  - lib/seiton/version.rb
141
141
  - seiton.gemspec
142
142
  homepage: https://github.com/oreno-tools/seiton