Skip to content

Commit bf31261

Browse files
committed
Support Google.config default options
1 parent e9a9848 commit bf31261

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

lib/aws/google.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ class Google
2727
include ::Aws::Google::CachedCredentials
2828

2929
class << self
30+
# Use `Aws::Google.config` to set default options for any instance of this provider.
3031
attr_accessor :config
3132
end
33+
self.config = {}
3234

3335
# @option options [required, String] :role_arn
3436
# @option options [String] :policy
@@ -43,6 +45,7 @@ class << self
4345
# @option options [String] :client_id Google client ID
4446
# @option options [String] :client_secret Google client secret
4547
def initialize(options = {})
48+
options = options.merge(self.class.config)
4649
@oauth_attempted = false
4750
@assume_role_params = options.slice(
4851
*Aws::STS::Client.api.operation(:assume_role_with_web_identity).

lib/aws/google/credential_provider.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ module GoogleSharedCredentials
2424
def google_credentials_from_config(opts = {})
2525
p = opts[:profile] || @profile_name
2626
if @config_enabled && @parsed_config
27-
entry = @parsed_config.fetch(p, {})
28-
if (google_opts = entry['google'])
29-
Google.new(google_opts.transform_keys(&:to_sym))
27+
google_opts = @parsed_config.
28+
fetch(p, {}).fetch('google', {}).
29+
transform_keys(&:to_sym)
30+
if google_opts.merge(::Aws::Google.config).has_key?(:role_arn)
31+
Google.new(google_opts)
3032
end
3133
end
3234
end

test/aws/google_test.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
end
2424

2525
describe 'not configured' do
26-
before do
27-
Aws::Google.stubs(:config).returns(nil)
28-
end
29-
3026
it 'does nothing' do
3127
Aws::Google.expects(:new).never
3228
Aws::STS::Client.new
@@ -64,7 +60,6 @@
6460
let(:system) { @system }
6561

6662
before do
67-
Aws::Google.stubs(:config).returns(config)
6863
config[:client].stub_responses(
6964
:assume_role_with_web_identity,
7065
credentials: credentials
@@ -129,6 +124,16 @@
129124
Aws::Google.any_instance.expects(:refresh).never
130125
Aws::Google.new(config).credentials
131126
end
127+
128+
it 'uses config defaults for new AWS clients' do
129+
Aws::Google.stubs(:config).returns(config)
130+
@oauth_default.once
131+
system.times(5)
132+
c = Aws::STS::Client.new.config.credentials
133+
_(c.credentials.access_key_id).must_equal credentials[:access_key_id]
134+
_(c.credentials.secret_access_key).must_equal credentials[:secret_access_key]
135+
_(c.credentials.session_token).must_equal credentials[:session_token]
136+
end
132137

133138
describe 'valid Google auth, no AWS permissions' do
134139
before do

0 commit comments

Comments
 (0)