yle-aws-role 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/yle/aws/role.rb +5 -5
- data/lib/yle/aws/role/cli.rb +36 -21
- data/lib/yle/aws/role/config.rb +2 -0
- data/lib/yle/aws/role/version.rb +1 -1
- metadata +6 -16
- data/.gitignore +0 -9
- data/.rspec +0 -1
- data/.travis.yml +0 -7
- data/CHANGELOG.md +0 -8
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -21
- data/README.md +0 -72
- data/Rakefile +0 -6
- data/yle-aws-role.gemspec +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c8b0f1070a9587c8e21af9afbdc5fe81b0f93d4015c1c3abc37835df1ea0c9e1
|
4
|
+
data.tar.gz: fd04107ea86be718b2c1859fd526d93a3326bc7c0cafd24f990eed4dd77ea4e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0c4ad64c3b2b79f4eb791f570ff293e003bcb6f654cc3348d6733f9bdac915905f9bf1b7bd1856e82c73af65cae4dcde998655d05ea4a9adbb6f8ebda95b0db
|
7
|
+
data.tar.gz: 491d7a7c1c44b4d228c31b6262487dfdb138865c3741811e25cf931c0a4a10df780c28ac559429987148d9c7155678e0cfc4417922c0f4a655e8905e9d711648
|
data/lib/yle/aws/role.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'aws-sdk'
|
1
|
+
require 'aws-sdk-core'
|
2
2
|
require 'shellwords'
|
3
3
|
|
4
4
|
require 'yle/aws/role/accounts'
|
@@ -54,12 +54,12 @@ module Yle
|
|
54
54
|
duration_seconds: duration
|
55
55
|
).credentials
|
56
56
|
rescue Aws::STS::Errors::ServiceError,
|
57
|
-
|
57
|
+
Aws::Errors::MissingCredentialsError => e
|
58
58
|
raise Errors::AssumeRoleError, "Failed to assume role #{role_arn}: #{e}"
|
59
59
|
end
|
60
60
|
|
61
61
|
def with_env
|
62
|
-
old_env =
|
62
|
+
old_env = export_env_vars(env_vars)
|
63
63
|
old_credentials = Aws.config[:credentials]
|
64
64
|
Aws.config.update(credentials: credentials)
|
65
65
|
|
@@ -70,7 +70,7 @@ module Yle
|
|
70
70
|
else
|
71
71
|
Aws.config.delete(:credentials)
|
72
72
|
end
|
73
|
-
|
73
|
+
export_env_vars(old_env)
|
74
74
|
end
|
75
75
|
|
76
76
|
def env_vars
|
@@ -82,7 +82,7 @@ module Yle
|
|
82
82
|
}
|
83
83
|
end
|
84
84
|
|
85
|
-
def
|
85
|
+
def export_env_vars(vars)
|
86
86
|
old_env = {}
|
87
87
|
vars.each do |key, value|
|
88
88
|
old_env[key] = ENV[key]
|
data/lib/yle/aws/role/cli.rb
CHANGED
@@ -6,21 +6,24 @@ module Yle
|
|
6
6
|
module AWS
|
7
7
|
class Role
|
8
8
|
class Cli
|
9
|
-
attr_reader :account_name, :
|
9
|
+
attr_reader :account_name, :opts
|
10
10
|
|
11
11
|
def initialize(argv)
|
12
12
|
parse_args(argv)
|
13
13
|
end
|
14
14
|
|
15
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
15
16
|
def parse_args(argv)
|
16
17
|
@opts = Slop.parse(argv) do |o|
|
17
18
|
o.banner = 'Usage: asu <account> [options] -- [command ...]'
|
18
19
|
o.separator ' or: asu --list'
|
19
20
|
o.separator ''
|
20
21
|
o.separator ' account The account ID or pattern of the role account'
|
21
|
-
o.separator ' command Command to execute with the role.
|
22
|
+
o.separator ' command Command to execute with the role. ' \
|
23
|
+
'Defaults to launching new shell session.'
|
22
24
|
o.separator ''
|
23
|
-
o.integer '-d', '--duration',
|
25
|
+
o.integer '-d', '--duration', 'Duration for the role credentials. ' \
|
26
|
+
"Default: #{Role.default_duration}"
|
24
27
|
o.bool '--env', 'Print out environment variables and exit'
|
25
28
|
o.bool '-l', '--list', 'Print out all configured account aliases'
|
26
29
|
o.bool '-q', '--quiet', 'Be quiet'
|
@@ -52,14 +55,13 @@ module Yle
|
|
52
55
|
STDERR.puts e
|
53
56
|
exit 64
|
54
57
|
end
|
58
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
55
59
|
|
60
|
+
# rubocop:disable Metrics/AbcSize
|
56
61
|
def execute
|
57
|
-
if opts[:list]
|
58
|
-
puts Role.accounts
|
59
|
-
return
|
60
|
-
end
|
62
|
+
return list_accounts if opts[:list]
|
61
63
|
|
62
|
-
|
64
|
+
assume_role(account_name, opts[:role], opts[:duration]) do |role|
|
63
65
|
STDERR.puts("Assumed role #{role.name}") if !opts[:quiet]
|
64
66
|
|
65
67
|
if opts[:env]
|
@@ -68,27 +70,40 @@ module Yle
|
|
68
70
|
run_command
|
69
71
|
end
|
70
72
|
end
|
73
|
+
end
|
74
|
+
# rubocop:enable Metrics/AbcSize
|
75
|
+
|
76
|
+
def list_accounts
|
77
|
+
puts Role.accounts
|
78
|
+
end
|
79
|
+
|
80
|
+
def assume_role(account_name, role_name, duration, &block)
|
81
|
+
Role.assume_role(account_name, role_name, duration, &block)
|
71
82
|
rescue Errors::AssumeRoleError => e
|
72
83
|
STDERR.puts e
|
73
84
|
exit 1
|
74
85
|
end
|
75
86
|
|
76
87
|
def run_command
|
77
|
-
|
78
|
-
if
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
88
|
+
ret = system(*command)
|
89
|
+
STDERR.puts "Failed to execute '#{command.first}'" if ret.nil?
|
90
|
+
exit(1) if !ret
|
91
|
+
end
|
92
|
+
|
93
|
+
def command
|
94
|
+
@command ||= [shell]
|
95
|
+
end
|
96
|
+
|
97
|
+
def shell
|
98
|
+
shell = ENV.fetch('SHELL', 'bash')
|
99
|
+
|
100
|
+
if !opts[:quiet]
|
101
|
+
puts "Executing shell '#{shell}' with the assumed role"
|
102
|
+
puts 'Use `exit` to quit'
|
103
|
+
puts
|
87
104
|
end
|
88
105
|
|
89
|
-
|
90
|
-
STDERR.puts "Failed to execute '#{cmd.first}'" if ret.nil?
|
91
|
-
exit(1) if !ret
|
106
|
+
[shell]
|
92
107
|
end
|
93
108
|
end
|
94
109
|
end
|
data/lib/yle/aws/role/config.rb
CHANGED
@@ -3,6 +3,7 @@ require 'yaml'
|
|
3
3
|
module Yle
|
4
4
|
module AWS
|
5
5
|
class Role
|
6
|
+
# rubocop:disable Metrics/BlockLength
|
6
7
|
Config = Struct.new(:accounts, :defaults) do
|
7
8
|
def self.default_path
|
8
9
|
ENV.fetch('ASU_CONFIG') { File.join(Dir.home, '.aws', 'asu.yaml') }
|
@@ -38,6 +39,7 @@ module Yle
|
|
38
39
|
)
|
39
40
|
end
|
40
41
|
end
|
42
|
+
# rubocop:enable Metrics/BlockLength
|
41
43
|
end
|
42
44
|
end
|
43
45
|
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:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yleisradio
|
@@ -10,22 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2018-01-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name: aws-sdk
|
16
|
+
name: aws-sdk-core
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
21
|
+
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: '
|
28
|
+
version: '3.0'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: slop
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,15 +92,6 @@ executables:
|
|
92
92
|
extensions: []
|
93
93
|
extra_rdoc_files: []
|
94
94
|
files:
|
95
|
-
- ".gitignore"
|
96
|
-
- ".rspec"
|
97
|
-
- ".travis.yml"
|
98
|
-
- CHANGELOG.md
|
99
|
-
- CODE_OF_CONDUCT.md
|
100
|
-
- Gemfile
|
101
|
-
- LICENSE.txt
|
102
|
-
- README.md
|
103
|
-
- Rakefile
|
104
95
|
- bin/asu
|
105
96
|
- lib/yle-aws-role.rb
|
106
97
|
- lib/yle/aws/role.rb
|
@@ -109,7 +100,6 @@ files:
|
|
109
100
|
- lib/yle/aws/role/config.rb
|
110
101
|
- lib/yle/aws/role/errors.rb
|
111
102
|
- lib/yle/aws/role/version.rb
|
112
|
-
- yle-aws-role.gemspec
|
113
103
|
homepage: https://github.com/Yleisradio/yle-aws-role
|
114
104
|
licenses:
|
115
105
|
- MIT
|
@@ -130,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
120
|
version: '0'
|
131
121
|
requirements: []
|
132
122
|
rubyforge_project:
|
133
|
-
rubygems_version: 2.
|
123
|
+
rubygems_version: 2.7.3
|
134
124
|
signing_key:
|
135
125
|
specification_version: 4
|
136
126
|
summary: Tooling to help to assume AWS IAM roles
|
data/.gitignore
DELETED
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|
data/.travis.yml
DELETED
data/CHANGELOG.md
DELETED
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at teemu.matilainen@iki.fi. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: http://contributor-covenant.org
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2016-2017 Yleisradio Oy
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
# yle-aws-role
|
2
|
-
|
3
|
-
Tooling to help to assume [AWS IAM roles](http://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html).
|
4
|
-
|
5
|
-
Offers a command-line helper tool, `asu`, and a Ruby library. After assuming the specified role, it sets the standard environment variables and configures the Ruby SDK for the role.
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
The project can be installed in a shell:
|
10
|
-
|
11
|
-
```sh
|
12
|
-
gem install yle-aws-role
|
13
|
-
```
|
14
|
-
|
15
|
-
To use the Ruby library, add this line to your application's Gemfile:
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
gem 'yle-aws-role'
|
19
|
-
```
|
20
|
-
|
21
|
-
and then execute `bundle`
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
```plain
|
26
|
-
Usage: asu <account> [options] -- [command ...]
|
27
|
-
or: asu --list
|
28
|
-
|
29
|
-
account The account ID or pattern of the role account
|
30
|
-
command Command to execute with the role. Defaults to launching new shell session.
|
31
|
-
|
32
|
-
-d, --duration Duration for the role credentials. Default: 900
|
33
|
-
--env Print out environment variables and exit
|
34
|
-
-l, --list Print out all configured account aliases
|
35
|
-
-q, --quiet Be quiet
|
36
|
-
-r, --role Name of the role
|
37
|
-
|
38
|
-
-h, --help Prints this help
|
39
|
-
-v, --version Prints the version information
|
40
|
-
```
|
41
|
-
|
42
|
-
### Configuration
|
43
|
-
|
44
|
-
Account aliases and their IDs can be specified in a configuration file. Then you can list the known accounts with `asu --list`, and use aliases (even with partial matching) when specifying the account for `asu`. Also the default role can be set.
|
45
|
-
|
46
|
-
The configuration file location defaults to _$HOME/.aws/asu.yaml_, but can be specified with the `ASU_CONFIG` environment variable.
|
47
|
-
|
48
|
-
Example configuration:
|
49
|
-
|
50
|
-
```yaml
|
51
|
-
defaults:
|
52
|
-
role: "dev"
|
53
|
-
|
54
|
-
accounts:
|
55
|
-
foo-bar: "123456789012"
|
56
|
-
baz: "987654321098"
|
57
|
-
```
|
58
|
-
|
59
|
-
With this you can just call for example
|
60
|
-
|
61
|
-
```sh
|
62
|
-
asu foo -- aws s3 ls s3://mybucket/
|
63
|
-
```
|
64
|
-
|
65
|
-
## Contributing
|
66
|
-
|
67
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/Yleisradio/yle-aws-role. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
68
|
-
|
69
|
-
|
70
|
-
## License
|
71
|
-
|
72
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
DELETED
data/yle-aws-role.gemspec
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'yle/aws/role/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = 'yle-aws-role'
|
8
|
-
spec.version = Yle::AWS::Role::VERSION
|
9
|
-
spec.summary = 'Tooling to help to assume AWS IAM roles'
|
10
|
-
spec.description = spec.summary
|
11
|
-
spec.homepage = 'https://github.com/Yleisradio/yle-aws-role'
|
12
|
-
spec.license = 'MIT'
|
13
|
-
|
14
|
-
spec.authors = [
|
15
|
-
'Yleisradio',
|
16
|
-
'Teemu Matilainen',
|
17
|
-
'Antti Forsell',
|
18
|
-
]
|
19
|
-
spec.email = [
|
20
|
-
'devops@yle.fi',
|
21
|
-
'teemu.matilainen@iki.fi',
|
22
|
-
'antti@fosu.me',
|
23
|
-
]
|
24
|
-
|
25
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
-
f.match(%r{^(test|spec|features)/})
|
27
|
-
end
|
28
|
-
|
29
|
-
spec.bindir = 'bin'
|
30
|
-
spec.executables = ['asu']
|
31
|
-
spec.require_paths = ['lib']
|
32
|
-
|
33
|
-
spec.add_dependency 'aws-sdk', '~> 2.6'
|
34
|
-
spec.add_dependency 'slop', '~> 4.4'
|
35
|
-
|
36
|
-
spec.add_development_dependency 'bundler', '~> 1.13'
|
37
|
-
spec.add_development_dependency 'rake', '~> 12.0'
|
38
|
-
spec.add_development_dependency 'rspec', '~> 3.5'
|
39
|
-
end
|