seiton 0.0.6 → 0.1.1

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: ea0570c0626f45cd54f5032682a7407e453ceb4dd58106fed42fa93486a19235
4
- data.tar.gz: 788a3308edcde668f7ce959fce1e05e285c30547bfbb571d8fd245f6a360acca
3
+ metadata.gz: 68c2eabf63161a231cb8de12a3836e3dbc0e66e73410978fe0f08600c4f916dd
4
+ data.tar.gz: 38e22caf6a46b10b8e5a133015da577b7c619801a8609f7a22ba7f8cdbbd042b
5
5
  SHA512:
6
- metadata.gz: 80a0343730dd939401076e414035489c8af8fb4de4473d039765b9eac00d62b76a3d07e8955ed9a524bfabacb9b87f204fa3a7e1cacb28e5a4fc8cb4fa12a020
7
- data.tar.gz: 91eca85684d31116681727a197ef6617468665edd87122b5f39e4ab9fcbca81aea4ce3e3b5c7d93309327e566f461d5da708d7970bda05e03fd3b6dcf2f08b56
6
+ metadata.gz: b99b0b5a3abe2d580c487c854a4d773f4e4dfa0ca19e01f484d36741a9b79df626dcee82ff17b3847dbee953cc52c8f9ea90e09cf52a2f3f3750e93dd320aa3f
7
+ data.tar.gz: 0d156ec83984ad4e0786824beeec9d7ebd5d6e6f56ec9d638af3ee09b6400a327ee3ceba4b4d626ae701a0175efd80c3e3e44d6390617582a325576a4f6caf98
@@ -0,0 +1,33 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ # specify the version you desire here
6
+ - image: cimg/ruby:2.6.5
7
+ working_directory: ~/repo
8
+ steps:
9
+ - checkout
10
+ - restore_cache:
11
+ keys:
12
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
13
+ # fallback to using the latest cache if no exact match is found
14
+ - v1-dependencies-
15
+ - run:
16
+ name: install dependencies
17
+ command: |
18
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
19
+ - save_cache:
20
+ paths:
21
+ - ./vendor/bundle
22
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
23
+ # run tests!
24
+ - run:
25
+ name: run tests
26
+ command: |
27
+ bundle exec rake spec
28
+ # collect reports
29
+ - store_test_results:
30
+ path: /tmp/test-results
31
+ - store_artifacts:
32
+ path: /tmp/test-results
33
+ destination: test-results
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # seiton
1
+ # seiton [![CircleCI](https://circleci.com/gh/oreno-tools/seiton.svg?style=svg)](https://circleci.com/gh/oreno-tools/seiton)
2
2
 
3
3
  The seiton (整頓) tidies up your AWS Resources.
4
4
 
@@ -8,7 +8,6 @@ Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
10
  gem 'seiton'
11
- gem 'rake' # require
12
11
  ```
13
12
 
14
13
  And then execute:
@@ -31,7 +30,7 @@ $ gem install seiton
31
30
  $ bundle exec seiton --help
32
31
  Commands:
33
32
  seiton ami # Delete the EC2 AMI.
34
- seiton ec2_snapshot # Delete the EC2 Snapshot.
33
+ seiton ebs_snapshot # Delete the EC2 Snapshot.
35
34
  seiton eip # Delete the Elastic IP.
36
35
  seiton help [COMMAND] # Describe available commands or one specific command
37
36
  seiton init # Initialize seiton.
@@ -39,6 +38,12 @@ Commands:
39
38
  seiton rds_snapshot # Delete the RDS Snapshot.
40
39
  seiton sqs_queue # Delete the SQS Queue.
41
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.
42
47
  ```
43
48
 
44
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
 
@@ -17,8 +17,7 @@ end
17
17
  <%- end -%>
18
18
  <% end %>
19
19
  EOF
20
- FileUtils.mkdir_p("check") unless FileTest.exist?("check")
21
- File.open("check/" + "ec2_instance_spec.rb", "w") do |file|
20
+ File.open("spec/" + "ec2_instance_spec.rb", "w") do |file|
22
21
  file.puts "require 'spec_helper'"
