Skip to content

Commit

Permalink
fix service name in user agent for smithy clients
Browse files Browse the repository at this point in the history
  • Loading branch information
sbiscigl committed Jan 10, 2025
1 parent 38b33e1 commit aeb1969
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 5 deletions.
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
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 @@ -86,10 +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_serviceUserAgentName(std::move(serviceUserAgentName)),
m_httpClient(std::move(httpClient)),
m_errorMarshaller(std::move(errorMarshaller)),
m_interceptors{Aws::MakeShared<ChecksumInterceptor>("AwsSmithyClientBase")}
Expand All @@ -100,10 +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_serviceUserAgentName(std::move(serviceUserAgentName)),
m_httpClient(std::move(httpClient)),
m_errorMarshaller(std::move(errorMarshaller)),
m_interceptors{Aws::MakeShared<ChecksumInterceptor>("AwsSmithyClientBase")}
Expand Down Expand Up @@ -180,6 +184,7 @@ namespace client

std::shared_ptr<Aws::Client::ClientConfiguration> m_clientConfig;
Aws::String m_serviceName;
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
Expand Up @@ -62,7 +62,7 @@ void AwsSmithyClientBase::baseInit() {
m_interceptors.emplace_back(Aws::MakeShared<UserAgentInterceptor>(AWS_SMITHY_CLIENT_LOG,
*m_clientConfig,
m_clientConfig->retryStrategy->GetStrategyName(),
m_serviceName));
m_serviceUserAgentName));
}
}

Expand All @@ -76,7 +76,7 @@ void AwsSmithyClientBase::baseCopyInit() {
m_interceptors.emplace_back(Aws::MakeShared<UserAgentInterceptor>(AWS_SMITHY_CLIENT_LOG,
*m_clientConfig,
m_clientConfig->retryStrategy->GetStrategyName(),
m_serviceName));
m_serviceUserAgentName));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class TestClient : public MySmithyClient
MySmithyClient(
clientConfig,
serviceName,
"ServiceUserAgentName",
httpClient,
errorMarshaller,
endpointProvider,
Expand Down Expand Up @@ -408,6 +409,7 @@ class SampleClient: public smithy::client::AwsSmithyClientT<SampleServiceName,
public:
SampleClient(): AwsSmithyClientT(SampleConfiguration{},
SampleServiceName,
"SampleServiceUserAgentName",
Aws::MakeShared<MockHttpClient>(SampleServiceName),
Aws::MakeShared<Aws::Client::JsonErrorMarshaller>(SampleServiceName),
Aws::MakeShared<SampleEndpointProvider>(SampleServiceName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ TEST_F(DynamoDBUnitTest, ListTablesShouldHaveCorrectUserAgent)
EXPECT_TRUE(sdkMetadata != userAgentParsed.end());
auto uaMetadata = std::find_if(userAgentParsed.begin(), userAgentParsed.end(), [](const Aws::String & value) { return value.find("ua/") != Aws::String::npos; });
EXPECT_TRUE(uaMetadata != userAgentParsed.end());
auto apiMetadata = std::find_if(userAgentParsed.begin(), userAgentParsed.end(), [](const Aws::String & value) { return value.find("api/dynamodb") != Aws::String::npos; });
auto apiMetadata = std::find_if(userAgentParsed.begin(), userAgentParsed.end(), [](const Aws::String & value) { return value.find("api/DynamoDB") != Aws::String::npos; });
EXPECT_TRUE(apiMetadata != userAgentParsed.end());
auto osMetadata = std::find_if(userAgentParsed.begin(), userAgentParsed.end(), [](const Aws::String & value) { return value.find("os/") != Aws::String::npos; });
EXPECT_TRUE(osMetadata != userAgentParsed.end());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ${className}::${className}(const ${clientConfiguration}& clientConfiguration,
std::shared_ptr<${metadata.classNamePrefix}EndpointProviderBase> endpointProvider) :
AwsSmithyClientT(clientConfiguration,
GetServiceName(),
"${metadata.serviceId}",
Aws::Http::CreateHttpClient(clientConfiguration),
Aws::MakeShared<${metadata.classNamePrefix}ErrorMarshaller>(ALLOCATION_TAG),
endpointProvider ? endpointProvider : Aws::MakeShared<${metadata.classNamePrefix}EndpointProvider>(ALLOCATION_TAG),
Expand All @@ -19,6 +20,7 @@ ${className}::${className}(const AWSCredentials& credentials,
const ${clientConfiguration}& clientConfiguration) :
AwsSmithyClientT(clientConfiguration,
GetServiceName(),
"${metadata.serviceId}",
Aws::Http::CreateHttpClient(clientConfiguration),
Aws::MakeShared<${metadata.classNamePrefix}ErrorMarshaller>(ALLOCATION_TAG),
endpointProvider ? endpointProvider : Aws::MakeShared<${metadata.classNamePrefix}EndpointProvider>(ALLOCATION_TAG),
Expand All @@ -35,6 +37,7 @@ ${className}::${className}(const std::shared_ptr<AWSCredentialsProvider>& creden
const ${clientConfiguration}& clientConfiguration) :
AwsSmithyClientT(clientConfiguration,
GetServiceName(),
"${metadata.serviceId}",
Aws::Http::CreateHttpClient(clientConfiguration),
Aws::MakeShared<${metadata.classNamePrefix}ErrorMarshaller>(ALLOCATION_TAG),
endpointProvider ? endpointProvider : Aws::MakeShared<${metadata.classNamePrefix}EndpointProvider>(ALLOCATION_TAG),
Expand All @@ -50,6 +53,7 @@ ${className}::${className}(const std::shared_ptr<AWSCredentialsProvider>& creden
${className}::${className}(const Client::ClientConfiguration& clientConfiguration) :
AwsSmithyClientT(clientConfiguration,
GetServiceName(),
"${metadata.serviceId}",
Aws::Http::CreateHttpClient(clientConfiguration),
Aws::MakeShared<${metadata.classNamePrefix}ErrorMarshaller>(ALLOCATION_TAG),
Aws::MakeShared<${metadata.classNamePrefix}EndpointProvider>(ALLOCATION_TAG),
Expand All @@ -65,6 +69,7 @@ ${className}::${className}(const AWSCredentials& credentials,
const Client::ClientConfiguration& clientConfiguration) :
AwsSmithyClientT(clientConfiguration,
GetServiceName(),
"${metadata.serviceId}",
Aws::Http::CreateHttpClient(clientConfiguration),
Aws::MakeShared<${metadata.classNamePrefix}ErrorMarshaller>(ALLOCATION_TAG),
Aws::MakeShared<${metadata.classNamePrefix}EndpointProvider>(ALLOCATION_TAG),
Expand All @@ -80,6 +85,7 @@ ${className}::${className}(const std::shared_ptr<AWSCredentialsProvider>& creden
const Client::ClientConfiguration& clientConfiguration) :
AwsSmithyClientT(clientConfiguration,
GetServiceName(),
"${metadata.serviceId}",
Aws::Http::CreateHttpClient(clientConfiguration),
Aws::MakeShared<${metadata.classNamePrefix}ErrorMarshaller>(ALLOCATION_TAG),
Aws::MakeShared<${metadata.classNamePrefix}EndpointProvider>(ALLOCATION_TAG),
Expand Down

0 comments on commit aeb1969

Please sign in to comment.