File tree Expand file tree Collapse file tree 3 files changed +18
-8
lines changed Expand file tree Collapse file tree 3 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -27,8 +27,10 @@ class Google
27
27
include ::Aws ::Google ::CachedCredentials
28
28
29
29
class << self
30
+ # Use `Aws::Google.config` to set default options for any instance of this provider.
30
31
attr_accessor :config
31
32
end
33
+ self . config = { }
32
34
33
35
# @option options [required, String] :role_arn
34
36
# @option options [String] :policy
@@ -43,6 +45,7 @@ class << self
43
45
# @option options [String] :client_id Google client ID
44
46
# @option options [String] :client_secret Google client secret
45
47
def initialize ( options = { } )
48
+ options = options . merge ( self . class . config )
46
49
@oauth_attempted = false
47
50
@assume_role_params = options . slice (
48
51
*Aws ::STS ::Client . api . operation ( :assume_role_with_web_identity ) .
Original file line number Diff line number Diff line change @@ -24,9 +24,11 @@ module GoogleSharedCredentials
24
24
def google_credentials_from_config ( opts = { } )
25
25
p = opts [ :profile ] || @profile_name
26
26
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 )
30
32
end
31
33
end
32
34
end
Original file line number Diff line number Diff line change 23
23
end
24
24
25
25
describe 'not configured' do
26
- before do
27
- Aws ::Google . stubs ( :config ) . returns ( nil )
28
- end
29
-
30
26
it 'does nothing' do
31
27
Aws ::Google . expects ( :new ) . never
32
28
Aws ::STS ::Client . new
64
60
let ( :system ) { @system }
65
61
66
62
before do
67
- Aws ::Google . stubs ( :config ) . returns ( config )
68
63
config [ :client ] . stub_responses (
69
64
:assume_role_with_web_identity ,
70
65
credentials : credentials
129
124
Aws ::Google . any_instance . expects ( :refresh ) . never
130
125
Aws ::Google . new ( config ) . credentials
131
126
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
132
137
133
138
describe 'valid Google auth, no AWS permissions' do
134
139
before do
You can’t perform that action at this time.
0 commit comments