aws_log_cleaner 0.1.5 → 0.1.6

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
  SHA1:
3
- metadata.gz: d9e2389006bc57357e377983859742cbc22cf614
4
- data.tar.gz: b16f3d00ad984644d75e1d2f5ce7feacfd6b9812
3
+ metadata.gz: 930d1449b8c7ba7ec0ec21761574836bf9ea3154
4
+ data.tar.gz: 79fe79bff4d046ebee699b745c0c94d46f899814
5
5
  SHA512:
6
- metadata.gz: 4fd78ad333f4748349f7d2bfaf532b9a1fcce5dec84bc77a4202e0aa700b5c28b3b6a5072cb8ecd9e551742017ff92da9ab39c6d7b7243b34b85450cc83352f1
7
- data.tar.gz: bd455736d9d2629f4faf02dce2fbf271675bcffd55957803709532990ea2c61277984848d21ca4be19041d26b35057e631119be98281fe812f928db8bb60afc8
6
+ metadata.gz: 76ea2614ada694c445e8aa976fc7daa9ddfc6a06267f19e3021d23abd3de801ce5eafffc63d8bd311a442b9342e889e75a1f0ae38ee6eb0d06e254361f2e787b
7
+ data.tar.gz: e458dbc7b89fe8dfdf02e70bb4b4e25399e3c76f2763d9aa43606599d238a4bc55a9522f79b62c1d1b9e81e0b0b6790cc87a86fe15fadc68c0fa58a2db7094b1
data/.travis.yml CHANGED
@@ -1,11 +1,12 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.1.6
5
- before_install: gem install bundler -v 1.14.6
4
+ - 2.1.6
5
+ before_install:
6
+ - gem install bundler -v 1.14.6
6
7
  os:
7
- - linux
8
- - osx
8
+ - linux
9
+ - osx
9
10
  deploy:
10
11
  provider: rubygems
11
12
  api_key:
data/bin/aws_log_cleaner CHANGED
@@ -9,13 +9,14 @@ USAGE = <<ENDUSAGE.freeze
9
9
  ENDUSAGE
10
10
 
11
11
  HELP = <<ENDHELP.freeze
12
- -h, --help Show this help.
13
- -p, --plan Runs the plan command.
14
- -a, --apply Applys the deletion. Preview what will be deleted with [-p]
15
- -l, --like The search term returned logs should contain.
16
- -r, --region The region to run in.
17
- -k, --access_key The access key to use for AWS.
18
- -s, --secret The secret to use for AWS.
12
+ -h, --help Show this help.
13
+ -p, --plan Runs the plan command.
14
+ -a, --apply Applys the deletion. Preview what will be deleted with [-p]
15
+ -l, --like The search term returned logs should contain.
16
+ -r, --region The region to run in.
17
+ -k, --access_key The access key to use for AWS.
18
+ -s, --secret The secret to use for AWS.
19
+ -P, --profile The profile to use for AWS Credentials.
19
20
  ENDHELP
20
21
 
21
22
  args = { region: nil, access_key: nil, secret: nil }
@@ -30,6 +31,7 @@ ARGV.each do |arg|
30
31
  when '-r', '--region' then next_arg = :region
31
32
  when '-k', '--access_key' then next_arg = :access_key
32
33
  when '-s', '--secret' then next_arg = :secret
34
+ when '-P', '--profile' then next_arg = :profile
33
35
  else
34
36
  if next_arg
35
37
  args[next_arg] = arg
@@ -47,8 +49,24 @@ end
47
49
 
48
50
  like = args[:like].nil? ? '' : args[:like].downcase
49
51
 
52
+ credentials_args =
53
+ if args[:access_key] && args[:secret]
54
+ {
55
+ access_key: args[:access_key],
56
+ secret: args[:secret]
57
+ }
58
+ elsif args[:profile]
59
+ {
60
+ profile: args[:profile]
61
+ }
62
+ else
63
+ nil
64
+ end
65
+
66
+ credentials_args[:region] = args[:region] unless args[:region].nil?
67
+
50
68
  log_cleaner = \
51
- AwsLogCleaner::AwsLogCleaner.new(args[:access_key], args[:secret], args[:region])
69
+ AwsLogCleaner::AwsLogCleaner.new(credentials_args)
52
70
 
53
71
  if args[:plan]
54
72
  puts "== PLAN MODE ==\n\n"
@@ -9,17 +9,60 @@ module AwsLogCleaner
9
9
 
10
10
  attr_reader :credentials, :region
11
11
 
12
- def initialize(access_key = nil, secret = nil, region = nil)
13
- key_id = access_key || ENV['AWS_ACCESS_KEY_ID']
14
- secret = secret || ENV['AWS_SECRET_ACCESS_KEY']
15
- @region = region || ENV['AWS_DEFAULT_REGION']
12
+ def initialize(credential_args = nil)
13
+ key_id, secret, profile, region = parse_credential_arguments(credential_args)
16
14
 
15
+ set_credentials(key_id, secret, profile, region)
16
+
17
+ return @credentials
18
+ end
19
+
20
+ private
21
+
22
+ def raise_credentials_error
23
+ raise "Could not load credentials."
24
+ end
25
+
26
+ def parse_credential_arguments(credential_args)
27
+ if credential_args.nil?
28
+ key_id = ENV['AWS_ACCESS_KEY_ID']
29
+ secret = ENV['AWS_SECRET_ACCESS_KEY']
30
+ region = ENV['AWS_REGION']
31
+ else
32
+ if credential_args[:profile] \
33
+ && (credential_args[:access_key] || credential_args[:secret] )
34
+ raise 'Cannot pass a profile and a secret'
35
+ end
36
+
37
+ if credential_args[:profile]
38
+ profile = credential_args[:profile]
39
+ else
40
+ key_id = credential_args[:access_key]
41
+ secret = credential_args[:secret]
42
+ end
43
+ region = credential_args[:region] || ENV['AWS_DEFAULT_REGION']
44
+ end
45
+ return key_id, secret, profile, region
46
+ end
47
+
48
+ def set_credentials(key_id, secret, profile, region)
49
+ @region = region
17
50
  @credentials =
18
51
  if key_id.nil? && secret.nil?
19
- Aws::SharedCredentials.new
52
+ begin
53
+ profile.nil? ? Aws::SharedCredentials.new : Aws::SharedCredentials.new(profile_name: profile)
54
+ rescue Aws::Errors::NoSuchProfileError
55
+ raise_credentials_error
56
+ end
20
57
  else
21
58
  Aws::Credentials.new(key_id, secret)
22
59
  end
60
+
61
+ if (@credentials.credentials.nil? || @region.nil?) \
62
+ || @credentials.credentials.set? == false
63
+ raise_credentials_error
64
+ end
23
65
  end
66
+
24
67
  end
25
68
  end
@@ -1,3 +1,3 @@
1
1
  module AwsLogCleaner
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
@@ -12,8 +12,8 @@ module AwsLogCleaner
12
12
  # Application wrapper
13
13
  class AwsLogCleaner
14
14
 
15
- def initialize(access_key = nil, secret = nil, region = nil)
16
- credentials = AwsCredentials.new(access_key, secret, region)
15
+ def initialize(credentials_args)
16
+ credentials = AwsCredentials.new(credentials_args)
17
17
  cloud_watch_logs = CloudWatchLogs.new(credentials)
18
18
  api_gateway = ApiGateway.new(credentials)
19
19
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws_log_cleaner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - dbaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-11 00:00:00.000000000 Z
11
+ date: 2017-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler