aws_session_token 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,184 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # AWS Session Token Gem - Tool to wrap AWS API to create and store Session tokens
5
+ # so that other commands/tools (e.g. Terraform) can function as necessary
6
+ #
7
+ #
8
+ # Copyright 2018 Bryan Stopp <bryan.stopp@gmail.com>
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the "License");
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at
13
+ #
14
+ # http://www.apache.org/licenses/LICENSE-2.0
15
+ #
16
+ # Unless required by applicable law or agreed to in writing, software
17
+ # distributed under the License is distributed on an "AS IS" BASIS,
18
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ # See the License for the specific language governing permissions and
20
+ # limitations under the License.
21
+ #
22
+
23
+ require 'spec_helper'
24
+
25
+ describe AwsSessionToken::Options, :isolated_environment do
26
+
27
+ before do
28
+ $stdout = StringIO.new
29
+ $stderr = StringIO.new
30
+ end
31
+
32
+ after do
33
+ $stdout = STDOUT
34
+ $stderr = STDERR
35
+ end
36
+
37
+ subject(:options) { described_class.new }
38
+
39
+ let(:demo_creds) do
40
+ Aws::SharedCredentials.new
41
+ end
42
+
43
+ describe 'initialize' do
44
+ it 'should default credentials_file' do
45
+ expect(options.credentials_file).to eq(demo_creds.path)
46
+ end
47
+ it 'should default the profile name' do
48
+ expect(options.profile).to eq(demo_creds.profile_name)
49
+ end
50
+ it 'should default the session_profile name' do
51
+ expect(options.session_profile).to eq('session_profile')
52
+ end
53
+ it 'should default the duration' do
54
+ expect(options.duration).to eq(AwsSessionToken::Options::DURATION)
55
+ end
56
+ end
57
+
58
+ describe 'options' do
59
+ describe '-h/--help' do
60
+ it 'exits cleanly' do
61
+ expect { options.parse ['-h'] }.to exit_with_code(0)
62
+ expect { options.parse ['--help'] }.to exit_with_code(0)
63
+ end
64
+
65
+ it 'shows help text' do
66
+ begin
67
+ options.parse(['--help'])
68
+ rescue SystemExit # rubocop:disable Lint/HandleExceptions
69
+ end
70
+
71
+ expected = <<~HELP
72
+ Usage: aws_session_token [options]
73
+
74
+ -f, --file FILE Specify a custom credentials file.
75
+ -u, --user USER Specify the AWS User name for passing to API.
76
+ -p, --profile PROFILE Specify the AWS credentials profile to use. Also sets user, if user is not provided.
77
+ -s, --session SESSION_PROFILE Specify the name of the profile used to store the session credentials.
78
+ -d, --duration DURATION Specify the duration the of the token in seconds. (Default 3600)
79
+ -t, --token TOKEN Specify the OTP Token to use for creating the session credentials.
80
+
81
+ Common options:
82
+ -h, --help Show this message.
83
+ -v, --version Show version.
84
+ HELP
85
+ expect($stdout.string).to eq(expected)
86
+ end
87
+ end
88
+
89
+ describe '-v/--version' do
90
+ it 'exits cleanly' do
91
+ expect { options.parse(['-h']) }.to exit_with_code(0)
92
+ expect { options.parse(['--help']) }.to exit_with_code(0)
93
+ end
94
+ it 'shows version' do
95
+ begin
96
+ options.parse(['--version'])
97
+ rescue SystemExit # rubocop:disable Lint/HandleExceptions
98
+ end
99
+ expected = SemVer.find.format(+ '%M.%m.%p%s')
100
+ expect($stdout.string.chomp).to eq(expected)
101
+ end
102
+ end
103
+
104
+ describe '-f/--file' do
105
+ it 'fails if no argument' do
106
+ expect { options.parse(['-f']) }.to raise_error(OptionParser::MissingArgument)
107
+ expect { options.parse(['--file']) }.to raise_error(OptionParser::MissingArgument)
108
+ end
109
+ it 'succeeds with an argument' do
110
+ expect { options.parse(%w[-f /foo/bar]) }.to_not raise_error(OptionParser::MissingArgument)
111
+ expect { options.parse(%w[--file /foo/bar]) }.to_not raise_error(OptionParser::MissingArgument)
112
+ end
113
+ end
114
+
115
+ describe '-p/--profile' do
116
+ it 'fails if no argument' do
117
+ expect { options.parse(['-p']) }.to raise_error(OptionParser::MissingArgument)
118
+ expect { options.parse(['--profile']) }.to raise_error(OptionParser::MissingArgument)
119
+ end
120
+ it 'succeeds with an argument' do
121
+ expect { options.parse(%w[-p foo]) }.to_not raise_error(OptionParser::MissingArgument)
122
+ expect { options.parse(%w[--profile foo]) }.to_not raise_error(OptionParser::MissingArgument)
123
+ end
124
+ end
125
+
126
+ describe '-u/--user' do
127
+ it 'fails if no argument' do
128
+ expect { options.parse(['-u']) }.to raise_error(OptionParser::MissingArgument)
129
+ expect { options.parse(['--user']) }.to raise_error(OptionParser::MissingArgument)
130
+ end
131
+ it 'succeeds with an argument' do
132
+ expect { options.parse(%w[-u foo]) }.to_not raise_error(OptionParser::MissingArgument)
133
+ expect { options.parse(%w[--user foo]) }.to_not raise_error(OptionParser::MissingArgument)
134
+ end
135
+ end
136
+
137
+ describe '-s/--session' do
138
+ it 'fails if no argument' do
139
+ expect { options.parse(['-s']) }.to raise_error(OptionParser::MissingArgument)
140
+ expect { options.parse(['--session']) }.to raise_error(OptionParser::MissingArgument)
141
+ end
142
+ it 'succeeds with an argument' do
143
+ expect { options.parse(%w[-s bar]) }.to_not raise_error(OptionParser::MissingArgument)
144
+ expect { options.parse(%w[--session bar]) }.to_not raise_error(OptionParser::MissingArgument)
145
+ end
146
+ end
147
+
148
+ describe '-d/--duration' do
149
+ it 'fails if no argument' do
150
+ expect { options.parse(['-d']) }.to raise_error(OptionParser::MissingArgument)
151
+ expect { options.parse(['--duration']) }.to raise_error(OptionParser::MissingArgument)
152
+ end
153
+ it 'fails if argument is not an integer' do
154
+ expect { options.parse(%w[-d abc]) }.to raise_error(OptionParser::InvalidArgument)
155
+ expect { options.parse(%w[--duration abc]) }.to raise_error(OptionParser::InvalidArgument)
156
+ end
157
+ it 'succeeds if argument is an integer' do
158
+ expect { options.parse(%w[-d 1800]) }.to_not raise_error
159
+ expect { options.parse(%w[--duration 1800]) }.to_not raise_error
160
+ end
161
+ end
162
+
163
+ describe '-t/--token' do
164
+ it 'succeeds with optional argument' do
165
+ expect { options.parse(['-t']) }.to raise_error(OptionParser::MissingArgument)
166
+ expect { options.parse(['--token']) }.to raise_error(OptionParser::MissingArgument)
167
+ end
168
+ it 'succeeds with an argument' do
169
+ expect { options.parse(%w[-t 123456]) }.to_not raise_error
170
+ expect { options.parse(%w[--token 123456]) }.to_not raise_error
171
+ end
172
+ end
173
+
174
+ describe 'validate' do
175
+ it 'does not allow -p & -s' do
176
+ expect { options.parse(%w[-p default -s default]) }.to raise_error(ArgumentError)
177
+ end
178
+ it 'defaults profile attr to user if unspecified' do
179
+ options.parse(%w[-p foo])
180
+ expect(options.profile).to eq(options.user)
181
+ end
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,7 @@
1
+ --format
2
+ s
3
+ --colour
4
+ --loadby
5
+ mtime
6
+ --backtrace
7
+ --rdebugger
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # AWS Session Token Gem - Tool to wrap AWS API to create and store Session tokens
5
+ # so that other commands/tools (e.g. Terraform) can function as necessary.
6
+ #
7
+ # Copyright 2018 Bryan Stopp <bryan.stopp@gmail.com>
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ require 'simplecov'
23
+
24
+ module SimpleCov
25
+ module Configuration
26
+ def clean_filters
27
+ @filters = []
28
+ end
29
+ end
30
+ end
31
+
32
+ SimpleCov.configure do
33
+ clean_filters
34
+ load_profile 'test_frameworks'
35
+ load_profile 'bundler_filter'
36
+ end
37
+
38
+ ENV['COVERAGE'] && SimpleCov.start do
39
+ add_filter '/.rvm/'
40
+
41
+ end
42
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
43
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
44
+
45
+ require 'rspec'
46
+ require 'aws_session_token'
47
+
48
+ # Requires supporting files with custom matchers and macros, etc,
49
+ # in ./support/ and its subdirectories.
50
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
51
+
52
+ RSpec.configure do |config|
53
+
54
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # AWS Session Token Gem - Tool to wrap AWS API to create and store
5
+ # Session tokens so that other commands/tools (e.g. Terraform) can function as
6
+ # necessary.
7
+ #
8
+ #
9
+ # Copyright 2018 Bryan Stopp <bryan.stopp@gmail.com>
10
+ #
11
+ # Licensed under the Apache License, Version 2.0 (the "License");
12
+ # you may not use this file except in compliance with the License.
13
+ # You may obtain a copy of the License at
14
+ #
15
+ # http://www.apache.org/licenses/LICENSE-2.0
16
+ #
17
+ # Unless required by applicable law or agreed to in writing, software
18
+ # distributed under the License is distributed on an "AS IS" BASIS,
19
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ # See the License for the specific language governing permissions and
21
+ # limitations under the License.
22
+ #
23
+
24
+ RSpec::Matchers.define :exit_with_code do |code|
25
+ supports_block_expectations
26
+
27
+ actual = nil
28
+
29
+ match do |block|
30
+ begin
31
+ block.call
32
+ rescue SystemExit => e
33
+ actual = e.status
34
+ end
35
+ actual && actual == code
36
+ end
37
+
38
+ failure_message do
39
+ "expected block to call exit(#{code}) but exit" +
40
+ (actual.nil? ? ' not called' : "(#{actual}) was called")
41
+ end
42
+
43
+ failure_message_when_negated do
44
+ "expected block not to call exit(#{code})"
45
+ end
46
+
47
+ description do
48
+ "expect block to call exit(#{code})"
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,226 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws_session_token
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Bryan Stopp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: highline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: semver2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: copyright-header
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: github_changelog_generator
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.14'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.14'
97
+ - !ruby/object:Gem::Dependency
98
+ name: juwelier
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rdoc
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.12'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.12'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.55'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.55'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: yard
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.7'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.7'
167
+ description: 'Tool to wrap AWS API to create and store Session tokens so that other
168
+ commands/tools (e.g. Terraform) can function as necessary.
169
+
170
+ '
171
+ email: bryan.stopp@gmail.com
172
+ executables:
173
+ - aws_session_token
174
+ extensions: []
175
+ extra_rdoc_files:
176
+ - LICENSE
177
+ - README.markdown
178
+ files:
179
+ - ".document"
180
+ - ".rspec"
181
+ - ".rubocop.yml"
182
+ - ".semver"
183
+ - ".travis.yml"
184
+ - CHANGELOG.md
185
+ - Gemfile
186
+ - Gemfile.lock
187
+ - LICENSE
188
+ - README.markdown
189
+ - Rakefile
190
+ - bin/aws_session_token
191
+ - config/syntax.yaml
192
+ - lib/aws_session_token.rb
193
+ - lib/aws_session_token/cli.rb
194
+ - lib/aws_session_token/credentials_file.rb
195
+ - lib/aws_session_token/options.rb
196
+ - spec/aws_session_token/cli_spec.rb
197
+ - spec/aws_session_token/credentials_file_spec.rb
198
+ - spec/aws_session_token/options_spec.rb
199
+ - spec/spec.opts
200
+ - spec/spec_helper.rb
201
+ - spec/support/custom_matchers.rb
202
+ homepage: http://github.com/bstopp/aws_session_token
203
+ licenses:
204
+ - Apache-2.0
205
+ metadata: {}
206
+ post_install_message:
207
+ rdoc_options: []
208
+ require_paths:
209
+ - lib
210
+ required_ruby_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '2.3'
215
+ required_rubygems_version: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ version: '0'
220
+ requirements: []
221
+ rubyforge_project:
222
+ rubygems_version: 2.6.14
223
+ signing_key:
224
+ specification_version: 4
225
+ summary: Create & Store AWS Session Tokens
226
+ test_files: []