Skip to content

Commit 0f4e562

Browse files
committed
Revert "Delegate CRT credentials (#2020)"
This reverts commit de25252.
1 parent 0d94287 commit 0f4e562

File tree

4 files changed

+64
-64
lines changed

4 files changed

+64
-64
lines changed

aws-cpp-sdk-s3-crt/include/aws/s3-crt/S3CrtClient.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5178,7 +5178,7 @@ namespace Aws
51785178
Aws::Client::StreamOutcome GenerateStreamOutcome(const std::shared_ptr<Http::HttpResponse>& response) const;
51795179

51805180
private:
5181-
void init(const S3Crt::ClientConfiguration& clientConfiguration, const std::shared_ptr<Aws::Auth::AWSCredentialsProvider> credentialsProvider);
5181+
void init(const S3Crt::ClientConfiguration& clientConfiguration, const Aws::Auth::AWSCredentials* credentials = nullptr);
51825182

51835183
struct CrtClientShutdownCallbackDataWrapper {
51845184
void *data;
@@ -5305,8 +5305,6 @@ namespace Aws
53055305
struct CrtClientShutdownCallbackDataWrapper m_wrappedData;
53065306
std::shared_ptr<Aws::Utils::Threading::Semaphore> m_clientShutdownSem;
53075307
Aws::String m_userAgent;
5308-
std::shared_ptr<Aws::Auth::AWSCredentialsProvider> m_credProvider;
5309-
std::shared_ptr<Aws::Crt::Auth::ICredentialsProvider> m_crtCredProvider;
53105308
bool m_useVirtualAddressing;
53115309
bool m_useDualStack;
53125310
bool m_useArnRegion;

aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,22 @@ static const char* ALLOCATION_TAG = "S3CrtClient";
143143

144144
S3CrtClient::S3CrtClient(const S3Crt::ClientConfiguration& clientConfiguration, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy signPayloads, bool useVirtualAddressing, Aws::S3Crt::US_EAST_1_REGIONAL_ENDPOINT_OPTION USEast1RegionalEndPointOption) :
145145
BASECLASS(clientConfiguration,
146-
Aws::MakeShared<Aws::Auth::DefaultAuthSignerProvider>(ALLOCATION_TAG, m_credProvider,
146+
Aws::MakeShared<Aws::Auth::DefaultAuthSignerProvider>(ALLOCATION_TAG, Aws::MakeShared<DefaultAWSCredentialsProviderChain>(ALLOCATION_TAG),
147147
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region), signPayloads, false),
148148
Aws::MakeShared<S3CrtErrorMarshaller>(ALLOCATION_TAG)),
149-
m_executor(clientConfiguration.executor), m_credProvider(Aws::MakeShared<DefaultAWSCredentialsProviderChain>(ALLOCATION_TAG)), m_useVirtualAddressing(useVirtualAddressing), m_USEast1RegionalEndpointOption(USEast1RegionalEndPointOption)
149+
m_executor(clientConfiguration.executor), m_useVirtualAddressing(useVirtualAddressing), m_USEast1RegionalEndpointOption(USEast1RegionalEndPointOption)
150150
{
151-
init(clientConfiguration, m_credProvider);
151+
init(clientConfiguration);
152152
}
153153

154154
S3CrtClient::S3CrtClient(const AWSCredentials& credentials, const S3Crt::ClientConfiguration& clientConfiguration, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy signPayloads, bool useVirtualAddressing, Aws::S3Crt::US_EAST_1_REGIONAL_ENDPOINT_OPTION USEast1RegionalEndPointOption) :
155155
BASECLASS(clientConfiguration,
156-
Aws::MakeShared<Aws::Auth::DefaultAuthSignerProvider>(ALLOCATION_TAG, m_credProvider,
156+
Aws::MakeShared<Aws::Auth::DefaultAuthSignerProvider>(ALLOCATION_TAG, Aws::MakeShared<SimpleAWSCredentialsProvider>(ALLOCATION_TAG, credentials),
157157
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region), signPayloads, false),
158158
Aws::MakeShared<S3CrtErrorMarshaller>(ALLOCATION_TAG)),
159-
m_executor(clientConfiguration.executor), m_credProvider(Aws::MakeShared<SimpleAWSCredentialsProvider>(ALLOCATION_TAG, credentials)), m_useVirtualAddressing(useVirtualAddressing), m_USEast1RegionalEndpointOption(USEast1RegionalEndPointOption)
159+
m_executor(clientConfiguration.executor), m_useVirtualAddressing(useVirtualAddressing), m_USEast1RegionalEndpointOption(USEast1RegionalEndPointOption)
160160
{
161-
init(clientConfiguration, m_credProvider);
161+
init(clientConfiguration, &credentials);
162162
}
163163

164164
S3CrtClient::S3CrtClient(const std::shared_ptr<AWSCredentialsProvider>& credentialsProvider,
@@ -167,9 +167,10 @@ S3CrtClient::S3CrtClient(const std::shared_ptr<AWSCredentialsProvider>& credenti
167167
Aws::MakeShared<Aws::Auth::DefaultAuthSignerProvider>(ALLOCATION_TAG, credentialsProvider,
168168
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region), signPayloads, false),
169169
Aws::MakeShared<S3CrtErrorMarshaller>(ALLOCATION_TAG)),
170-
m_executor(clientConfiguration.executor), m_credProvider(credentialsProvider), m_useVirtualAddressing(useVirtualAddressing), m_USEast1RegionalEndpointOption(USEast1RegionalEndPointOption)
170+
m_executor(clientConfiguration.executor), m_useVirtualAddressing(useVirtualAddressing), m_USEast1RegionalEndpointOption(USEast1RegionalEndPointOption)
171171
{
172-
init(clientConfiguration, m_credProvider);
172+
Aws::Auth::AWSCredentials credentials = credentialsProvider->GetAWSCredentials();
173+
init(clientConfiguration, &credentials);
173174
}
174175

175176
S3CrtClient::~S3CrtClient()
@@ -178,7 +179,7 @@ S3CrtClient::~S3CrtClient()
178179
m_clientShutdownSem->WaitOne(); // Wait aws_s3_client shutdown
179180
}
180181

