Skip to content

Commit 2224695

Browse files
Fixes and rubocop
1 parent c4a2136 commit 2224695

2 files changed

Lines changed: 17 additions & 19 deletions

File tree

gems/smithy-client/lib/smithy-client/plugins/resolve_auth.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,34 @@ def call(context)
3232
private
3333

3434
def resolve_auth(context, auth_options)
35-
failures = []
3635
raise 'No auth options were resolved' if auth_options.empty?
3736

37+
failures = []
3838
auth_options.each do |auth_option|
3939
scheme_id = auth_option[:scheme_id]
40+
4041
# Anonymous auth does not have a plugin and does not sign
4142
return auth_option if scheme_id == 'smithy.api#noAuth'
4243

43-
unless context.config.auth_schemes.key?(scheme_id)
44-
failures << "Auth scheme #{scheme_id} was not enabled for this request"
45-
next
46-
end
44+
error = validate_auth_scheme(context, scheme_id)
45+
return auth_option unless error
4746

48-
identity_provider = context.config.auth_schemes[scheme_id]
49-
unless identity_provider
50-
failures << "Auth scheme #{scheme_id} did not have an identity provider configured"
51-
next
52-
end
47+
failures << error
48+
end
5349

54-
unless identity_provider.identity
55-
failures << "Auth scheme #{scheme_id} failed to resolve identity"
56-
next
57-
end
50+
raise failures.join("\n")
51+
end
5852

59-
return auth_option
53+
def validate_auth_scheme(context, scheme_id)
54+
unless context.config.auth_schemes.key?(scheme_id)
55+
return "Auth scheme #{scheme_id} was not enabled for this request"
6056
end
6157

62-
raise failures.join("\n")
58+
identity_provider = context.config.auth_schemes[scheme_id]
59+
return "Auth scheme #{scheme_id} did not have an identity provider configured" unless identity_provider
60+
return "Auth scheme #{scheme_id} failed to resolve identity" unless identity_provider.set?
61+
62+
nil
6363
end
6464
end
6565

gems/smithy-client/spec/smithy-client/plugins/resolve_auth_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ def resolve(_)
9696
it 'raises an error when identity resolver fails to resolve identity' do
9797
shapes['smithy.ruby.tests#SampleClient']['traits']['smithy.api#httpApiKeyAuth'] = {}
9898
client_class.add_plugin(HttpApiKeyAuth)
99-
provider = ApiKeyProvider.new(key: 'stubbed_key')
100-
expect(provider).to receive(:identity).and_return(nil)
101-
client = client_class.new(stub_responses: true, api_key_provider: provider)
99+
client = client_class.new(stub_responses: true, api_key_provider: ApiKeyProvider.new)
102100
expect { client.operation }.to raise_error(/failed to resolve identity/)
103101
end
104102
end

0 commit comments

Comments
 (0)