Skip to content

Commit ca99ccc

Browse files
committed
update to not use typeid at run time
1 parent e955386 commit ca99ccc

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

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

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#include <aws/core/platform/Environment.h>
4545
#include <aws/core/platform/OSVersionInfo.h>
4646
#include <aws/core/auth/AWSCredentialsProviderChain.h>
47-
#include <typeinfo>
4847

4948
#include <smithy/tracing/TracingUtils.h>
5049
#include <smithy/client/features/ChecksumInterceptor.h>
@@ -143,7 +142,6 @@ AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration,
143142
m_userAgentInterceptor{Aws::MakeShared<smithy::client::UserAgentInterceptor>(AWS_CLIENT_LOG_TAG, configuration, m_retryStrategy->GetStrategyName(), m_serviceName)},
144143
m_interceptors{Aws::MakeShared<smithy::client::ChecksumInterceptor>(AWS_CLIENT_LOG_TAG), m_userAgentInterceptor}
145144
{
146-
147145
}
148146

149147
AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration,
@@ -568,11 +566,6 @@ HttpResponseOutcome AWSClient::AttemptOneRequest(const std::shared_ptr<Aws::Http
568566
*m_telemetryProvider->getMeter(this->GetServiceClientName(), {}),
569567
{{TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName()},{TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName()}});
570568

571-
// Check for environment credentials
572-
if (!Aws::Environment::GetEnv("AWS_ACCESS_KEY_ID").empty() &&
573-
!Aws::Environment::GetEnv("AWS_SECRET_ACCESS_KEY").empty()) {
574-
request.AddUserAgentFeature(Aws::Client::UserAgentFeature::CREDENTIALS_ENV_VARS);
575-
}
576569
InterceptorContext context{request};
577570
context.SetTransmitRequest(httpRequest);
578571
for (const auto& interceptor : m_interceptors)
@@ -917,7 +910,6 @@ void AWSClient::BuildHttpRequest(const Aws::AmazonWebServiceRequest& request, co
917910
if (Aws::Client::CompressionAlgorithm::NONE != selectedCompressionAlgorithm) {
918911
Aws::Client::RequestCompression rc;
919912
auto compressOutcome = rc.compress(request.GetBody(), selectedCompressionAlgorithm);
920-
// TODO: is this successful -- its not
921913
if (compressOutcome.IsSuccess()) {
922914
Aws::String compressionAlgorithmId = Aws::Client::GetCompressionAlgorithmId(selectedCompressionAlgorithm);
923915
AppendHeaderValueToRequest(httpRequest, CONTENT_ENCODING_HEADER, compressionAlgorithmId);
@@ -1082,33 +1074,26 @@ void AWSClient::TrackCredentialProviderUsage(const Aws::AmazonWebServiceRequest&
10821074
{
10831075
return;
10841076
}
1085-
1086-
// Check if using environment credentials
1087-
const auto& provider = *credentialsProvider;
1088-
const std::type_info& providerType = typeid(provider);
1089-
1090-
if (providerType == typeid(Aws::Auth::DefaultAWSCredentialsProviderChain))
1077+
1078+
// Get the provider type
1079+
auto providerType = credentialsProvider->GetProviderType();
1080+
1081+
switch (providerType)
10911082
{
1092-
// For provider chains, we need to check which provider was actually used
1093-
auto providerChain = std::dynamic_pointer_cast<Aws::Auth::DefaultAWSCredentialsProviderChain>(credentialsProvider);
1094-
if (providerChain)
1095-
{
1096-
// Check if environment variables are set (indicating env provider usage)
1083+
case Aws::Auth::CredentialProviderType::ENVIRONMENT:
1084+
// Environment credentials are being used
1085+
request.AddUserAgentFeature(Aws::Client::UserAgentFeature::CREDENTIALS_ENV_VARS);
1086+
AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Added CREDENTIALS_ENV_VARS to User-Agent");
1087+
break;
1088+
1089+
// Add more provider types as needed
1090+
default:
1091+
// For provider chains or unknown types, check environment variables as fallback
10971092
if (!Aws::Environment::GetEnv("AWS_ACCESS_KEY_ID").empty())
10981093
{
1099-
// Environment credentials are being used
11001094
request.AddUserAgentFeature(Aws::Client::UserAgentFeature::CREDENTIALS_ENV_VARS);
1101-
AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Added CREDENTIALS_ENV_VARS to User-Agent");
1095+
AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Added CREDENTIALS_ENV_VARS to User-Agent (fallback detection)");
11021096
}
1103-
// Add other providers
1104-
}
1105-
}
1106-
// direct provider usage
1107-
else if (providerType == typeid(Aws::Auth::EnvironmentAWSCredentialsProvider))
1108-
{
1109-
// Direct environment provider usage
1110-
request.AddUserAgentFeature(Aws::Client::UserAgentFeature::CREDENTIALS_ENV_VARS);
1111-
AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Added CREDENTIALS_ENV_VARS to User-Agent");
1097+
break;
11121098
}
1113-
// Add more provider types as needed
11141099
}

0 commit comments

Comments
 (0)