23
22
  file.puts ERB.new(template, nil, "-").result(binding).gsub(/^\n/, "")
24
23
  end
@@ -32,8 +31,7 @@ describe ebs("<%= resource.volume_id %>") do
32
31
  end
33
32
  <% end %>
34
33
  EOF
35
- FileUtils.mkdir_p("check") unless FileTest.exist?("check")
36
- File.open("check/" + "ec2_volumes_spec.rb", "w") do |file|
34
+ File.open("spec/" + "ec2_volumes_spec.rb", "w") do |file|
37
35
  file.puts "require 'spec_helper'"
38
36
  file.puts ERB.new(template, nil, "-").result(binding).gsub(/^\n/, "")
39
37
  end
@@ -56,21 +54,19 @@ end
56
54
  <%- end -%>
57
55
  <% end %>
58
56
  EOF
59
- FileUtils.mkdir_p("check") unless FileTest.exist?("check")
60
- File.open("check/" + "ec2_images_spec.rb", "w") do |file|
57
+ File.open("spec/" + "ec2_images_spec.rb", "w") do |file|
61
58
  file.puts "require 'spec_helper'"
62
59
  file.puts ERB.new(template, nil, "-").result(binding).gsub(/^\n/, "")
63
60
  end
64
61
  end
65
62
 
66
- def generator_ec2_snapshots_check(delete_resources)
63
+ def generator_ebs_snapshots_check(delete_resources)
67
64
  template = <<-'EOF'
68
65
  <% delete_resources.each do |resource| %>
69
66
  <%= resource.snapshot_id %>
70
67
  <% end %>
71
68
  EOF
72
- FileUtils.mkdir_p("check") unless FileTest.exist?("check")
73
- File.open("check/" + "ec2_snapshots_list.txt", "w") do |file|
69
+ File.open("spec/" + "ebs_snapshots_list.txt", "w") do |file|
74
70
  file.puts ERB.new(template, nil, "-").result(binding).gsub(/^\n/, "")
75
71
  end
76
72
  end
@@ -92,8 +88,7 @@ end
92
88
  <%- end -%>
93
89
  <% end %>
94
90
  EOF
95
- FileUtils.mkdir_p("check") unless FileTest.exist?("check")
96
- File.open("check/" + "ec2_eips_spec.rb", "w") do |file|
91
+ File.open("spec/" + "ec2_eips_spec.rb", "w") do |file|
97
92
  file.puts "require 'spec_helper'"
98
93
  file.puts ERB.new(template, nil, "-").result(binding).gsub(/^\n/, "")
99
94
  end
@@ -11,8 +11,7 @@ ignore|<%= resouce.db_cluster_snapshot_identifier %>
11
11
  <%- end -%>
12
12
  <% end %>
13
13
  EOF
14
- FileUtils.mkdir_p("check") unless FileTest.exist?("check")
15
- File.open("check/" + "db_snapshots_list.txt", "w") do |file|
14
+ File.open("spec/" + "db_snapshots_list.txt", "w") do |file|
16
15
  file.puts ERB.new(template, nil, "-").result(binding).gsub(/^\n/, "")
17
16
  end
18
17
  end
@@ -17,8 +17,7 @@ end
17
17
  <%- end -%>
18
18
  <% end %>
19
19
  EOF
20
- FileUtils.mkdir_p("check") unless FileTest.exist?("check")
21
- File.open("check/" + "sqs_queue_spec.rb", "w") do |file|
20
+ File.open("spec/" + "sqs_queue_spec.rb", "w") do |file|
22
21
  file.puts "require 'spec_helper'"
23
22
  file.puts ERB.new(template, nil, "-").result(binding).gsub(/^\n/, "")
24
23
  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
@@ -6,7 +6,7 @@ module Seiton
6
6
  end
7
7
 
8
8
  def generate
9
- ignores = nil
9
+ ignores = []
10
10
  begin
11
11
  File.open(@file) do |file|
