Skip to content

Commit ae59bf0

Browse files
committed
update user agent to 2.1
1 parent 8e41fd0 commit ae59bf0

File tree

18 files changed

+777
-78
lines changed

18 files changed

+777
-78
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ DynamoDBClient::DynamoDBClient(const DynamoDB::DynamoDBClientConfiguration& clie
109109
std::shared_ptr<DynamoDBEndpointProviderBase> endpointProvider) :
110110
AwsSmithyClientT(clientConfiguration,
111111
GetServiceName(),
112+
"DynamoDB",
112113
Aws::Http::CreateHttpClient(clientConfiguration),
113114
Aws::MakeShared<DynamoDBErrorMarshaller>(ALLOCATION_TAG),
114115
endpointProvider ? endpointProvider : Aws::MakeShared<DynamoDBEndpointProvider>(ALLOCATION_TAG),
@@ -123,6 +124,7 @@ DynamoDBClient::DynamoDBClient(const AWSCredentials& credentials,
123124
const DynamoDB::DynamoDBClientConfiguration& clientConfiguration) :
124125
AwsSmithyClientT(clientConfiguration,
125126
GetServiceName(),
127+
"DynamoDB",
126128
Aws::Http::CreateHttpClient(clientConfiguration),
127129
Aws::MakeShared<DynamoDBErrorMarshaller>(ALLOCATION_TAG),
128130
endpointProvider ? endpointProvider : Aws::MakeShared<DynamoDBEndpointProvider>(ALLOCATION_TAG),
@@ -137,6 +139,7 @@ DynamoDBClient::DynamoDBClient(const std::shared_ptr<AWSCredentialsProvider>& cr
137139
const DynamoDB::DynamoDBClientConfiguration& clientConfiguration) :
138140
AwsSmithyClientT(clientConfiguration,
139141
GetServiceName(),
142+
"DynamoDB",
140143
Aws::Http::CreateHttpClient(clientConfiguration),
141144
Aws::MakeShared<DynamoDBErrorMarshaller>(ALLOCATION_TAG),
142145
endpointProvider ? endpointProvider : Aws::MakeShared<DynamoDBEndpointProvider>(ALLOCATION_TAG),
@@ -150,6 +153,7 @@ DynamoDBClient::DynamoDBClient(const std::shared_ptr<AWSCredentialsProvider>& cr
150153
DynamoDBClient::DynamoDBClient(const Client::ClientConfiguration& clientConfiguration) :
151154
AwsSmithyClientT(clientConfiguration,
152155
GetServiceName(),
156+
"DynamoDB",
153157
Aws::Http::CreateHttpClient(clientConfiguration),
154158
Aws::MakeShared<DynamoDBErrorMarshaller>(ALLOCATION_TAG),
155159
Aws::MakeShared<DynamoDBEndpointProvider>(ALLOCATION_TAG),
@@ -163,6 +167,7 @@ DynamoDBClient::DynamoDBClient(const AWSCredentials& credentials,
163167
const Client::ClientConfiguration& clientConfiguration) :
164168
AwsSmithyClientT(clientConfiguration,
165169
GetServiceName(),
170+
"DynamoDB",
166171
Aws::Http::CreateHttpClient(clientConfiguration),
167172
Aws::MakeShared<DynamoDBErrorMarshaller>(ALLOCATION_TAG),
168173
Aws::MakeShared<DynamoDBEndpointProvider>(ALLOCATION_TAG),
@@ -176,6 +181,7 @@ DynamoDBClient::DynamoDBClient(const std::shared_ptr<AWSCredentialsProvider>& cr
176181
const Client::ClientConfiguration& clientConfiguration) :
177182
AwsSmithyClientT(clientConfiguration,
178183
GetServiceName(),
184+
"DynamoDB",
179185
Aws::Http::CreateHttpClient(clientConfiguration),
180186
Aws::MakeShared<DynamoDBErrorMarshaller>(ALLOCATION_TAG),
181187
Aws::MakeShared<DynamoDBEndpointProvider>(ALLOCATION_TAG),

src/aws-cpp-sdk-core/include/aws/core/AmazonWebServiceRequest.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <aws/core/Core_EXPORTS.h>
99

1010
#include <aws/core/client/RequestCompression.h>
11+
#include <aws/core/client/UserAgent.h>
1112
#include <aws/core/auth/AWSAuthSigner.h>
1213
#include <aws/core/client/CoreErrors.h>
1314
#include <aws/core/endpoint/EndpointParameter.h>
@@ -203,6 +204,18 @@ namespace Aws
203204
virtual Aws::Client::CompressionAlgorithm
204205
GetSelectedCompressionAlgorithm(Aws::Client::RequestCompressionConfig) const { return Aws::Client::CompressionAlgorithm::NONE; }
205206

207+
/**
208+
* Adds a used feature to the user agent string for the request.
209+
* @param feature the feature to be added in the user agent string.
210+
*/
211+
void AddUserAgentFeature(Aws::Client::UserAgentFeature feature) { m_userAgentFeatures.insert(feature); }
212+
213+
/**
214+
* Gets all features that would be included in the requests user agent string.
215+
* @return a set of features that will be included in the user agent associated with this request.
216+
*/
217+
Aws::Set<Aws::Client::UserAgentFeature> GetUserAgentFeatures() const { return m_userAgentFeatures; }
218+
206219
protected:
207220
/**
208221
* Default does nothing. Override this to convert what would otherwise be the payload of the
@@ -221,6 +234,7 @@ namespace Aws
221234
RequestSignedHandler m_onRequestSigned;
222235
RequestRetryHandler m_requestRetryHandler;
223236
mutable std::shared_ptr<Aws::Http::ServiceSpecificParameters> m_serviceSpecificParameters;
237+
Aws::Set<Client::UserAgentFeature> m_userAgentFeatures;
224238
};
225239

226240
} // namespace Aws

src/aws-cpp-sdk-core/include/aws/core/client/AWSClient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <aws/core/utils/crypto/Hash.h>
1717
#include <aws/core/auth/AWSAuthSignerProvider.h>
1818
#include <aws/core/endpoint/AWSEndpoint.h>
19+
#include <smithy/client/features/UserAgentInterceptor.h>
1920
#include <smithy/interceptor/Interceptor.h>
2021
#include <memory>
2122
#include <atomic>
@@ -341,20 +342,19 @@ namespace Aws
341342
void AddHeadersToRequest(const std::shared_ptr<Aws::Http::HttpRequest>& httpRequest, const Http::HeaderValueCollection& headerValues) const;
342343
void AddContentBodyToRequest(const std::shared_ptr<Aws::Http::HttpRequest>& httpRequest, const std::shared_ptr<Aws::IOStream>& body,
343344
bool needsContentMd5 = false, bool isChunked = false) const;
344-
void AddCommonHeaders(Aws::Http::HttpRequest& httpRequest) const;
345345
void AppendHeaderValueToRequest(const std::shared_ptr<Http::HttpRequest> &request, String header, String value) const;
346346

347347
std::shared_ptr<Aws::Http::HttpClient> m_httpClient;
348348
std::shared_ptr<AWSErrorMarshaller> m_errorMarshaller;
349349
std::shared_ptr<RetryStrategy> m_retryStrategy;
350350
std::shared_ptr<Aws::Utils::RateLimits::RateLimiterInterface> m_writeRateLimiter;
351351
std::shared_ptr<Aws::Utils::RateLimits::RateLimiterInterface> m_readRateLimiter;
352-
Aws::String m_userAgent;
353352
std::shared_ptr<Aws::Utils::Crypto::Hash> m_hash;
354353
long m_requestTimeoutMs;
355354
bool m_enableClockSkewAdjustment;
356355
Aws::String m_serviceName = "AWSBaseClient";
357356
Aws::Client::RequestCompressionConfig m_requestCompressionConfig;
357+
std::shared_ptr<smithy::client::UserAgentInterceptor> m_userAgentInterceptor;
358358
Aws::Vector<std::shared_ptr<smithy::interceptor::Interceptor>> m_interceptors;
359359
};
360360

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
#include <aws/core/client/ClientConfiguration.h>
7+
#include <aws/core/client/RetryStrategy.h>
8+
#include <aws/core/utils/memory/stl/AWSSet.h>
9+
10+
namespace Aws {
11+
namespace Client {
12+
13+
enum class UserAgentFeature {
14+
RETRY_MODE_LEGACY,
15+
RETRY_MODE_STANDARD,
16+
RETRY_MODE_ADAPTIVE,
17+
S3_TRANSFER,
18+
S3_CRYPTO_V1N,
19+
S3_CRYPTO_V2,
20+
};
21+
22+
class AWS_CORE_API UserAgent {
23+
public:
24+
explicit UserAgent(const ClientConfiguration& clientConfiguration, const Aws::String& retryStrategyName, const Aws::String& apiName);
25+
Aws::String SerializeWithFeatures(const Aws::Set<UserAgentFeature>& features) const;
26+
void SetApiName(const Aws::String& apiName) { m_api = apiName; }
27+
void AddLegacyFeature(const Aws::String& legacyFeature);
28+
29+
private:
30+
const Aws::String m_sdkVersion;
31+
const Aws::String m_userAgentVersion;
32+
Aws::String m_api;
33+
const Aws::String m_crtVersion;
34+
const Aws::String m_osVersion;
35+
const Aws::String m_archName;
36+
const Aws::String m_cppVersion;
37+
const Aws::String m_compilerMetadata;
38+
const Aws::String m_retryStrategyName;
39+
const Aws::String m_execEnv;
40+
const Aws::String m_appId;
41+
const Aws::String m_customizations;
42+
Aws::Set<UserAgentFeature> m_features;
43+
};
44+
} // namespace Client
45+
} // namespace Aws

src/aws-cpp-sdk-core/include/smithy/client/AwsSmithyClient.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,19 @@ namespace client
3636
public:
3737
static_assert(std::is_base_of<Aws::Client::AWSErrorMarshaller, ErrorMarshallerT>::value, "MarshallerT must be derived from class Aws::Client::AWSErrorMarshaller");
3838

39-
explicit AwsSmithyClientT(const ServiceClientConfigurationT& clientConfig, const Aws::String& serviceName,
39+
explicit AwsSmithyClientT(const ServiceClientConfigurationT& clientConfig,
40+
const Aws::String& serviceName,
41+
const Aws::String& serviceUserAgentName,
4042
const std::shared_ptr<Aws::Http::HttpClient>& httpClient,
4143
const std::shared_ptr<Aws::Client::AWSErrorMarshaller>& errorMarshaller,
4244
const std::shared_ptr<EndpointProviderT> endpointProvider,
4345
const std::shared_ptr<ServiceAuthSchemeResolverT>& authSchemeResolver,
4446
const Aws::UnorderedMap<Aws::String, AuthSchemesVariantT>& authSchemes)
45-
: AwsSmithyClientBase(Aws::MakeUnique<ServiceClientConfigurationT>(ServiceNameT, clientConfig), serviceName, httpClient, errorMarshaller),
47+
: AwsSmithyClientBase(Aws::MakeUnique<ServiceClientConfigurationT>(ServiceNameT, clientConfig),
48+
serviceName,
49+
serviceUserAgentName,
50+
httpClient,
51+
errorMarshaller),
4652
m_clientConfiguration(*static_cast<ServiceClientConfigurationT*>(AwsSmithyClientBase::m_clientConfig.get())),
4753
m_endpointProvider(endpointProvider),
4854
m_authSchemeResolver(authSchemeResolver),
@@ -57,6 +63,7 @@ namespace client
5763
AwsSmithyClientBase(other,
5864
Aws::MakeUnique<ServiceClientConfigurationT>(ServiceNameT, other.m_clientConfiguration),
5965
ServiceNameT,
66+
other.m_serviceUserAgentName,
6067
Aws::Http::CreateHttpClient(other.m_clientConfiguration),
6168
Aws::MakeShared<ErrorMarshallerT>(ServiceNameT)),
6269
m_clientConfiguration{*static_cast<ServiceClientConfigurationT*>(m_clientConfig.get())},

src/aws-cpp-sdk-core/include/smithy/client/AwsSmithyClientBase.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <smithy/tracing/TelemetryProvider.h>
1010
#include <smithy/interceptor/Interceptor.h>
1111
#include <smithy/client/features/ChecksumInterceptor.h>
12+
#include <smithy/client/features/UserAgentInterceptor.h>
1213

1314
#include <aws/crt/Variant.h>
1415
#include <aws/core/client/ClientConfiguration.h>
@@ -85,11 +86,12 @@ namespace client
8586

8687
AwsSmithyClientBase(Aws::UniquePtr<Aws::Client::ClientConfiguration>&& clientConfig,
8788
Aws::String serviceName,
89+
Aws::String serviceUserAgentName,
8890
std::shared_ptr<Aws::Http::HttpClient> httpClient,
8991
std::shared_ptr<Aws::Client::AWSErrorMarshaller> errorMarshaller) :
9092
m_clientConfig(std::move(clientConfig)),
9193
m_serviceName(std::move(serviceName)),
92-
m_userAgent(),
94+
m_serviceUserAgentName(std::move(serviceUserAgentName)),
9395
m_httpClient(std::move(httpClient)),
9496
m_errorMarshaller(std::move(errorMarshaller)),
9597
m_interceptors{Aws::MakeShared<ChecksumInterceptor>("AwsSmithyClientBase")}
@@ -100,11 +102,12 @@ namespace client
100102
AwsSmithyClientBase(const AwsSmithyClientBase& other,
101103
Aws::UniquePtr<Aws::Client::ClientConfiguration>&& clientConfig,
102104
Aws::String serviceName,
105+
Aws::String serviceUserAgentName,
103106
std::shared_ptr<Aws::Http::HttpClient> httpClient,
104107
std::shared_ptr<Aws::Client::AWSErrorMarshaller> errorMarshaller) :
105108
m_clientConfig(std::move(clientConfig)),
106109
m_serviceName(std::move(serviceName)),
107-
m_userAgent(),
110+
m_serviceUserAgentName(std::move(serviceUserAgentName)),
108111
m_httpClient(std::move(httpClient)),
109112
m_errorMarshaller(std::move(errorMarshaller)),
110113
m_interceptors{Aws::MakeShared<ChecksumInterceptor>("AwsSmithyClientBase")}
@@ -181,7 +184,7 @@ namespace client
181184

182185
std::shared_ptr<Aws::Client::ClientConfiguration> m_clientConfig;
183186
Aws::String m_serviceName;
184-
Aws::String m_userAgent;
187+
Aws::String m_serviceUserAgentName;
185188

186189
std::shared_ptr<Aws::Http::HttpClient> m_httpClient;
187190
std::shared_ptr<Aws::Client::AWSErrorMarshaller> m_errorMarshaller;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
7+
#include <aws/core/client/ClientConfiguration.h>
8+
#include <aws/core/client/RetryStrategy.h>
9+
#include <aws/core/client/UserAgent.h>
10+
#include <smithy/interceptor/Interceptor.h>
11+
12+
#include <utility>
13+
14+
namespace smithy {
15+
namespace client {
16+
class UserAgentInterceptor : public interceptor::Interceptor {
17+
public:
18+
explicit UserAgentInterceptor(const Aws::Client::ClientConfiguration& configuration,
19+
const Aws::String& retryStrategyName,
20+
const Aws::String& apiName)
21+
: m_userAgent{configuration, retryStrategyName, apiName} {};
22+
UserAgentInterceptor(const UserAgentInterceptor& other) = delete;
23+
UserAgentInterceptor(UserAgentInterceptor&& other) noexcept = default;
24+
UserAgentInterceptor& operator=(const UserAgentInterceptor& other) = delete;
25+
UserAgentInterceptor& operator=(UserAgentInterceptor&& other) noexcept = delete;
26+
27+
ModifyRequestOutcome ModifyBeforeSigning(interceptor::InterceptorContext& context) override {
28+
auto transmitRequest = context.GetTransmitRequest();
29+
assert(transmitRequest);
30+
transmitRequest->SetUserAgent(m_userAgent.SerializeWithFeatures(context.GetModeledRequest().GetUserAgentFeatures()));
31+
return transmitRequest;
32+
}
33+
34+
ModifyResponseOutcome ModifyBeforeDeserialization(interceptor::InterceptorContext& context) override {
35+
return context.GetTransmitResponse();
36+
}
37+
38+
void SetApiName(const Aws::String& apiName) { m_userAgent.SetApiName(apiName); }
39+
40+
void AddLegacyFeaturesToUserAgent(const Aws::String& valueToAppend) { m_userAgent.AddLegacyFeature(valueToAppend); }
41+
42+
private:
43+
Aws::Client::UserAgent m_userAgent;
44+
};
45+
} // namespace client
46+
} // namespace smithy

src/aws-cpp-sdk-core/source/client/AWSClient.cpp

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration,
134134
m_retryStrategy(configuration.retryStrategy ? configuration.retryStrategy : configuration.configFactories.retryStrategyCreateFn()),
135135
m_writeRateLimiter(configuration.writeRateLimiter ? configuration.writeRateLimiter : configuration.configFactories.writeRateLimiterCreateFn()),
136136
m_readRateLimiter(configuration.readRateLimiter ? configuration.readRateLimiter : configuration.configFactories.readRateLimiterCreateFn()),
137-
m_userAgent(Aws::Client::ComputeUserAgentString(&configuration)),
138137
m_hash(Aws::Utils::Crypto::CreateMD5Implementation()),
139138
m_requestTimeoutMs(configuration.requestTimeoutMs),
140139
m_enableClockSkewAdjustment(configuration.enableClockSkewAdjustment),
141140
m_requestCompressionConfig(configuration.requestCompressionConfig),
142-
m_interceptors{Aws::MakeShared<smithy::client::ChecksumInterceptor>(AWS_CLIENT_LOG_TAG)}
141+
m_userAgentInterceptor{Aws::MakeShared<smithy::client::UserAgentInterceptor>(AWS_CLIENT_LOG_TAG, configuration, m_retryStrategy->GetStrategyName(), m_serviceName)},
142+
m_interceptors{Aws::MakeShared<smithy::client::ChecksumInterceptor>(AWS_CLIENT_LOG_TAG), m_userAgentInterceptor}
143143
{
144144
}
145145

@@ -160,13 +160,13 @@ AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration,
160160
m_retryStrategy(configuration.retryStrategy ? configuration.retryStrategy : configuration.configFactories.retryStrategyCreateFn()),
161161
m_writeRateLimiter(configuration.writeRateLimiter ? configuration.writeRateLimiter : configuration.configFactories.writeRateLimiterCreateFn()),
162162
m_readRateLimiter(configuration.readRateLimiter ? configuration.readRateLimiter : configuration.configFactories.readRateLimiterCreateFn()),
163-
m_userAgent(Aws::Client::ComputeUserAgentString(&configuration)),
164163
m_hash(Aws::Utils::Crypto::CreateMD5Implementation()),
165164
m_requestTimeoutMs(configuration.requestTimeoutMs),
166165
m_enableClockSkewAdjustment(configuration.enableClockSkewAdjustment),
167-
m_requestCompressionConfig(configuration.requestCompressionConfig)
166+
m_requestCompressionConfig(configuration.requestCompressionConfig),
167+
m_userAgentInterceptor{Aws::MakeShared<smithy::client::UserAgentInterceptor>(AWS_CLIENT_LOG_TAG, configuration, m_retryStrategy->GetStrategyName(), m_serviceName)},
168+
m_interceptors{Aws::MakeShared<smithy::client::ChecksumInterceptor>(AWS_CLIENT_LOG_TAG), m_userAgentInterceptor}
168169
{
169-
m_interceptors.emplace_back(Aws::MakeUnique<smithy::client::ChecksumInterceptor>(AWS_CLIENT_LOG_TAG));
170170
}
171171

172172
void AWSClient::DisableRequestProcessing()
@@ -182,17 +182,14 @@ void AWSClient::EnableRequestProcessing()
182182
void AWSClient::SetServiceClientName(const Aws::String& name)
183183
{
184184
m_serviceName = std::move(name);
185-
AppendToUserAgent("api/" + m_serviceName);
185+
assert(m_userAgentInterceptor);
186+
m_userAgentInterceptor->SetApiName(m_serviceName);
186187
}
187188

188189
void AWSClient::AppendToUserAgent(const Aws::String& valueToAppend)
189190
{
190-
Aws::String value = Aws::Client::FilterUserAgentToken(valueToAppend.c_str());
191-
if (value.empty())
192-
return;
193-
if (m_userAgent.find(value) != Aws::String::npos)
194-
return;
195-
m_userAgent += " " + std::move(value);
191+
assert(m_userAgentInterceptor);
192+
m_userAgentInterceptor->AddLegacyFeaturesToUserAgent(valueToAppend);
196193
}
197194

198195
Aws::Client::AWSAuthSigner* AWSClient::GetSignerByName(const char* name) const
@@ -632,9 +629,6 @@ HttpResponseOutcome AWSClient::AttemptOneRequest(const std::shared_ptr<Aws::Http
632629
return HttpResponseOutcome(AWSError<CoreErrors>(CoreErrors::CLIENT_SIGNING_FAILURE, "", "SDK failed to sign the request", false/*retryable*/));
633630
}
634631

635-
//user agent and headers like that shouldn't be signed for the sake of compatibility with proxies which MAY mutate that header.
636-
AddCommonHeaders(*httpRequest);
637-
638632
AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request Successfully signed");
639633
auto httpResponse = ::TracingUtils::MakeCallWithTiming<std::shared_ptr<HttpResponse>>(
640634
[&]() -> std::shared_ptr<HttpResponse> {
@@ -779,8 +773,6 @@ void AWSClient::AddHeadersToRequest(const std::shared_ptr<Aws::Http::HttpRequest
779773
{
780774
httpRequest->SetHeaderValue(headerValue.first, headerValue.second);
781775
}
782-
783-
AddCommonHeaders(*httpRequest);
784776
}
785777

786778
void AWSClient::AppendHeaderValueToRequest(const std::shared_ptr<Aws::Http::HttpRequest> &httpRequest, const String header, const String value) const
@@ -921,11 +913,6 @@ void AWSClient::BuildHttpRequest(const Aws::AmazonWebServiceRequest& request, co
921913
request.AddQueryStringParameters(httpRequest->GetUri());
922914
}
923915

924-
void AWSClient::AddCommonHeaders(Aws::Http::HttpRequest& httpRequest) const
925-
{
926-
httpRequest.SetUserAgent(m_userAgent);
927-
}
928-
929916
Aws::String AWSClient::GeneratePresignedUrl(const Aws::Http::URI& uri, Aws::Http::HttpMethod method, long long expirationInSeconds, const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameter)
930917
{
931918
return AWSUrlPresigner(*this).GeneratePresignedUrl(uri, method, expirationInSeconds, serviceSpecificParameter);

0 commit comments

Comments
 (0)