Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update user agent to 2.1 #3238

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions generated/src/aws-cpp-sdk-dynamodb/source/DynamoDBClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ DynamoDBClient::DynamoDBClient(const DynamoDB::DynamoDBClientConfiguration& clie
std::shared_ptr<DynamoDBEndpointProviderBase> endpointProvider) :
AwsSmithyClientT(clientConfiguration,
GetServiceName(),
"DynamoDB",
Aws::Http::CreateHttpClient(clientConfiguration),
Aws::MakeShared<DynamoDBErrorMarshaller>(ALLOCATION_TAG),
endpointProvider ? endpointProvider : Aws::MakeShared<DynamoDBEndpointProvider>(ALLOCATION_TAG),
Expand All @@ -123,6 +124,7 @@ DynamoDBClient::DynamoDBClient(const AWSCredentials& credentials,
const DynamoDB::DynamoDBClientConfiguration& clientConfiguration) :
AwsSmithyClientT(clientConfiguration,
GetServiceName(),
"DynamoDB",
Aws::Http::CreateHttpClient(clientConfiguration),
Aws::MakeShared<DynamoDBErrorMarshaller>(ALLOCATION_TAG),
endpointProvider ? endpointProvider : Aws::MakeShared<DynamoDBEndpointProvider>(ALLOCATION_TAG),
Expand All @@ -137,6 +139,7 @@ DynamoDBClient::DynamoDBClient(const std::shared_ptr<AWSCredentialsProvider>& cr
const DynamoDB::DynamoDBClientConfiguration& clientConfiguration) :
AwsSmithyClientT(clientConfiguration,
GetServiceName(),
"DynamoDB",
Aws::Http::CreateHttpClient(clientConfiguration),
Aws::MakeShared<DynamoDBErrorMarshaller>(ALLOCATION_TAG),
endpointProvider ? endpointProvider : Aws::MakeShared<DynamoDBEndpointProvider>(ALLOCATION_TAG),
Expand All @@ -150,6 +153,7 @@ DynamoDBClient::DynamoDBClient(const std::shared_ptr<AWSCredentialsProvider>& cr
DynamoDBClient::DynamoDBClient(const Client::ClientConfiguration& clientConfiguration) :
AwsSmithyClientT(clientConfiguration,
GetServiceName(),
"DynamoDB",
Aws::Http::CreateHttpClient(clientConfiguration),
Aws::MakeShared<DynamoDBErrorMarshaller>(ALLOCATION_TAG),
Aws::MakeShared<DynamoDBEndpointProvider>(ALLOCATION_TAG),
Expand All @@ -163,6 +167,7 @@ DynamoDBClient::DynamoDBClient(const AWSCredentials& credentials,
const Client::ClientConfiguration& clientConfiguration) :
AwsSmithyClientT(clientConfiguration,
GetServiceName(),
"DynamoDB",
Aws::Http::CreateHttpClient(clientConfiguration),
Aws::MakeShared<DynamoDBErrorMarshaller>(ALLOCATION_TAG),
Aws::MakeShared<DynamoDBEndpointProvider>(ALLOCATION_TAG),
Expand All @@ -176,6 +181,7 @@ DynamoDBClient::DynamoDBClient(const std::shared_ptr<AWSCredentialsProvider>& cr
const Client::ClientConfiguration& clientConfiguration) :
AwsSmithyClientT(clientConfiguration,
GetServiceName(),
"DynamoDB",
Aws::Http::CreateHttpClient(clientConfiguration),
Aws::MakeShared<DynamoDBErrorMarshaller>(ALLOCATION_TAG),
Aws::MakeShared<DynamoDBEndpointProvider>(ALLOCATION_TAG),
Expand Down
14 changes: 14 additions & 0 deletions src/aws-cpp-sdk-core/include/aws/core/AmazonWebServiceRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <aws/core/Core_EXPORTS.h>

#include <aws/core/client/RequestCompression.h>
#include <aws/core/client/UserAgent.h>
#include <aws/core/auth/AWSAuthSigner.h>
#include <aws/core/client/CoreErrors.h>
#include <aws/core/endpoint/EndpointParameter.h>
Expand Down Expand Up @@ -203,6 +204,18 @@ namespace Aws
virtual Aws::Client::CompressionAlgorithm
GetSelectedCompressionAlgorithm(Aws::Client::RequestCompressionConfig) const { return Aws::Client::CompressionAlgorithm::NONE; }

/**
* Adds a used feature to the user agent string for the request.
* @param feature the feature to be added in the user agent string.
*/
void AddUserAgentFeature(Aws::Client::UserAgentFeature feature) { m_userAgentFeatures.insert(feature); }
sbiscigl marked this conversation as resolved.
Show resolved Hide resolved

/**
* Gets all features that would be included in the requests user agent string.
* @return a set of features that will be included in the user agent associated with this request.
*/
Aws::Set<Aws::Client::UserAgentFeature> GetUserAgentFeatures() const { return m_userAgentFeatures; }

protected:
/**
* Default does nothing. Override this to convert what would otherwise be the payload of the
Expand All @@ -221,6 +234,7 @@ namespace Aws
RequestSignedHandler m_onRequestSigned;
RequestRetryHandler m_requestRetryHandler;
mutable std::shared_ptr<Aws::Http::ServiceSpecificParameters> m_serviceSpecificParameters;
Aws::Set<Client::UserAgentFeature> m_userAgentFeatures;
};

} // namespace Aws
Expand Down
4 changes: 2 additions & 2 deletions src/aws-cpp-sdk-core/include/aws/core/client/AWSClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <aws/core/utils/crypto/Hash.h>
#include <aws/core/auth/AWSAuthSignerProvider.h>
#include <aws/core/endpoint/AWSEndpoint.h>
#include <smithy/client/features/UserAgentInterceptor.h>
#include <smithy/interceptor/Interceptor.h>
#include <memory>
#include <atomic>
Expand Down Expand Up @@ -341,20 +342,19 @@ namespace Aws
void AddHeadersToRequest(const std::shared_ptr<Aws::Http::HttpRequest>& httpRequest, const Http::HeaderValueCollection& headerValues) const;
void AddContentBodyToRequest(const std::shared_ptr<Aws::Http::HttpRequest>& httpRequest, const std::shared_ptr<Aws::IOStream>& body,
bool needsContentMd5 = false, bool isChunked = false) const;
void AddCommonHeaders(Aws::Http::HttpRequest& httpRequest) const;
void AppendHeaderValueToRequest(const std::shared_ptr<Http::HttpRequest> &request, String header, String value) const;

std::shared_ptr<Aws::Http::HttpClient> m_httpClient;
std::shared_ptr<AWSErrorMarshaller> m_errorMarshaller;
std::shared_ptr<RetryStrategy> m_retryStrategy;
std::shared_ptr<Aws::Utils::RateLimits::RateLimiterInterface> m_writeRateLimiter;
std::shared_ptr<Aws::Utils::RateLimits::RateLimiterInterface> m_readRateLimiter;
Aws::String m_userAgent;
std::shared_ptr<Aws::Utils::Crypto::Hash> m_hash;
long m_requestTimeoutMs;
bool m_enableClockSkewAdjustment;
Aws::String m_serviceName = "AWSBaseClient";
Aws::Client::RequestCompressionConfig m_requestCompressionConfig;
std::shared_ptr<smithy::client::UserAgentInterceptor> m_userAgentInterceptor;
Aws::Vector<std::shared_ptr<smithy::interceptor::Interceptor>> m_interceptors;
};

Expand Down
45 changes: 45 additions & 0 deletions src/aws-cpp-sdk-core/include/aws/core/client/UserAgent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <aws/core/client/ClientConfiguration.h>
#include <aws/core/client/RetryStrategy.h>
#include <aws/core/utils/memory/stl/AWSSet.h>

namespace Aws {
namespace Client {

enum class UserAgentFeature {
RETRY_MODE_LEGACY,
RETRY_MODE_STANDARD,
RETRY_MODE_ADAPTIVE,
S3_TRANSFER,
S3_CRYPTO_V1N,
S3_CRYPTO_V2,
};

class AWS_CORE_API UserAgent {
public:
explicit UserAgent(const ClientConfiguration& clientConfiguration, const Aws::String& retryStrategyName, const Aws::String& apiName);
Aws::String SerializeWithFeatures(const Aws::Set<UserAgentFeature>& features) const;
void SetApiName(const Aws::String& apiName) { m_api = apiName; }
void AddLegacyFeature(const Aws::String& legacyFeature);

private:
const Aws::String m_sdkVersion;
const Aws::String m_userAgentVersion;
Aws::String m_api;
const Aws::String m_crtVersion;
const Aws::String m_osVersion;
const Aws::String m_archName;
const Aws::String m_cppVersion;
const Aws::String m_compilerMetadata;
const Aws::String m_retryStrategyName;
const Aws::String m_execEnv;
const Aws::String m_appId;
const Aws::String m_customizations;
Aws::Set<UserAgentFeature> m_features;
};
} // namespace Client
} // namespace Aws
11 changes: 9 additions & 2 deletions src/aws-cpp-sdk-core/include/smithy/client/AwsSmithyClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ namespace client
public:
static_assert(std::is_base_of<Aws::Client::AWSErrorMarshaller, ErrorMarshallerT>::value, "MarshallerT must be derived from class Aws::Client::AWSErrorMarshaller");

explicit AwsSmithyClientT(const ServiceClientConfigurationT& clientConfig, const Aws::String& serviceName,
explicit AwsSmithyClientT(const ServiceClientConfigurationT& clientConfig,
const Aws::String& serviceName,
const Aws::String& serviceUserAgentName,
const std::shared_ptr<Aws::Http::HttpClient>& httpClient,
const std::shared_ptr<Aws::Client::AWSErrorMarshaller>& errorMarshaller,
const std::shared_ptr<EndpointProviderT> endpointProvider,
const std::shared_ptr<ServiceAuthSchemeResolverT>& authSchemeResolver,
const Aws::UnorderedMap<Aws::String, AuthSchemesVariantT>& authSchemes)
: AwsSmithyClientBase(Aws::MakeUnique<ServiceClientConfigurationT>(ServiceNameT, clientConfig), serviceName, httpClient, errorMarshaller),
: AwsSmithyClientBase(Aws::MakeUnique<ServiceClientConfigurationT>(ServiceNameT, clientConfig),
serviceName,
serviceUserAgentName,
httpClient,
errorMarshaller),
m_clientConfiguration(*static_cast<ServiceClientConfigurationT*>(AwsSmithyClientBase::m_clientConfig.get())),
m_endpointProvider(endpointProvider),
m_authSchemeResolver(authSchemeResolver),
Expand All @@ -57,6 +63,7 @@ namespace client
AwsSmithyClientBase(other,
Aws::MakeUnique<ServiceClientConfigurationT>(ServiceNameT, other.m_clientConfiguration),
ServiceNameT,
other.m_serviceUserAgentName,
Aws::Http::CreateHttpClient(other.m_clientConfiguration),
Aws::MakeShared<ErrorMarshallerT>(ServiceNameT)),
m_clientConfiguration{*static_cast<ServiceClientConfigurationT*>(m_clientConfig.get())},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <smithy/tracing/TelemetryProvider.h>
#include <smithy/interceptor/Interceptor.h>
#include <smithy/client/features/ChecksumInterceptor.h>
#include <smithy/client/features/UserAgentInterceptor.h>

#include <aws/crt/Variant.h>
#include <aws/core/client/ClientConfiguration.h>
Expand Down Expand Up @@ -85,11 +86,12 @@ namespace client

AwsSmithyClientBase(Aws::UniquePtr<Aws::Client::ClientConfiguration>&& clientConfig,
Aws::String serviceName,
Aws::String serviceUserAgentName,
std::shared_ptr<Aws::Http::HttpClient> httpClient,
std::shared_ptr<Aws::Client::AWSErrorMarshaller> errorMarshaller) :
m_clientConfig(std::move(clientConfig)),
m_serviceName(std::move(serviceName)),
m_userAgent(),
m_serviceUserAgentName(std::move(serviceUserAgentName)),
m_httpClient(std::move(httpClient)),
m_errorMarshaller(std::move(errorMarshaller)),
m_interceptors{Aws::MakeShared<ChecksumInterceptor>("AwsSmithyClientBase")}
Expand All @@ -100,11 +102,12 @@ namespace client
AwsSmithyClientBase(const AwsSmithyClientBase& other,
Aws::UniquePtr<Aws::Client::ClientConfiguration>&& clientConfig,
Aws::String serviceName,
Aws::String serviceUserAgentName,
std::shared_ptr<Aws::Http::HttpClient> httpClient,
std::shared_ptr<Aws::Client::AWSErrorMarshaller> errorMarshaller) :
m_clientConfig(std::move(clientConfig)),
m_serviceName(std::move(serviceName)),
m_userAgent(),
m_serviceUserAgentName(std::move(serviceUserAgentName)),
m_httpClient(std::move(httpClient)),
m_errorMarshaller(std::move(errorMarshaller)),
m_interceptors{Aws::MakeShared<ChecksumInterceptor>("AwsSmithyClientBase")}
Expand Down Expand Up @@ -181,7 +184,7 @@ namespace client

std::shared_ptr<Aws::Client::ClientConfiguration> m_clientConfig;
Aws::String m_serviceName;
Aws::String m_userAgent;
Aws::String m_serviceUserAgentName;

std::shared_ptr<Aws::Http::HttpClient> m_httpClient;
std::shared_ptr<Aws::Client::AWSErrorMarshaller> m_errorMarshaller;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once

#include <aws/core/client/ClientConfiguration.h>
#include <aws/core/client/RetryStrategy.h>
#include <aws/core/client/UserAgent.h>
#include <smithy/interceptor/Interceptor.h>

#include <utility>

namespace smithy {
namespace client {
class UserAgentInterceptor : public interceptor::Interceptor {
public:
explicit UserAgentInterceptor(const Aws::Client::ClientConfiguration& configuration,
const Aws::String& retryStrategyName,
const Aws::String& apiName)
: m_userAgent{configuration, retryStrategyName, apiName} {};
UserAgentInterceptor(const UserAgentInterceptor& other) = delete;
UserAgentInterceptor(UserAgentInterceptor&& other) noexcept = default;
UserAgentInterceptor& operator=(const UserAgentInterceptor& other) = delete;
UserAgentInterceptor& operator=(UserAgentInterceptor&& other) noexcept = delete;

ModifyRequestOutcome ModifyBeforeSigning(interceptor::InterceptorContext& context) override {
auto transmitRequest = context.GetTransmitRequest();
assert(transmitRequest);
transmitRequest->SetUserAgent(m_userAgent.SerializeWithFeatures(context.GetModeledRequest().GetUserAgentFeatures()));
return transmitRequest;
}

ModifyResponseOutcome ModifyBeforeDeserialization(interceptor::InterceptorContext& context) override {
return context.GetTransmitResponse();
}

void SetApiName(const Aws::String& apiName) { m_userAgent.SetApiName(apiName); }

void AddLegacyFeaturesToUserAgent(const Aws::String& valueToAppend) { m_userAgent.AddLegacyFeature(valueToAppend); }

private:
Aws::Client::UserAgent m_userAgent;
sbiscigl marked this conversation as resolved.
Show resolved Hide resolved
};
} // namespace client
} // namespace smithy
31 changes: 9 additions & 22 deletions src/aws-cpp-sdk-core/source/client/AWSClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration,
m_retryStrategy(configuration.retryStrategy ? configuration.retryStrategy : configuration.configFactories.retryStrategyCreateFn()),
m_writeRateLimiter(configuration.writeRateLimiter ? configuration.writeRateLimiter : configuration.configFactories.writeRateLimiterCreateFn()),
m_readRateLimiter(configuration.readRateLimiter ? configuration.readRateLimiter : configuration.configFactories.readRateLimiterCreateFn()),
m_userAgent(Aws::Client::ComputeUserAgentString(&configuration)),
m_hash(Aws::Utils::Crypto::CreateMD5Implementation()),
m_requestTimeoutMs(configuration.requestTimeoutMs),
m_enableClockSkewAdjustment(configuration.enableClockSkewAdjustment),
m_requestCompressionConfig(configuration.requestCompressionConfig),
m_interceptors{Aws::MakeShared<smithy::client::ChecksumInterceptor>(AWS_CLIENT_LOG_TAG)}
m_userAgentInterceptor{Aws::MakeShared<smithy::client::UserAgentInterceptor>(AWS_CLIENT_LOG_TAG, configuration, m_retryStrategy->GetStrategyName(), m_serviceName)},
m_interceptors{Aws::MakeShared<smithy::client::ChecksumInterceptor>(AWS_CLIENT_LOG_TAG), m_userAgentInterceptor}
{
}

Expand All @@ -160,13 +160,13 @@ AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration,
m_retryStrategy(configuration.retryStrategy ? configuration.retryStrategy : configuration.configFactories.retryStrategyCreateFn()),
m_writeRateLimiter(configuration.writeRateLimiter ? configuration.writeRateLimiter : configuration.configFactories.writeRateLimiterCreateFn()),
m_readRateLimiter(configuration.readRateLimiter ? configuration.readRateLimiter : configuration.configFactories.readRateLimiterCreateFn()),
m_userAgent(Aws::Client::ComputeUserAgentString(&configuration)),
m_hash(Aws::Utils::Crypto::CreateMD5Implementation()),
m_requestTimeoutMs(configuration.requestTimeoutMs),
m_enableClockSkewAdjustment(configuration.enableClockSkewAdjustment),
m_requestCompressionConfig(configuration.requestCompressionConfig)
m_requestCompressionConfig(configuration.requestCompressionConfig),
m_userAgentInterceptor{Aws::MakeShared<smithy::client::UserAgentInterceptor>(AWS_CLIENT_LOG_TAG, configuration, m_retryStrategy->GetStrategyName(), m_serviceName)},
m_interceptors{Aws::MakeShared<smithy::client::ChecksumInterceptor>(AWS_CLIENT_LOG_TAG), m_userAgentInterceptor}
{
m_interceptors.emplace_back(Aws::MakeUnique<smithy::client::ChecksumInterceptor>(AWS_CLIENT_LOG_TAG));
}

void AWSClient::DisableRequestProcessing()
Expand All @@ -182,17 +182,14 @@ void AWSClient::EnableRequestProcessing()
void AWSClient::SetServiceClientName(const Aws::String& name)
{
m_serviceName = std::move(name);
AppendToUserAgent("api/" + m_serviceName);
assert(m_userAgentInterceptor);
m_userAgentInterceptor->SetApiName(m_serviceName);
}

void AWSClient::AppendToUserAgent(const Aws::String& valueToAppend)
{
Aws::String value = Aws::Client::FilterUserAgentToken(valueToAppend.c_str());
if (value.empty())
return;
if (m_userAgent.find(value) != Aws::String::npos)
return;
m_userAgent += " " + std::move(value);
assert(m_userAgentInterceptor);
m_userAgentInterceptor->AddLegacyFeaturesToUserAgent(valueToAppend);
}

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

//user agent and headers like that shouldn't be signed for the sake of compatibility with proxies which MAY mutate that header.
AddCommonHeaders(*httpRequest);

AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request Successfully signed");
auto httpResponse = ::TracingUtils::MakeCallWithTiming<std::shared_ptr<HttpResponse>>(
[&]() -> std::shared_ptr<HttpResponse> {
Expand Down Expand Up @@ -779,8 +773,6 @@ void AWSClient::AddHeadersToRequest(const std::shared_ptr<Aws::Http::HttpRequest
{
httpRequest->SetHeaderValue(headerValue.first, headerValue.second);
}

AddCommonHeaders(*httpRequest);
}

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

void AWSClient::AddCommonHeaders(Aws::Http::HttpRequest& httpRequest) const
{
httpRequest.SetUserAgent(m_userAgent);
}

Aws::String AWSClient::GeneratePresignedUrl(const Aws::Http::URI& uri, Aws::Http::HttpMethod method, long long expirationInSeconds, const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameter)
{
return AWSUrlPresigner(*this).GeneratePresignedUrl(uri, method, expirationInSeconds, serviceSpecificParameter);
Expand Down
Loading
Loading