yle-aws-role 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yle/aws/role/cli.rb +46 -33
- data/lib/yle/aws/role/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 487ba074255efe194b3ce4a0c111cccb7131ce92f2cae0e04820d255aa22a1c2
|
4
|
+
data.tar.gz: 6e58f555b729400c092e8a47e25a1b584deb291ad988ab591471c1f402827e1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06f11aed7628aa9dbdd25853bb6eb25515763e1158edb7a67af63f27e71b5b8adaddc0ffc24ffa6c0258b22ae742b18578a1dfd5d43b92bdefe5fa4c6300cfde
|
7
|
+
data.tar.gz: 60103da98186ed41858ad14171e9bf2bbc2e4009f682f2ad8332ba7e5f06d6c1c67c3321d8a7e3567ed1191ca9b2a638d8608d40859846f9671dcdac496e5583
|
data/lib/yle/aws/role/cli.rb
CHANGED
@@ -10,6 +10,7 @@ module Yle
|
|
10
10
|
|
11
11
|
def initialize(argv)
|
12
12
|
parse_args(argv)
|
13
|
+
verify_args
|
13
14
|
end
|
14
15
|
|
15
16
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
@@ -39,63 +40,71 @@ module Yle
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
|
-
@account_name = opts.args.shift
|
43
|
-
@command = opts.args
|
44
|
-
|
45
|
-
if !@opts[:list]
|
46
|
-
if !@account_name
|
47
|
-
STDERR.puts @opts
|
48
|
-
exit 64
|
49
|
-
elsif !(@opts[:role] || Role.default_role_name)
|
50
|
-
STDERR.puts 'Role name must be passed with `--role` or set in the config'
|
51
|
-
exit 64
|
52
|
-
end
|
53
|
-
end
|
43
|
+
@account_name = @opts.args.shift
|
44
|
+
@command = @opts.args
|
54
45
|
rescue Slop::Error => e
|
55
46
|
STDERR.puts e
|
56
47
|
exit 64
|
57
48
|
end
|
58
49
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
59
50
|
|
60
|
-
|
61
|
-
|
62
|
-
return list_accounts if opts[:list]
|
51
|
+
def verify_args
|
52
|
+
return if opts[:list]
|
63
53
|
|
64
|
-
|
65
|
-
STDERR.puts
|
54
|
+
if !account_name
|
55
|
+
STDERR.puts opts
|
56
|
+
exit 64
|
57
|
+
end
|
66
58
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
59
|
+
if !(opts[:role] || Role.default_role_name)
|
60
|
+
STDERR.puts 'Role name must be passed with `--role` or set in the config'
|
61
|
+
exit 64
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def execute
|
66
|
+
if opts[:list]
|
67
|
+
list_accounts
|
68
|
+
elsif opts[:env]
|
69
|
+
print_env_vars
|
70
|
+
else
|
71
|
+
run_command
|
72
72
|
end
|
73
73
|
end
|
74
|
-
# rubocop:enable Metrics/AbcSize
|
75
74
|
|
76
75
|
def list_accounts
|
77
76
|
puts Role.accounts
|
78
77
|
end
|
79
78
|
|
80
|
-
def
|
81
|
-
|
82
|
-
rescue Errors::AssumeRoleError => e
|
83
|
-
STDERR.puts e
|
84
|
-
exit 1
|
79
|
+
def print_env_vars
|
80
|
+
assume_role(&:print_env_vars)
|
85
81
|
end
|
86
82
|
|
87
83
|
def run_command
|
88
|
-
|
89
|
-
|
90
|
-
|
84
|
+
assume_role do
|
85
|
+
ret = system(*command)
|
86
|
+
STDERR.puts "Failed to execute '#{command.first}'" if ret.nil?
|
87
|
+
exit(1) if !ret
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def assume_role
|
92
|
+
Role.assume_role(account_name, opts[:role], opts[:duration]) do |role|
|
93
|
+
STDERR.puts("Assumed role #{role.name}") if !opts[:quiet]
|
94
|
+
yield role
|
95
|
+
end
|
96
|
+
rescue Errors::AssumeRoleError => e
|
97
|
+
STDERR.puts e
|
98
|
+
exit 1
|
91
99
|
end
|
92
100
|
|
93
101
|
def command
|
94
|
-
@command
|
102
|
+
@command = shell if @command.empty?
|
103
|
+
@command
|
95
104
|
end
|
96
105
|
|
97
106
|
def shell
|
98
|
-
shell =
|
107
|
+
shell = default_shell
|
99
108
|
|
100
109
|
if !opts[:quiet]
|
101
110
|
puts "Executing shell '#{shell}' with the assumed role"
|
@@ -105,6 +114,10 @@ module Yle
|
|
105
114
|
|
106
115
|
[shell]
|
107
116
|
end
|
117
|
+
|
118
|
+
def default_shell
|
119
|
+
ENV.fetch('SHELL', 'bash')
|
120
|
+
end
|
108
121
|
end
|
109
122
|
end
|
110
123
|
end
|
data/lib/yle/aws/role/version.rb
CHANGED
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: 2.0.
|
4
|
+
version: 2.0.1
|
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: 2018-
|
13
|
+
date: 2018-02-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: aws-sdk-core
|