Skip to content

Commit f5ac52c

Browse files
committed
fix dynamo default crednetials provider chain
1 parent 2e8d691 commit f5ac52c

File tree

6 files changed

+86
-67
lines changed

6 files changed

+86
-67
lines changed

generated/src/aws-cpp-sdk-dynamodb/source/DynamoDBClient.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,16 @@ const char* DynamoDBClient::GetAllocationTag() { return ALLOCATION_TAG; }
101101

102102
DynamoDBClient::DynamoDBClient(const DynamoDB::DynamoDBClientConfiguration& clientConfiguration,
103103
std::shared_ptr<DynamoDBEndpointProviderBase> endpointProvider)
104-
: AwsSmithyClientT(clientConfiguration, GetServiceName(), "DynamoDB", Aws::Http::CreateHttpClient(clientConfiguration),
105-
Aws::MakeShared<DynamoDBErrorMarshaller>(ALLOCATION_TAG),
106-
endpointProvider ? endpointProvider : Aws::MakeShared<DynamoDBEndpointProvider>(ALLOCATION_TAG),
107-
Aws::MakeShared<smithy::GenericAuthSchemeResolver<>>(
108-
ALLOCATION_TAG, Aws::Vector<smithy::AuthSchemeOption>({smithy::SigV4AuthSchemeOption::sigV4AuthSchemeOption})),
109-
{
110-
{smithy::SigV4AuthSchemeOption::sigV4AuthSchemeOption.schemeId,
111-
smithy::SigV4AuthScheme{GetServiceName(), clientConfiguration.region}},
112-
}) {}
104+
: AwsSmithyClientT(
105+
clientConfiguration, GetServiceName(), "DynamoDB", Aws::Http::CreateHttpClient(clientConfiguration),
106+
Aws::MakeShared<DynamoDBErrorMarshaller>(ALLOCATION_TAG),
107+
endpointProvider ? endpointProvider : Aws::MakeShared<DynamoDBEndpointProvider>(ALLOCATION_TAG),
108+
Aws::MakeShared<smithy::GenericAuthSchemeResolver<>>(
109+
ALLOCATION_TAG, Aws::Vector<smithy::AuthSchemeOption>({smithy::SigV4AuthSchemeOption::sigV4AuthSchemeOption})),
110+
{
111+
{smithy::SigV4AuthSchemeOption::sigV4AuthSchemeOption.schemeId,
112+
smithy::SigV4AuthScheme{GetServiceName(), clientConfiguration.region, clientConfiguration.credentialProviderConfig}},
113+
}) {}
113114

114115
DynamoDBClient::DynamoDBClient(const AWSCredentials& credentials, std::shared_ptr<DynamoDBEndpointProviderBase> endpointProvider,
115116
const DynamoDB::DynamoDBClientConfiguration& clientConfiguration)
@@ -148,7 +149,8 @@ DynamoDBClient::DynamoDBClient(const Client::ClientConfiguration& clientConfigur
148149
ALLOCATION_TAG, Aws::Vector<smithy::AuthSchemeOption>({smithy::SigV4AuthSchemeOption::sigV4AuthSchemeOption})),
149150
{
150151
{smithy::SigV4AuthSchemeOption::sigV4AuthSchemeOption.schemeId,
151-
smithy::SigV4AuthScheme{Aws::MakeShared<smithy::DefaultAwsCredentialIdentityResolver>(ALLOCATION_TAG),
152+
smithy::SigV4AuthScheme{Aws::MakeShared<smithy::DefaultAwsCredentialIdentityResolver>(
153+
ALLOCATION_TAG, clientConfiguration.credentialProviderConfig),
152154
GetServiceName(), clientConfiguration.region}},
153155
}) {}
154156

src/aws-cpp-sdk-core/include/smithy/identity/auth/built-in/BearerTokenAuthScheme.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ class BearerTokenAuthScheme : public AuthScheme<AwsBearerTokenIdentityBase>
3333
assert(m_signer);
3434
}
3535

