yle-aws-role 1.0.1 → 1.1.0

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: 9f7b053ced151afced7e073a3b35b845c9063535
4
- data.tar.gz: c56becd6190bc4cc5d97547daa02257839a57319
3
+ metadata.gz: f0336e6ed9e03daa76c15b4659a1e6283bb2943b
4
+ data.tar.gz: 8884cd5b0f1d602d2f14445cd1f83cafed9e07c0
5
5
  SHA512:
6
- metadata.gz: 678d27720ced0e4d0aba60780cc8409367efea5477f93aeacaa45e98cb88cf09ebf0fd5651692d32a9ed93e151c158aaca3f8936181855908adb4cd5995e0a5d
7
- data.tar.gz: e980b5b1bec818f651045e98ad30241493fe67a5bef6108b158978057222cfcb71b4692c2f34fc11be48a3aeaec3fc83ff5dd5f601746a4d6f59dc8cf265bbec
6
+ metadata.gz: 0a90525adf5e57867a8faba1d12bcda886c06940946e8b8bac2e901a383a27d78eef1d67c8cd3d91dcbab0d1eec22442bd68e8a94bbb5bd1292e312bac77087c
7
+ data.tar.gz: 26eb0863413abe01edb45f28113631eb347f8d3c7d9f9c591cbfbd0af7bc8ee01d9801f8c15e6c1c21af979e03255b1e0544a26bee07a6fc730bc5ae8c40bbc8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.1.0 / 2017-05-23
2
+
3
+ - Support default role in the `Role` class
4
+ - Support `require 'yle-aws-role'`
5
+
1
6
  ## 1.0.1 / 2017-05-16
2
7
 
3
8
  - Initial public release
@@ -0,0 +1 @@
1
+ require 'yle/aws/role'
data/lib/yle/aws/role.rb CHANGED
@@ -12,7 +12,7 @@ module Yle
12
12
  # Default duration in seconds when assuming a role
13
13
  DEFAULT_DURATION = 900
14
14
 
15
- def self.assume_role(account_name, role_name, duration = nil)
15
+ def self.assume_role(account_name, role_name = nil, duration = nil)
16
16
  account_alias = accounts.find(account_name)
17
17
  if !account_alias
18
18
  raise Errors::AccountNotFoundError, "No account found for '#{account_name}'"
@@ -31,16 +31,27 @@ module Yle
31
31
  @accounts ||= Accounts.new(config['accounts'])
32
32
  end
33
33
 
34
+ def self.default_role_name
35
+ config['defaults']['role']
36
+ end
37
+
38
+ def self.default_duration
39
+ config['defaults']['duration'] || DEFAULT_DURATION
40
+ end
41
+
34
42
  attr_reader :account, :role_name, :credentials
35
43
 
36
- def initialize(account_alias, role_name, duration = nil)
44
+ def initialize(account_alias, role_name = nil, duration = nil)
37
45
  @account = account_alias
38
- @role_name = role_name
46
+ @role_name = role_name || Role.default_role_name
47
+ duration ||= Role.default_duration
48
+
49
+ raise Errors::AssumeRoleError, 'Role name not specified' if !@role_name
39
50
 
40
51
  @credentials = Aws::AssumeRoleCredentials.new(
41
52
  role_arn: role_arn,
42
53
  role_session_name: session_name,
43
- duration_seconds: duration || DEFAULT_DURATION
54
+ duration_seconds: duration
44
55
  ).credentials
45
56
  rescue Aws::STS::Errors::ServiceError,
46
57
  Aws::Errors::MissingCredentialsError => e
@@ -20,11 +20,11 @@ module Yle
20
20
  o.separator ' account The account ID or pattern of the role account'
21
21
  o.separator ' command Command to execute with the role. Defaults to launching new shell session.'
22
22
  o.separator ''
