Skip to content

Commit 090df4e

Browse files
Merge pull request #7 from code-dot-org/darin/update-aws-sdk
Update gem dependencies
2 parents 5350f17 + 02d2408 commit 090df4e

File tree

9 files changed

+121
-28
lines changed

9 files changed

+121
-28
lines changed

.github/workflows/pr-verify.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Run Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
# Test on code-dot-org Ruby version
10+
test_3_0_5:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Ruby
18+
uses: ruby/setup-ruby@v1
19+
with:
20+
ruby-version: 3.0.5
21+
bundler-cache: true
22+
23+
- name: Install gems
24+
run: bundle install
25+
26+
- name: Run tests
27+
run: bundle exec rake test
28+
29+
#Test on latest Ruby
30+
test_3_3:
31+
runs-on: ubuntu-latest
32+
33+
steps:
34+
- name: Checkout code
35+
uses: actions/checkout@v3
36+
37+
- name: Set up Ruby
38+
uses: ruby/setup-ruby@v1
39+
with:
40+
ruby-version: 3.3
41+
bundler-cache: true
42+
43+
- name: Install gems
44+
run: bundle install
45+
46+
- name: Run tests
47+
run: bundle exec rake test

.ruby-version

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

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM ruby:3.0.5
2+
3+
WORKDIR /app
4+
5+
# Copy bare minimum files to install gems
6+
COPY Gemfile aws-google.gemspec /app/
7+
COPY lib /app/lib
8+
RUN bundle install

README.md

Lines changed: 22 additions & 3 deletions
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

@@ -87,9 +93,22 @@ The extra `credential_process` config line tells AWS to [Source Credentials with
8793

8894
## Development
8995

90-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
96+
Prerequisites:
97+
98+
* Ruby 3.0.5
99+
100+
You can have Ruby installed locally, or use Docker and mount this repository into a Ruby container. By using Docker you can avoid conflicts with differing Ruby versions or other installed gems. To run and 'bash' into a Ruby container, install Docker and run the following. See [docker-compose.yml](docker-compose.yml) for details.
101+
102+
```
103+
docker compose build
104+
docker compose run ruby
105+
```
106+
107+
With either option, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
108+
109+
To install this gem onto your local machine, run `bundle exec rake install`.
91110

92-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
111+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
93112

94113
## Contributing
95114

aws-google.gemspec

Lines changed: 11 additions & 10 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 'google-apis-core'
26-
spec.add_dependency 'launchy', '~> 2'
25+
spec.add_dependency 'aws-sdk-core', '~> 3.211.0'
26+
spec.add_dependency 'google-apis-core', '~> 0.15.1'
27+
spec.add_dependency 'launchy', '~> 3.0.1'
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'
32-
spec.add_development_dependency 'timecop', '~> 0.8'
33-
spec.add_development_dependency 'webmock', '~> 3.3'
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.5'
32+
spec.add_development_dependency 'rake', '~> 13.2.1'
33+
spec.add_development_dependency 'timecop', '~> 0.9.10'
34+
spec.add_development_dependency 'webmock', '3.24.0'
3435
end

docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
ruby:
3+
build: .
4+
volumes:
5+
- .:/app
6+
working_dir: /app
7+
command: bash

lib/aws/google/cached_credentials.rb

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,31 @@ def initialize(options = {})
2323
end
2424

2525
def refresh_if_near_expiration
26-
if near_expiration?(SYNC_EXPIRATION_LENGTH)
27-
@mutex.synchronize do
28-
if near_expiration?(SYNC_EXPIRATION_LENGTH)
29-
refresh
30-
write_credentials
31-
end
26+
return unless near_expiration?(SYNC_EXPIRATION_LENGTH)
27+
28+
@mutex.synchronize do
29+
if near_expiration?(SYNC_EXPIRATION_LENGTH)
30+
refresh
31+
write_credentials
3232
end
3333
end
3434
end
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+
'expiration' => @expiration
47+
}
48+
49+
# Use the AWS CLI to set the credentials in the session profile
50+
credentials_map.each do |key, value|
4251
system("aws configure set #{key} #{value} --profile #{@session_profile}")
4352
end
4453
end

lib/aws/google/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Aws
22
class Google
3-
VERSION = '0.2.0'.freeze
3+
VERSION = '0.2.1'.freeze
44
end
55
end

test/aws/google_test.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@
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

9191
system.times(5)
@@ -108,6 +108,7 @@
108108
expiration = provider.expiration
109109
_(expiration).must_equal(provider.expiration)
110110
Timecop.travel(1.5.hours.from_now) do
111+
provider.refresh!
111112
_(expiration).wont_equal(provider.expiration)
112113
end
113114
end
@@ -124,7 +125,7 @@
124125
Aws::Google.any_instance.expects(:refresh).never
125126
Aws::Google.new(config).credentials
126127
end
127-
128+
128129
it 'uses config defaults for new AWS clients' do
129130
Aws::Google.stubs(:config).returns(config)
130131
@oauth_default.once
@@ -204,7 +205,7 @@
204205
Aws::Google.new(config).credentials
205206
end
206207
end
207-
208+
208209
describe 'no shared config' do
209210
before do
210211
Aws.shared_config.fresh(

0 commit comments

Comments
 (0)