181-
void S3CrtClient::init(const S3Crt::ClientConfiguration& config, const std::shared_ptr<Aws::Auth::AWSCredentialsProvider> credentialsProvider)
182+
void S3CrtClient::init(const S3Crt::ClientConfiguration& config, const Aws::Auth::AWSCredentials* credentials)
182183
{
183184
SetServiceClientName("S3");
184185
LoadS3CrtSpecificConfig(config.profileName);
@@ -204,18 +205,23 @@ void S3CrtClient::init(const S3Crt::ClientConfiguration& config, const std::shar
204205
Aws::Crt::Io::ClientBootstrap* clientBootstrap = config.clientBootstrap ? config.clientBootstrap.get() : Aws::GetDefaultClientBootstrap();
205206
s3CrtConfig.client_bootstrap = clientBootstrap->GetUnderlyingHandle();
206207

207-
m_crtCredProvider = Aws::Crt::Auth::CredentialsProvider::CreateCredentialsProviderDelegate({
208-
std::bind([](const std::shared_ptr<AWSCredentialsProvider>& provider) {
209-
AWSCredentials credentials = provider->GetAWSCredentials();
210-
return Aws::MakeShared<Aws::Crt::Auth::Credentials>(ALLOCATION_TAG,
211-
*Aws::MakeShared<Aws::Crt::ByteCursor>(ALLOCATION_TAG, Aws::Crt::ByteCursorFromCString(credentials.GetAWSAccessKeyId().c_str())),
212-
*Aws::MakeShared<Aws::Crt::ByteCursor>(ALLOCATION_TAG, Aws::Crt::ByteCursorFromCString(credentials.GetAWSSecretKey().c_str())),
213-
*Aws::MakeShared<Aws::Crt::ByteCursor>(ALLOCATION_TAG, Aws::Crt::ByteCursorFromCString(credentials.GetSessionToken().c_str())),
214-
credentials.GetExpiration().Millis());
215-
}, credentialsProvider)
216-
});
217-
218-
aws_s3_init_default_signing_config(&m_s3CrtSigningConfig, Aws::Crt::ByteCursorFromCString(config.region.c_str()), m_crtCredProvider->GetUnderlyingHandle());
208+
std::shared_ptr<Aws::Crt::Auth::ICredentialsProvider> provider(nullptr);
209+
if (credentials)
210+
{
211+
Aws::Crt::Auth::CredentialsProviderStaticConfig staticCreds;
212+
staticCreds.AccessKeyId = Aws::Crt::ByteCursorFromCString(credentials->GetAWSAccessKeyId().c_str());
213+
staticCreds.SecretAccessKey = Aws::Crt::ByteCursorFromCString(credentials->GetAWSSecretKey().c_str());
214+
staticCreds.SessionToken = Aws::Crt::ByteCursorFromCString(credentials->GetSessionToken().c_str());
215+
provider = Aws::Crt::Auth::CredentialsProvider::CreateCredentialsProviderStatic(staticCreds);
216+
}
217+
else
218+
{
219+
Aws::Crt::Auth::CredentialsProviderChainDefaultConfig credsConfig;
220+
credsConfig.Bootstrap = clientBootstrap;
221+
provider = Aws::Crt::Auth::CredentialsProvider::CreateCredentialsProviderChainDefault(credsConfig);
222+
}
223+
224+
aws_s3_init_default_signing_config(&m_s3CrtSigningConfig, Aws::Crt::ByteCursorFromCString(config.region.c_str()), provider->GetUnderlyingHandle());
219225
m_s3CrtSigningConfig.flags.use_double_uri_encode = false;
220226
s3CrtConfig.signing_config = &m_s3CrtSigningConfig;
221227

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

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,15 @@
3434
#end
3535
#if($serviceNamespace == "S3Crt")
3636
#set($clientConfigurationNamespace = $serviceNamespace)
37-
#set($credentialsParam = ", m_credProvider")
38-
#set($credentialsArg = ", const std::shared_ptr<Aws::Auth::AWSCredentialsProvider> credentialsProvider")
39-
#set($defaultCredentialsProviderChainParam = "m_credProvider")
40-
#set($defaultCredentialsProviderChainMember = ", m_credProvider(Aws::MakeShared<DefaultAWSCredentialsProviderChain>(ALLOCATION_TAG))")
41-
#set($simpleCredentialsProviderParam = "m_credProvider")
42-
#set($simpleCredentialsProviderMember = ", m_credProvider(Aws::MakeShared<SimpleAWSCredentialsProvider>(ALLOCATION_TAG, credentials))")
43-
#set($credentialsProviderMember = ", m_credProvider(credentialsProvider)")
37+
#set($credentialsParam = ", &credentials")
38+
#set($getAWSCredentials = "Aws::Auth::AWSCredentials credentials = credentialsProvider->GetAWSCredentials();
39+
")
40+
#set($credentialsArg = ", const Aws::Auth::AWSCredentials* credentials")
4441
#else
4542
#set($clientConfigurationNamespace = "Client")
4643
#set($credentialsParam = "")
44+
#set($getAWSCredentials = "")
4745
#set($credentialsArg = "")
48-
#set($defaultCredentialsProviderChainParam = "Aws::MakeShared<DefaultAWSCredentialsProviderChain>(ALLOCATION_TAG)")
49-
#set($defaultCredentialsProviderChainMember = "")
50-
#set($simpleCredentialsProviderParam = "Aws::MakeShared<SimpleAWSCredentialsProvider>(ALLOCATION_TAG, credentials)")
51-
#set($simpleCredentialsProviderMember = "")
52-
#set($credentialsProviderMember = "")
5346
#end
5447
#set($hasEventStreamInputOperation = false)
5548
#foreach($operation in $serviceModel.operations)
@@ -61,20 +54,20 @@
6154
#if($hasEventStreamInputOperation || $multiRegionAccessPointSupported)
6255
${className}::${className}(const ${clientConfigurationNamespace}::ClientConfiguration& clientConfiguration${signPayloads}${virtualAddressing}${USEast1RegionalEndpointArgString}) :
6356
BASECLASS(clientConfiguration,
64-
Aws::MakeShared<Aws::Auth::DefaultAuthSignerProvider>(ALLOCATION_TAG, ${defaultCredentialsProviderChainParam},
57+
Aws::MakeShared<Aws::Auth::DefaultAuthSignerProvider>(ALLOCATION_TAG, Aws::MakeShared<DefaultAWSCredentialsProviderChain>(ALLOCATION_TAG),
6558
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)${signPayloadsParam}${doubleEncodeValue}),
6659
Aws::MakeShared<${metadata.classNamePrefix}ErrorMarshaller>(ALLOCATION_TAG)),
67-
m_executor(clientConfiguration.executor)${defaultCredentialsProviderChainMember}${virtualAddressingInit}${USEast1RegionalEndpointInitString}
60+
m_executor(clientConfiguration.executor)${virtualAddressingInit}${USEast1RegionalEndpointInitString}
6861
{
69-
init(clientConfiguration${credentialsParam});
62+
init(clientConfiguration);
7063
}
7164

7265
${className}::${className}(const AWSCredentials& credentials, const ${clientConfigurationNamespace}::ClientConfiguration& clientConfiguration${signPayloads}${virtualAddressing}${USEast1RegionalEndpointArgString}) :
7366
BASECLASS(clientConfiguration,
74-
Aws::MakeShared<Aws::Auth::DefaultAuthSignerProvider>(ALLOCATION_TAG, ${simpleCredentialsProviderParam},
67+
Aws::MakeShared<Aws::Auth::DefaultAuthSignerProvider>(ALLOCATION_TAG, Aws::MakeShared<SimpleAWSCredentialsProvider>(ALLOCATION_TAG, credentials),
7568
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)${signPayloadsParam}${doubleEncodeValue}),
7669
Aws::MakeShared<${metadata.classNamePrefix}ErrorMarshaller>(ALLOCATION_TAG)),
77-
m_executor(clientConfiguration.executor)${simpleCredentialsProviderMember}${virtualAddressingInit}${USEast1RegionalEndpointInitString}
70+
m_executor(clientConfiguration.executor)${virtualAddressingInit}${USEast1RegionalEndpointInitString}
7871
{
7972
init(clientConfiguration${credentialsParam});
8073
}
@@ -85,27 +78,27 @@ ${className}::${className}(const std::shared_ptr<AWSCredentialsProvider>& creden
8578
Aws::MakeShared<Aws::Auth::DefaultAuthSignerProvider>(ALLOCATION_TAG, credentialsProvider,
8679
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)${signPayloadsParam}${doubleEncodeValue}),
8780
Aws::MakeShared<${metadata.classNamePrefix}ErrorMarshaller>(ALLOCATION_TAG)),
88-
m_executor(clientConfiguration.executor)${credentialsProviderMember}${virtualAddressingInit}${USEast1RegionalEndpointInitString}
81+
m_executor(clientConfiguration.executor)${virtualAddressingInit}${USEast1RegionalEndpointInitString}
8982
{
90-
init(clientConfiguration${credentialsParam});
83+
${getAWSCredentials}init(clientConfiguration${credentialsParam});
9184
}
9285
#else
9386
${className}::${className}(const ${clientConfigurationNamespace}::ClientConfiguration& clientConfiguration${signPayloads}${virtualAddressing}${USEast1RegionalEndpointArgString}) :
9487
BASECLASS(clientConfiguration,
95-
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, ${defaultCredentialsProviderChainParam},
88+
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, Aws::MakeShared<DefaultAWSCredentialsProviderChain>(ALLOCATION_TAG),
9689
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)${signPayloadsParam}${doubleEncodeValue}),
9790
Aws::MakeShared<${metadata.classNamePrefix}ErrorMarshaller>(ALLOCATION_TAG)),
98-
m_executor(clientConfiguration.executor)${defaultCredentialsProviderChainMember}${virtualAddressingInit}${USEast1RegionalEndpointInitString}
91+
m_executor(clientConfiguration.executor)${virtualAddressingInit}${USEast1RegionalEndpointInitString}
9992
{
100-
init(clientConfiguration${credentialsParam});
93+
init(clientConfiguration);
10194
}
10295

