Skip to content

Commit

Permalink
Change credentials to take kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp committed Oct 20, 2023
1 parent efa28fb commit 5f57727
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def built_in_to_param(built_in, value)
when 'AWS::Auth::CredentialScope'
Param.new(
'credentials',
"Aws::Credentials.new('stubbed-akid', 'stubbed-secret', nil, '#{value}')",
"Aws::Credentials.new('stubbed-akid', 'stubbed-secret', nil, credential_scope: '#{value}')",
true
)
when 'AWS::STS::UseGlobalEndpoint'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def static_credentials(options)
options[:config].access_key_id,
options[:config].secret_access_key,
options[:config].session_token,
options[:config].credential_scope
credential_scope: options[:config].credential_scope
)
end
end
Expand Down Expand Up @@ -96,7 +96,12 @@ def env_credentials(_options)
secret = %w[AWS_SECRET_ACCESS_KEY AMAZON_SECRET_ACCESS_KEY AWS_SECRET_KEY]
token = %w[AWS_SESSION_TOKEN AMAZON_SESSION_TOKEN]
scope = %w[AWS_CREDENTIAL_SCOPE]
Credentials.new(envar(key), envar(secret), envar(token), envar(scope))
Credentials.new(
envar(key),
envar(secret),
envar(token),
credential_scope: envar(scope)
)
end

def envar(keys)
Expand Down
7 changes: 4 additions & 3 deletions gems/aws-sdk-core/lib/aws-sdk-core/credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ class Credentials
# @param [String] access_key_id
# @param [String] secret_access_key
# @param [String] session_token (nil)
# @param [String] credential_scope (nil)
# @param [Hash] kwargs
# @option kwargs [String] :credential_scope (nil)
def initialize(access_key_id, secret_access_key, session_token = nil,
credential_scope = nil)
**kwargs)
@access_key_id = access_key_id
@secret_access_key = secret_access_key
@session_token = session_token
@credential_scope = credential_scope
@credential_scope = kwargs[:credential_scope]
end

# @return [String]
Expand Down
2 changes: 1 addition & 1 deletion gems/aws-sdk-core/lib/aws-sdk-core/shared_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def credentials_from_profile(prof_config)
prof_config['aws_access_key_id'],
prof_config['aws_secret_access_key'],
prof_config['aws_session_token'],
prof_config['aws_credential_scope']
credential_scope: prof_config['aws_credential_scope']
)
creds if creds.set?
end
Expand Down
3 changes: 1 addition & 2 deletions gems/aws-sdk-core/spec/aws/credential_scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def setup_profile(profile)
credentials: Credentials.new(
profile['aws_access_key_id'],
profile['aws_secret_access_key'],
nil,
profile['aws_credential_scope']
credential_scope: profile['aws_credential_scope']
),
set?: true
)
Expand Down
8 changes: 7 additions & 1 deletion gems/aws-sdk-core/spec/aws/credentials_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ module Aws
expect(Credentials.new('akid', 'secret').session_token).to be(nil)
end

it 'takes extra properties after session token' do
expect do
Credentials.new('akid', 'secret', nil, foo: 'bar')
end.to_not raise_error
end

it 'provides access to the credential scope' do
creds = Credentials.new('akid', 'secret', nil, 'scope')
creds = Credentials.new('akid', 'secret', credential_scope: 'scope')
expect(creds.credential_scope).to eq('scope')
end

Expand Down

0 comments on commit 5f57727

Please sign in to comment.