yle-aws-role 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8b0f1070a9587c8e21af9afbdc5fe81b0f93d4015c1c3abc37835df1ea0c9e1
4
- data.tar.gz: fd04107ea86be718b2c1859fd526d93a3326bc7c0cafd24f990eed4dd77ea4e3
3
+ metadata.gz: 487ba074255efe194b3ce4a0c111cccb7131ce92f2cae0e04820d255aa22a1c2
4
+ data.tar.gz: 6e58f555b729400c092e8a47e25a1b584deb291ad988ab591471c1f402827e1b
5
5
  SHA512:
6
- metadata.gz: b0c4ad64c3b2b79f4eb791f570ff293e003bcb6f654cc3348d6733f9bdac915905f9bf1b7bd1856e82c73af65cae4dcde998655d05ea4a9adbb6f8ebda95b0db
7
- data.tar.gz: 491d7a7c1c44b4d228c31b6262487dfdb138865c3741811e25cf931c0a4a10df780c28ac559429987148d9c7155678e0cfc4417922c0f4a655e8905e9d711648
6
+ metadata.gz: 06f11aed7628aa9dbdd25853bb6eb25515763e1158edb7a67af63f27e71b5b8adaddc0ffc24ffa6c0258b22ae742b18578a1dfd5d43b92bdefe5fa4c6300cfde
7
+ data.tar.gz: 60103da98186ed41858ad14171e9bf2bbc2e4009f682f2ad8332ba7e5f06d6c1c67c3321d8a7e3567ed1191ca9b2a638d8608d40859846f9671dcdac496e5583
@@ -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
- # rubocop:disable Metrics/AbcSize
61
- def execute
62
- return list_accounts if opts[:list]
51
+ def verify_args
52
+ return if opts[:list]
63
53
 
64
- assume_role(account_name, opts[:role], opts[:duration]) do |role|
65
- STDERR.puts("Assumed role #{role.name}") if !opts[:quiet]
54
+ if !account_name
55
+ STDERR.puts opts
56
+ exit 64
57
+ end
66
58
 
67
- if opts[:env]
68
- role.print_env_vars
69
- else
70
- run_command
71
- end
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 assume_role(account_name, role_name, duration, &block)
81
- Role.assume_role(account_name, role_name, duration, &block)
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
- ret = system(*command)
89
- STDERR.puts "Failed to execute '#{command.first}'" if ret.nil?
90
- exit(1) if !ret
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 ||= [shell]
102
+ @command = shell if @command.empty?
103
+ @command
95
104
  end
96
105
 
97
106
  def shell
98
- shell = ENV.fetch('SHELL', 'bash')
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
@@ -1,7 +1,7 @@
1
1
  module Yle
2
2
  module AWS
3
3
  class Role
4
- VERSION = '2.0.0'.freeze
4
+ VERSION = '2.0.1'.freeze
5
5
  end
6
6
  end
7
7
  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: 2.0.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-01-26 00:00:00.000000000 Z
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