10396
${className}::${className}(const AWSCredentials& credentials, const ${clientConfigurationNamespace}::ClientConfiguration& clientConfiguration${signPayloads}${virtualAddressing}${USEast1RegionalEndpointArgString}) :
10497
BASECLASS(clientConfiguration,
105-
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, ${simpleCredentialsProviderParam},
98+
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, Aws::MakeShared<SimpleAWSCredentialsProvider>(ALLOCATION_TAG, credentials),
10699
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)${signPayloadsParam}${doubleEncodeValue}),
107100
Aws::MakeShared<${metadata.classNamePrefix}ErrorMarshaller>(ALLOCATION_TAG)),
108-
m_executor(clientConfiguration.executor)${simpleCredentialsProviderMember}${virtualAddressingInit}${USEast1RegionalEndpointInitString}
101+
m_executor(clientConfiguration.executor)${virtualAddressingInit}${USEast1RegionalEndpointInitString}
109102
{
110103
init(clientConfiguration${credentialsParam});
111104
}
@@ -116,9 +109,9 @@ ${className}::${className}(const std::shared_ptr<AWSCredentialsProvider>& creden
116109
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, credentialsProvider,
117110
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)${signPayloadsParam}${doubleEncodeValue}),
118111
Aws::MakeShared<${metadata.classNamePrefix}ErrorMarshaller>(ALLOCATION_TAG)),
119-
m_executor(clientConfiguration.executor)${virtualAddressingInit}${USEast1RegionalEndpointInitString}${credentialsProviderMember}
112+
m_executor(clientConfiguration.executor)${virtualAddressingInit}${USEast1RegionalEndpointInitString}
120113
{
121-
init(clientConfiguration${credentialsParam});
114+
${getAWSCredentials}init(clientConfiguration${credentialsParam});
122115
}
123116
#end
124117