12
12
  file.read.split("\n").each do |ignore|
@@ -7,14 +7,14 @@ module Seiton
7
7
  end
8
8
 
9
9
  def self.create_directory
10
- puts 'Create check directory...'
11
- FileUtils.mkdir_p('check') unless FileTest.exist?('check')
10
+ puts 'Create spec directory...'
11
+ FileUtils.mkdir_p('spec') unless FileTest.exist?('spec')
12
12
  spec_helper = <<~SPEC_HELPER
13
13
  require 'awspec'
14
14
  Awsecrets.load(secrets_path: File.expand_path('./secrets.yml', File.dirname(__FILE__)))
15
15
  SPEC_HELPER
16
16
 
17
- File.open('check/spec_helper.rb', 'w') do |f|
17
+ File.open('spec/spec_helper.rb', 'w') do |f|
18
18
  f.puts(spec_helper)
19
19
  end
20
20
  end
@@ -30,7 +30,7 @@ require 'logger'
30
30
  namespace :check do
31
31
  targets1 = []
32
32
  targets2 = []
33
- Dir.glob(['./spec/*', './check/*']).each do |file|
33
+ Dir.glob(['./spec/*']).each do |file|
34
34
  target = File.basename(file)
35
35
  if target.include?('_spec.rb') then
36
36
  targets1 << File.basename(target, '_spec.rb')
@@ -44,7 +44,7 @@ namespace :check do
44
44
 
45
45
  RSpec::Core::RakeTask.new(target.to_sym) do |t|
46
46
  # t.rspec_opts = ["--format documentation", "--format html", "--out ./result_html/\#{target}_result.html"]
47
- t.rspec_opts = ["--format documentation", "--format html", "--out ./result_html/\#{target}_result.html"]
47
+ t.rspec_opts = ["--format documentation"]
48
48
  t.pattern = "spec/\#{target}_spec.rb"
49
49
  t.verbose = true
50
50
  end if target != 'ec2_snapshot'
@@ -55,7 +55,7 @@ namespace :check do
55
55
  task target.to_sym do
56
56
  log.info('Check that ' + target + ' has been deleted.')
57
57
  resouces = []
58
- File.open('./check/' + target + '_list.txt', "r") do |f|
58
+ File.open('./spec/' + target + '_list.txt', "r") do |f|
59
59
  f.each_line do |line|
60
60
  resouces << line.chomp
61
61
  end
@@ -1,3 +1,3 @@
1
1
  module Seiton
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_development_dependency "bundler", "~> 2.1.4"
24
- spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_dependency "rake"
25
25
  spec.add_dependency 'thor'
26
26
  spec.add_dependency 'aws-sdk'
27
27
  spec.add_dependency 'terminal-table'
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seiton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
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
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.4
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.4
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
33
+ version: '0'
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: thor
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -116,6 +116,7 @@ executables:
116
116
  extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
+ - ".circleci/config.yml"
119
120
  - ".gitignore"
120
121
  - Gemfile
121
122
  - README.md
@@ -124,18 +125,18 @@ files:
124
125
  - bin/setup
125
126
  - exe/seiton
126
127
  - lib/seiton.rb
128
+ - lib/seiton/checks/ec2.rb
129
+ - lib/seiton/checks/rds.rb
130
+ - lib/seiton/checks/sqs.rb
127
131
  - lib/seiton/cli.rb
128
132
  - lib/seiton/client.rb
129
133
  - lib/seiton/common.rb
130
134
  - lib/seiton/ec2.rb
131
- - lib/seiton/ec2_check.rb
132
135
  - lib/seiton/ext.rb
133
136
  - lib/seiton/ignores.rb
134
137
  - lib/seiton/init.rb
135
138
  - lib/seiton/rds.rb
136
- - lib/seiton/rds_check.rb
137
139
  - lib/seiton/sqs.rb
138
- - lib/seiton/sqs_check.rb
139
140
  - lib/seiton/version.rb
140
141
  - seiton.gemspec
141
142
  homepage: https://github.com/oreno-tools/seiton