Skip to content

Commit

Permalink
Add appId to the ClientConfiguration structure
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyRyabinin committed May 17, 2024
1 parent 00141d2 commit c2d4671
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/aws-cpp-sdk-core/include/aws/core/client/ClientConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,16 @@ namespace Aws
*/
bool disableImdsV1 = false;

/**
* AppId is an optional application specific identifier that can be set.
* When set it will be appended to the User-Agent header of every request
* in the form of App/{AppId}. This variable is sourced from environment
* variable AWS_SDK_UA_APP_ID or the shared config profile attribute sdk_ua_app_id.
* See https://docs.aws.amazon.com/sdkref/latest/guide/settings-reference.html for
* more information on environment variables and shared config settings.
*/
Aws::String appId;

/**
* A helper function to read config value from env variable or aws profile config
*/
Expand Down
20 changes: 16 additions & 4 deletions src/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ Aws::String ComputeUserAgentString(ClientConfiguration const * const pConfig)
ss << " exec-env/" << FilterUserAgentToken(awsExecEnv.c_str());
}

const Aws::String& profile = pConfig ? pConfig->profileName : "default";
Aws::String appId = ClientConfiguration::LoadConfigFromEnvOrProfile("AWS_SDK_UA_APP_ID", profile, "sdk_ua_app_id", {}, "");
const Aws::String& appId = pConfig ? pConfig->appId :
ClientConfiguration::LoadConfigFromEnvOrProfile("AWS_SDK_UA_APP_ID", "default", "sdk_ua_app_id", {}, "");
if(!appId.empty())
{
ss << " app/" << appId;
Expand Down Expand Up @@ -141,11 +141,14 @@ void setLegacyClientConfigurationParameters(ClientConfiguration& clientConfig)
clientConfig.enableClockSkewAdjustment = true;
clientConfig.enableHostPrefixInjection = true;
clientConfig.enableHttpClientTrace = false;
clientConfig.profileName = Aws::Auth::GetConfigProfileName();
if (clientConfig.profileName.empty())
{
clientConfig.profileName = Aws::Auth::GetConfigProfileName();
}

Aws::String disableCompressionConfig = clientConfig.LoadConfigFromEnvOrProfile(
DISABLE_REQUEST_COMPRESSION_ENV_VAR,
Aws::Auth::GetConfigProfileName(),
clientConfig.profileName,
DISABLE_REQUEST_COMPRESSION_CONFIG_VAR,
{"TRUE", "FALSE", "true", "false"},
"false"
Expand Down Expand Up @@ -206,6 +209,14 @@ void setLegacyClientConfigurationParameters(ClientConfiguration& clientConfig)
client->SetEndpoint(ec2MetadataServiceEndpoint);
}
}

clientConfig.appId = clientConfig.LoadConfigFromEnvOrProfile(
"AWS_SDK_UA_APP_ID",
clientConfig.profileName,
"sdk_ua_app_id",
{},
""
);
}

void setConfigFromEnvOrProfile(ClientConfiguration &config)
Expand Down Expand Up @@ -271,6 +282,7 @@ ClientConfiguration::ClientConfiguration(const ClientConfigurationInitValues &co
ClientConfiguration::ClientConfiguration(const char* profile, bool shouldDisableIMDS)
{
this->disableIMDS = shouldDisableIMDS;
this->profileName = profile;
setLegacyClientConfigurationParameters(*this);
// Call EC2 Instance Metadata service only once
Aws::String ec2MetadataRegion;
Expand Down

0 comments on commit c2d4671

Please sign in to comment.