@@ -198,18 +191,23 @@ void ${className}::init(const ${clientConfigurationNamespace}::ClientConfigurati
198191
Aws::Crt::Io::ClientBootstrap* clientBootstrap = config.clientBootstrap ? config.clientBootstrap.get() : Aws::GetDefaultClientBootstrap();
199192
s3CrtConfig.client_bootstrap = clientBootstrap->GetUnderlyingHandle();
200193

201-
m_crtCredProvider = Aws::Crt::Auth::CredentialsProvider::CreateCredentialsProviderDelegate({
202-
std::bind([](const std::shared_ptr<AWSCredentialsProvider>& provider) {
203-
AWSCredentials credentials = provider->GetAWSCredentials();
204-
return Aws::MakeShared<Aws::Crt::Auth::Credentials>(ALLOCATION_TAG,
205-
*Aws::MakeShared<Aws::Crt::ByteCursor>(ALLOCATION_TAG, Aws::Crt::ByteCursorFromCString(credentials.GetAWSAccessKeyId().c_str())),
206-
*Aws::MakeShared<Aws::Crt::ByteCursor>(ALLOCATION_TAG, Aws::Crt::ByteCursorFromCString(credentials.GetAWSSecretKey().c_str())),
207-
*Aws::MakeShared<Aws::Crt::ByteCursor>(ALLOCATION_TAG, Aws::Crt::ByteCursorFromCString(credentials.GetSessionToken().c_str())),
208-
credentials.GetExpiration().Millis());
209-
}, credentialsProvider)
210-
});
194+
std::shared_ptr<Aws::Crt::Auth::ICredentialsProvider> provider(nullptr);
195+
if (credentials)
196+
{
197+
Aws::Crt::Auth::CredentialsProviderStaticConfig staticCreds;
198+
staticCreds.AccessKeyId = Aws::Crt::ByteCursorFromCString(credentials->GetAWSAccessKeyId().c_str());
199+
staticCreds.SecretAccessKey = Aws::Crt::ByteCursorFromCString(credentials->GetAWSSecretKey().c_str());
200+
staticCreds.SessionToken = Aws::Crt::ByteCursorFromCString(credentials->GetSessionToken().c_str());
201+
provider = Aws::Crt::Auth::CredentialsProvider::CreateCredentialsProviderStatic(staticCreds);
202+
}
203+
else
204+
{
205+
Aws::Crt::Auth::CredentialsProviderChainDefaultConfig credsConfig;
206+
credsConfig.Bootstrap = clientBootstrap;
207+
provider = Aws::Crt::Auth::CredentialsProvider::CreateCredentialsProviderChainDefault(credsConfig);
208+
}
211209

212-
aws_s3_init_default_signing_config(&m_s3CrtSigningConfig, Aws::Crt::ByteCursorFromCString(config.region.c_str()), m_crtCredProvider->GetUnderlyingHandle());
210+
aws_s3_init_default_signing_config(&m_s3CrtSigningConfig, Aws::Crt::ByteCursorFromCString(config.region.c_str()), provider->GetUnderlyingHandle());
213211
m_s3CrtSigningConfig.flags.use_double_uri_encode = false;
214212
s3CrtConfig.signing_config = &m_s3CrtSigningConfig;
215213

code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/s3/S3ClientHeader.vm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ namespace Aws
197197
#end
198198
private:
199199
#if($serviceNamespace == "S3Crt")
200-
void init(const S3Crt::ClientConfiguration& clientConfiguration, const std::shared_ptr<Aws::Auth::AWSCredentialsProvider> credentialsProvider);
200+
void init(const S3Crt::ClientConfiguration& clientConfiguration, const Aws::Auth::AWSCredentials* credentials = nullptr);
201201

202202
struct CrtClientShutdownCallbackDataWrapper {
203203
void *data;
@@ -236,8 +236,6 @@ namespace Aws
236236
struct CrtClientShutdownCallbackDataWrapper m_wrappedData;
237237
std::shared_ptr<Aws::Utils::Threading::Semaphore> m_clientShutdownSem;
238238
Aws::String m_userAgent;
239-
std::shared_ptr<Aws::Auth::AWSCredentialsProvider> m_credProvider;
240-
std::shared_ptr<Aws::Crt::Auth::ICredentialsProvider> m_crtCredProvider;
241239
#end
242240
bool m_useVirtualAddressing;
243241
bool m_useDualStack;

0 commit comments

Comments
 (0)