Skip to content

Commit 759d70c

Browse files
WIP update aws sdk
1 parent 5350f17 commit 759d70c

File tree

5 files changed

+39
-23
lines changed

5 files changed

+39
-23
lines changed

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.0.5

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ Or install it yourself as:
2424
Visit the [Google API Console](https://console.developers.google.com/) to create/obtain [OAuth 2.0 Client ID credentials](https://support.google.com/cloud/answer/6158849) (client ID and client secret) for an application in your Google account.
2525

2626
### Create an AWS IAM Role
27-
Create an AWS IAM Role with the desired IAM policies attached, and a ['trust policy'](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html#term_trust-policy) ([`AssumeRolePolicyDocument`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateRole.html)) allowing the [`sts:AssumeRoleWithWebIdentity`](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithWebIdentity.html) action with [Web Identity Federation condition keys](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_iam-condition-keys.html#condition-keys-wif) authorizing
27+
Create an AWS IAM Role with the desired IAM policies attached, and a ['trust policy'][1] ([`AssumeRolePolicyDocument`][2]) allowing the [`sts:AssumeRoleWithWebIdentity`][3] action with [Web Identity Federation condition keys][4] authorizing
2828
your Google Client ID (`accounts.google.com:aud`) and a specific set of Google Account IDs (`accounts.google.com:sub`):
2929

30+
[1]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html#term_trust-policy "IAM Trust Policy"
31+
[2]: https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateRole.html "Create Role API"
32+
[3]: https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithWebIdentity.html "Assume Role With Identity API"
33+
[4]: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_iam-condition-keys.html#condition-keys-wif "IAM Condition Keys"
34+
3035
```json
3136
{
3237
"Version": "2012-10-17",
@@ -53,6 +58,7 @@ your Google Client ID (`accounts.google.com:aud`) and a specific set of Google A
5358

5459
### Method 1: `Aws::Google`
5560
In your Ruby code, construct an `Aws::Google` object by passing the AWS `role_arn`, Google `client_id` and `client_secret`, either as constructor arguments or via the `Aws::Google.config` global defaults:
61+
5662
```ruby
5763
require 'aws/google'
5864

aws-google.gemspec

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
lib = File.expand_path('../lib', __FILE__)
1+
lib = File.expand_path('lib', __dir__)
22
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
33
require 'aws/google/version'
44

55
Gem::Specification.new do |spec|
6+
spec.required_ruby_version = '>= 3.0.5'
67
spec.name = 'aws-google'
78
spec.version = Aws::Google::VERSION
89
spec.authors = ['Will Jordan']
@@ -21,14 +22,14 @@ Gem::Specification.new do |spec|
2122
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2223
spec.require_paths = ['lib']
2324

24-
spec.add_dependency 'aws-sdk-core', '~> 3.130'
25+
spec.add_dependency 'aws-sdk-core', '~> 3.201'
2526
spec.add_dependency 'google-apis-core'
2627
spec.add_dependency 'launchy', '~> 2'
2728

28-
spec.add_development_dependency 'activesupport', '~> 5'
29-
spec.add_development_dependency 'minitest', '~> 5.14.2'
30-
spec.add_development_dependency 'mocha', '~> 1.5'
31-
spec.add_development_dependency 'rake', '~> 12'
29+
spec.add_development_dependency 'activesupport', '~> 6.1.7.8'
30+
spec.add_development_dependency 'minitest', '~> 5.25.1'
31+
spec.add_development_dependency 'mocha', '~> 2.4'
32+
spec.add_development_dependency 'rake', '~> 13'
3233
spec.add_development_dependency 'timecop', '~> 0.8'
33-
spec.add_development_dependency 'webmock', '~> 3.3'
34+
spec.add_development_dependency 'webmock', '~> 3'
3435
end

lib/aws/google/cached_credentials.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,18 @@ def refresh_if_near_expiration
3535

3636
# Write credentials and expiration to AWS credentials file.
3737
def write_credentials
38-
# AWS CLI is needed because writing AWS credentials is not supported by the AWS Ruby SDK.
38+
# Ensure the AWS CLI is available before attempting to write credentials.
3939
return unless system('which aws >/dev/null 2>&1')
40-
Aws::SharedCredentials::KEY_MAP.transform_values(&@credentials.method(:send)).
41-
merge(expiration: @expiration).each do |key, value|
40+
41+
# Manually map the credentials to the keys used by AWS CLI
42+
credentials_map = {
43+
'aws_access_key_id' => @credentials.access_key_id,
44+
'aws_secret_access_key' => @credentials.secret_access_key,
45+
'aws_session_token' => @credentials.session_token
46+
}
47+
48+
# Use the AWS CLI to set the credentials in the session profile
49+
credentials_map.each do |key, value|
4250
system("aws configure set #{key} #{value} --profile #{@session_profile}")
4351
end
4452
end

test/aws/google_test.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272

7373
it 'creates credentials from a Google auth token' do
7474
@oauth_default.once
75-
system.times(5)
75+
system.times(4)
7676

7777
c = Aws::Google.new(config).credentials
7878
_(c.credentials.access_key_id).must_equal credentials[:access_key_id]
@@ -83,12 +83,12 @@
8383
it 'refreshes expired Google auth token credentials' do
8484
m = mock
8585
m.stubs(:refresh!)
86-
m.stubs(:id_token).
87-
returns(JWT.encode({ email: 'email', exp: Time.now.to_i - 1 }, '')).
88-
then.returns(JWT.encode({ email: 'email' }, ''))
86+
m.stubs(:id_token)
87+
.returns(JWT.encode({ email: 'email', exp: Time.now.to_i - 1 }, ''))
88+
.then.returns(JWT.encode({ email: 'email' }, ''))
8989
Google::Auth.stubs(:get_application_default).returns(m)
9090

91-
system.times(5)
91+
system.times(4)
9292

9393
c = Aws::Google.new(config).credentials
9494
_(c.credentials.access_key_id).must_equal credentials[:access_key_id]
@@ -115,7 +115,7 @@
115115
it 'refreshes saved expired credentials' do
116116
config[:profile] = 'cdo-expired'
117117
@oauth_default.once
118-
system.times(5)
118+
system.times(4)
119119
Aws::Google.new(config).credentials
120120
end
121121

@@ -124,11 +124,11 @@
124124
Aws::Google.any_instance.expects(:refresh).never
125125
Aws::Google.new(config).credentials
126126
end
127-
127+
128128
it 'uses config defaults for new AWS clients' do
129129
Aws::Google.stubs(:config).returns(config)
130130
@oauth_default.once
131-
system.times(5)
131+
system.times(4)
132132
c = Aws::STS::Client.new.config.credentials
133133
_(c.credentials.access_key_id).must_equal credentials[:access_key_id]
134134
_(c.credentials.secret_access_key).must_equal credentials[:secret_access_key]
@@ -147,7 +147,7 @@
147147
end
148148

149149
it 'retries Google auth when invalid credentials are provided' do
150-
system.times(5)
150+
system.times(4)
151151
@oauth_default.once
152152
Aws::Google.any_instance.expects(:google_oauth).returns(oauth)
153153
Aws::Google.new(config).credentials
@@ -198,13 +198,13 @@
198198
end
199199

200200
it 'refreshes Google auth token when expired' do
201-
system.times(5)
201+
system.times(4)
202202
@oauth_default.once
203203
Aws::Google.any_instance.expects(:google_oauth).returns(oauth).once
204204
Aws::Google.new(config).credentials
205205
end
206206
end
207-
207+
208208
describe 'no shared config' do
209209
before do
210210
Aws.shared_config.fresh(
@@ -218,7 +218,7 @@
218218
Aws::Google.stubs(:config).returns(config)
219219

220220
@oauth_default.once
221-
system.times(5)
221+
system.times(4)
222222

223223
c = Aws::STS::Client.new(region: 'us-east-1').config.credentials
224224
_(c.credentials.access_key_id).must_equal credentials[:access_key_id]

0 commit comments

Comments
 (0)