23
- o.integer '-d', '--duration', "Duration for the role credentials. Default: #{Role::DEFAULT_DURATION}"
23
+ o.integer '-d', '--duration', "Duration for the role credentials. Default: #{Role.default_duration}"
24
24
  o.bool '--env', 'Print out environment variables and exit'
25
25
  o.bool '-l', '--list', 'Print out all configured account aliases'
26
26
  o.bool '-q', '--quiet', 'Be quiet'
27
- o.string '-r', '--role', 'Name of the role'
27
+ o.string '-r', '--role', "Name of the role. Default: '#{Role.default_role_name}'"
28
28
  o.separator ''
29
29
  o.on '-h', '--help', 'Prints this help' do
30
30
  puts o
@@ -39,9 +39,14 @@ module Yle
39
39
  @account_name = opts.args.shift
40
40
  @command = opts.args
41
41
 
42
- if !@account_name && !@opts[:list]
43
- STDERR.puts @opts
44
- exit 64
42
+ if !@opts[:list]
43
+ if !@account_name
44
+ STDERR.puts @opts
45
+ exit 64
46
+ elsif !(@opts[:role] || Role.default_role_name)
47
+ STDERR.puts 'Role name must be passed with `--role` or set in the config'
48
+ exit 64
49
+ end
45
50
  end
46
51
  rescue Slop::Error => e
47
52
  STDERR.puts e
@@ -54,12 +59,7 @@ module Yle
54
59
  return
55
60
  end
56
61
 
57
- if !role_name
58
- STDERR.puts 'Role name must be passed with `--role` or set in the config'
59
- exit 64
60
- end
61
-
62
- Role.assume_role(account_name, role_name, duration) do |role|
62
+ Role.assume_role(account_name, opts[:role], opts[:duration]) do |role|
63
63
  STDERR.puts("Assumed role #{role.name}") if !opts[:quiet]
64
64
 
65
65
  if opts[:env]
@@ -90,14 +90,6 @@ module Yle
90
90
  STDERR.puts "Failed to execute '#{cmd.first}'" if ret.nil?
91
91
  exit(1) if !ret
92
92
  end
93
-
94
- def role_name
95
- opts[:role] || Role.config['defaults']['role']
96
- end
97
-
98
- def duration
99
- opts[:duration] || Role.config['defaults']['duration']
100
- end
101
93
  end
102
94
  end
103
95
  end
@@ -1,7 +1,7 @@
1
1
  module Yle
2
2
  module AWS
3
3
  class Role
4
- VERSION = '1.0.1'.freeze
4
+ VERSION = '1.1.0'.freeze
5
5
  end
6
6
  end
7
7
  end
data/yle-aws-role.gemspec CHANGED
@@ -34,6 +34,6 @@ Gem::Specification.new do |spec|
34
34
  spec.add_dependency 'slop', '~> 4.4'
35
35
 
36
36
  spec.add_development_dependency 'bundler', '~> 1.13'
37
- spec.add_development_dependency 'rake', '~> 11.0'
37
+ spec.add_development_dependency 'rake', '~> 12.0'
38
38
  spec.add_development_dependency 'rspec', '~> 3.5'
39
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yle-aws-role
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yleisradio
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-05-16 00:00:00.000000000 Z
13
+ date: 2017-05-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-sdk
@@ -60,14 +60,14 @@ dependencies:
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: '11.0'
63
+ version: '12.0'
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - "~>"
69
69
  - !ruby/object:Gem::Version
70
- version: '11.0'
70
+ version: '12.0'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rspec
73
73
  requirement: !ruby/object:Gem::Requirement
@@ -102,6 +102,7 @@ files:
102
102
  - README.md
103
103
  - Rakefile
104
104
  - bin/asu
105
+ - lib/yle-aws-role.rb
105
106
  - lib/yle/aws/role.rb
106
107
  - lib/yle/aws/role/accounts.rb
107
108
  - lib/yle/aws/role/cli.rb