36+
explicit BearerTokenAuthScheme(const Aws::String &serviceName, const Aws::String &region,
37+
const Aws::Client::ClientConfiguration::CredentialProviderConfiguration& config)
38+
: BearerTokenAuthScheme(Aws::MakeShared<DefaultAwsBearerTokenIdentityResolver>("BearerTokenAuthScheme"), serviceName, region) {
39+
AWS_UNREFERENCED_PARAM(config);
40+
assert(m_identityResolver);
41+
assert(m_signer);
42+
}
43+
3644
explicit BearerTokenAuthScheme(const Aws::String &serviceName,
3745
const Aws::String &region)
3846
: BearerTokenAuthScheme(

src/aws-cpp-sdk-core/include/smithy/identity/auth/built-in/SigV4AuthScheme.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ namespace smithy {
5959
{
6060
}
6161

62+
explicit SigV4AuthScheme(const Aws::String& serviceName, const Aws::String& region,
63+
const Aws::Client::ClientConfiguration::CredentialProviderConfiguration& config)
64+
: SigV4AuthScheme(
65+
Aws::MakeShared<DefaultAwsCredentialIdentityResolver>("SigV4AuthScheme", config),
66+
serviceName, region) {}
67+
6268
//For legacy constructors, signing requires additional input parameters
6369
explicit SigV4AuthScheme(const Aws::String& serviceName,
6470
const Aws::String& region,

src/aws-cpp-sdk-core/include/smithy/identity/auth/built-in/SigV4aAuthScheme.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ namespace smithy {
3636
assert(m_signer);
3737
}
3838

39+
explicit SigV4aAuthScheme(const Aws::String& serviceName, const Aws::String& region,
40+
const Aws::Client::ClientConfiguration::CredentialProviderConfiguration& config)
41+
: SigV4aAuthScheme(
42+
Aws::MakeShared<DefaultAwsCredentialIdentityResolver>("SigV4aAuthScheme", config),
43+
serviceName, region) {
44+
assert(m_identityResolver);
45+
assert(m_signer);
46+
}
47+
3948
explicit SigV4aAuthScheme(const Aws::String& serviceName,
4049
const Aws::String& region)
4150
: SigV4aAuthScheme(Aws::MakeShared<DefaultAwsCredentialIdentityResolver>("SigV4aAuthScheme"), serviceName, region)

src/aws-cpp-sdk-core/include/smithy/identity/resolver/built-in/DefaultAwsCredentialIdentityResolver.h

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,53 @@
44
*/
55
#pragma once
66

7-
#include <smithy/identity/resolver/AwsCredentialIdentityResolver.h>
8-
97
#include <aws/core/auth/AWSCredentials.h>
108
#include <aws/core/auth/AWSCredentialsProviderChain.h>
9+
#include <smithy/identity/resolver/AwsCredentialIdentityResolver.h>
1110

1211
namespace smithy {
13-
constexpr char ALLOC_ID[] = "DefaultAwsCredentialIdentityResolver";
14-
/**
15-
* A smithy SigV4 AWS Credentials resolver wrapper on top of legacy SDK Credentials provider
16-
* TODO: refactor into own signer using smithy design
17-
*/
18-
class DefaultAwsCredentialIdentityResolver : public AwsCredentialIdentityResolver {
19-
protected:
20-
21-
mutable std::shared_ptr<Aws::Auth::AWSCredentialsProviderChain> legacyChain_sp;
22-
23-
public:
24-
using SigV4AuthSchemeParameters = DefaultAuthSchemeResolverParameters;
25-
26-
DefaultAwsCredentialIdentityResolver(): legacyChain_sp{Aws::MakeShared<Aws::Auth::DefaultAWSCredentialsProviderChain>(ALLOC_ID)}{
27-
28-
};
29-
30-
DefaultAwsCredentialIdentityResolver(const Aws::Auth::DefaultAWSCredentialsProviderChain& credChain): legacyChain_sp{Aws::MakeShared<Aws::Auth::DefaultAWSCredentialsProviderChain>(ALLOC_ID, credChain)}{
31-
32-
};
33-
34-
DefaultAwsCredentialIdentityResolver(const DefaultAwsCredentialIdentityResolver& other) = delete;
35-
DefaultAwsCredentialIdentityResolver(DefaultAwsCredentialIdentityResolver&& other) noexcept = default;
36-
DefaultAwsCredentialIdentityResolver& operator=(const DefaultAwsCredentialIdentityResolver& other) = delete;
37-
DefaultAwsCredentialIdentityResolver& operator=(DefaultAwsCredentialIdentityResolver&& other) noexcept = default;
38-
virtual ~DefaultAwsCredentialIdentityResolver() = default;
39-
40-
DefaultAwsCredentialIdentityResolver(std::shared_ptr<Aws::Auth::AWSCredentialsProviderChain> providerChain): legacyChain_sp{providerChain}
41-
{
42-
assert(legacyChain_sp);
43-
};
44-
45-
ResolveIdentityFutureOutcome getIdentity(const IdentityProperties& identityProperties, const AdditionalParameters& additionalParameters) override
46-
{
47-
AWS_UNREFERENCED_PARAM(identityProperties);
48-
AWS_UNREFERENCED_PARAM(additionalParameters);
49-
50-
auto legacyCreds = legacyChain_sp->GetAWSCredentials();
51-
52-
auto smithyCreds = Aws::MakeUnique<AwsCredentialIdentity>("DefaultAwsCredentialIdentityResolver",
53-
legacyCreds.GetAWSAccessKeyId(),
54-
legacyCreds.GetAWSSecretKey(),
55-
legacyCreds.GetSessionToken().empty()? Aws::Crt::Optional<Aws::String>() : legacyCreds.GetSessionToken(),
56-
legacyCreds.GetExpiration(),
57-
legacyCreds.GetAccountId().empty()? Aws::Crt::Optional<Aws::String>() : legacyCreds.GetAccountId());
58-
59-
return ResolveIdentityFutureOutcome(std::move(smithyCreds));
60-
}
61-
};
62-
}
12+
constexpr char ALLOC_ID[] = "DefaultAwsCredentialIdentityResolver";
13+
/**
14+
* A smithy SigV4 AWS Credentials resolver wrapper on top of legacy SDK Credentials provider
15+
* TODO: refactor into own signer using smithy design
16+
*/
17+
class DefaultAwsCredentialIdentityResolver : public AwsCredentialIdentityResolver {
18+
protected:
19+
mutable std::shared_ptr<Aws::Auth::AWSCredentialsProviderChain> legacyChain_sp;
20+
21+
public:
22+
using SigV4AuthSchemeParameters = DefaultAuthSchemeResolverParameters;
23+
24+
DefaultAwsCredentialIdentityResolver() : legacyChain_sp{Aws::MakeShared<Aws::Auth::DefaultAWSCredentialsProviderChain>(ALLOC_ID)} {};
25+
DefaultAwsCredentialIdentityResolver(const Aws::Client::ClientConfiguration::CredentialProviderConfiguration& config)
26+
: legacyChain_sp{Aws::MakeShared<Aws::Auth::DefaultAWSCredentialsProviderChain>(ALLOC_ID, config)} {};
27+
DefaultAwsCredentialIdentityResolver(const Aws::Auth::DefaultAWSCredentialsProviderChain& credChain)
28+
: legacyChain_sp{Aws::MakeShared<Aws::Auth::DefaultAWSCredentialsProviderChain>(ALLOC_ID, credChain)} {};
29+
30+
DefaultAwsCredentialIdentityResolver(const DefaultAwsCredentialIdentityResolver& other) = delete;
31+
DefaultAwsCredentialIdentityResolver(DefaultAwsCredentialIdentityResolver&& other) noexcept = default;
32+
DefaultAwsCredentialIdentityResolver& operator=(const DefaultAwsCredentialIdentityResolver& other) = delete;
33+
DefaultAwsCredentialIdentityResolver& operator=(DefaultAwsCredentialIdentityResolver&& other) noexcept = default;
34+
virtual ~DefaultAwsCredentialIdentityResolver() = default;
35+
36+
DefaultAwsCredentialIdentityResolver(std::shared_ptr<Aws::Auth::AWSCredentialsProviderChain> providerChain)
37+
: legacyChain_sp{providerChain} {
38+
assert(legacyChain_sp);
39+
};
40+
41+
ResolveIdentityFutureOutcome getIdentity(const IdentityProperties& identityProperties,
42+
const AdditionalParameters& additionalParameters) override {
43+
AWS_UNREFERENCED_PARAM(identityProperties);
44+
AWS_UNREFERENCED_PARAM(additionalParameters);
45+
46+
auto legacyCreds = legacyChain_sp->GetAWSCredentials();
47+
48+
auto smithyCreds = Aws::MakeUnique<AwsCredentialIdentity>(
49+
"DefaultAwsCredentialIdentityResolver", legacyCreds.GetAWSAccessKeyId(), legacyCreds.GetAWSSecretKey(),
50+
legacyCreds.GetSessionToken().empty() ? Aws::Crt::Optional<Aws::String>() : legacyCreds.GetSessionToken(),
51+
legacyCreds.GetExpiration(), legacyCreds.GetAccountId().empty() ? Aws::Crt::Optional<Aws::String>() : legacyCreds.GetAccountId());
52+
53+
return ResolveIdentityFutureOutcome(std::move(smithyCreds));
54+
}
55+
};
56+
} // namespace smithy

tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/smithy/SmithyClientSourceInit.vm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ ${className}::${className}(const ${clientConfiguration}& clientConfiguration,
6969
{
7070
#if($serviceModel.metadata.serviceId == "S3")
7171
[&]() -> Aws::UnorderedMap<Aws::String, ${rootNamespace}::Crt::Variant<${AuthSchemeVariants}> > {
72-
auto credsResolver = Aws::MakeShared<smithy::DefaultAwsCredentialIdentityResolver>(ALLOCATION_TAG);
72+
auto credsResolver = Aws::MakeShared<smithy::DefaultAwsCredentialIdentityResolver>(ALLOCATION_TAG, clientConfiguration.credentialProviderConfig);
7373
return {
7474
#foreach($entry in $AuthSchemeMapEntries)
7575
#if($AuthSchemes && $AuthSchemes[$foreach.index] == $s3_express_auth)
@@ -82,7 +82,7 @@ ${className}::${className}(const ${clientConfiguration}& clientConfiguration,
8282
}()
8383
#else
8484
#foreach($entry in $AuthSchemeMapEntries)
85-
{${entry}{GetServiceName(), clientConfiguration.region}},
85+
{${entry}{GetServiceName(), clientConfiguration.region, clientConfiguration.credentialProviderConfig}},
8686
#end
8787
#end
8888
})
@@ -188,7 +188,7 @@ ${className}::${className}(const Client::ClientConfiguration& clientConfiguratio
188188
Aws::MakeShared<${AuthSchemeResolver}>(ALLOCATION_TAG),
189189
{
190190
[&]() -> Aws::UnorderedMap<Aws::String, ${rootNamespace}::Crt::Variant<${AuthSchemeVariants}> > {
191-
auto credsResolver = Aws::MakeShared<smithy::DefaultAwsCredentialIdentityResolver>(ALLOCATION_TAG);
191+
auto credsResolver = Aws::MakeShared<smithy::DefaultAwsCredentialIdentityResolver>(ALLOCATION_TAG, clientConfiguration.credentialProviderConfig);
192192
return {
193193
#foreach($entry in $AuthSchemeMapEntries)
194194
#if($AuthSchemes && $AuthSchemes[$foreach.index] == $s3_express_auth)
@@ -271,7 +271,7 @@ ${className}::${className}(const ${className} &rhs) :
271271
Aws::Client::ClientWithAsyncTemplateMethods<S3Client>(), AwsSmithyClientT(rhs) {
272272
m_authSchemes =
273273
[&]() -> Aws::UnorderedMap<Aws::String, ${rootNamespace}::Crt::Variant<${AuthSchemeVariants}> > {
274-
auto credsResolver = Aws::MakeShared<smithy::DefaultAwsCredentialIdentityResolver>(ALLOCATION_TAG);
274+
auto credsResolver = Aws::MakeShared<smithy::DefaultAwsCredentialIdentityResolver>(ALLOCATION_TAG, clientConfiguration.credentialProviderConfig);
275275
return {
276276
#foreach($entry in $AuthSchemeMapEntries)
277277
#if($AuthSchemes && $AuthSchemes[$foreach.index] == $s3_express_auth)
@@ -304,7 +304,7 @@ ${className}::${className}(const Client::ClientConfiguration& clientConfiguratio
304304
#if($entry.contains("smithy::BearerTokenAuthScheme"))
305305
{${entry}{Aws::MakeShared<smithy::AwsBearerTokenIdentityResolver>(ALLOCATION_TAG), GetServiceName(), clientConfiguration.region}},
306306
#else
307-
{$entry{Aws::MakeShared<smithy::DefaultAwsCredentialIdentityResolver>(ALLOCATION_TAG), GetServiceName(), clientConfiguration.region}},
307+
{$entry{Aws::MakeShared<smithy::DefaultAwsCredentialIdentityResolver>(ALLOCATION_TAG, clientConfiguration.credentialProviderConfig), GetServiceName(), clientConfiguration.region}},
308308
#end
309309
#end
310310
})

0 commit comments

Comments
 (0)