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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/yle-aws-role.rb +1 -0
- data/lib/yle/aws/role.rb +15 -4
- data/lib/yle/aws/role/cli.rb +11 -19
- data/lib/yle/aws/role/version.rb +1 -1
- data/yle-aws-role.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0336e6ed9e03daa76c15b4659a1e6283bb2943b
|
4
|
+
data.tar.gz: 8884cd5b0f1d602d2f14445cd1f83cafed9e07c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a90525adf5e57867a8faba1d12bcda886c06940946e8b8bac2e901a383a27d78eef1d67c8cd3d91dcbab0d1eec22442bd68e8a94bbb5bd1292e312bac77087c
|
7
|
+
data.tar.gz: 26eb0863413abe01edb45f28113631eb347f8d3c7d9f9c591cbfbd0af7bc8ee01d9801f8c15e6c1c21af979e03255b1e0544a26bee07a6fc730bc5ae8c40bbc8
|
data/CHANGELOG.md
CHANGED
data/lib/yle-aws-role.rb
ADDED
@@ -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
|
54
|
+
duration_seconds: duration
|
44
55
|
).credentials
|
45
56
|
rescue Aws::STS::Errors::ServiceError,
|
46
57
|
Aws::Errors::MissingCredentialsError => e
|
data/lib/yle/aws/role/cli.rb
CHANGED
@@ -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
|
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',
|
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 !@
|
43
|
-
|
44
|
-
|
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
|
-
|
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
|
data/lib/yle/aws/role/version.rb
CHANGED
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', '~>
|
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
|
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-
|
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: '
|
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: '
|
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
|