Skip to content

Commit 4876e18

Browse files
Add appId to the ClientConfiguration structure
1 parent 00141d2 commit 4876e18

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,16 @@ namespace Aws
354354
*/
355355
bool disableImdsV1 = false;
356356

357+
/**
358+
* AppId is an optional application specific identifier that can be set.
359+
* When set it will be appended to the User-Agent header of every request
360+
* in the form of App/{AppId}. This variable is sourced from environment
361+
* variable AWS_SDK_UA_APP_ID or the shared config profile attribute sdk_ua_app_id.
362+
* See https://docs.aws.amazon.com/sdkref/latest/guide/settings-reference.html for
363+
* more information on environment variables and shared config settings.
364+
*/
365+
Aws::String appId;
366+
357367
/**
358368
* A helper function to read config value from env variable or aws profile config
359369
*/

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ Aws::String ComputeUserAgentString(ClientConfiguration const * const pConfig)
107107
ss << " exec-env/" << FilterUserAgentToken(awsExecEnv.c_str());
108108
}
109109

110-
const Aws::String& profile = pConfig ? pConfig->profileName : "default";
111-
Aws::String appId = ClientConfiguration::LoadConfigFromEnvOrProfile("AWS_SDK_UA_APP_ID", profile, "sdk_ua_app_id", {}, "");
110+
const Aws::String& appId = pConfig ? pConfig->appId :
111+
ClientConfiguration::LoadConfigFromEnvOrProfile("AWS_SDK_UA_APP_ID", "default", "sdk_ua_app_id", {}, "");
112112
if(!appId.empty())
113113
{
114114
ss << " app/" << appId;
@@ -141,11 +141,14 @@ void setLegacyClientConfigurationParameters(ClientConfiguration& clientConfig)
141141
clientConfig.enableClockSkewAdjustment = true;
142142
clientConfig.enableHostPrefixInjection = true;
143143
clientConfig.enableHttpClientTrace = false;
144-
clientConfig.profileName = Aws::Auth::GetConfigProfileName();
144+
if (clientConfig.profileName.empty())
145+
{
146+
clientConfig.profileName = Aws::Auth::GetConfigProfileName();
147+
}
145148

146149
Aws::String disableCompressionConfig = clientConfig.LoadConfigFromEnvOrProfile(
147150
DISABLE_REQUEST_COMPRESSION_ENV_VAR,
148-
Aws::Auth::GetConfigProfileName(),
151+
clientConfig.profileName,
149152
DISABLE_REQUEST_COMPRESSION_CONFIG_VAR,
150153
{"TRUE", "FALSE", "true", "false"},
151154
"false"
@@ -206,6 +209,14 @@ void setLegacyClientConfigurationParameters(ClientConfiguration& clientConfig)
206209
client->SetEndpoint(ec2MetadataServiceEndpoint);
207210
}
208211
}
212+
213+
clientConfig.appId = clientConfig.LoadConfigFromEnvOrProfile(
214+
"AWS_SDK_UA_APP_ID",
215+
clientConfig.profileName,
216+
"sdk_ua_app_id",
217+
{},
218+
""
219+
);
209220
}
210221

211222
void setConfigFromEnvOrProfile(ClientConfiguration &config)
@@ -271,6 +282,9 @@ ClientConfiguration::ClientConfiguration(const ClientConfigurationInitValues &co
271282
ClientConfiguration::ClientConfiguration(const char* profile, bool shouldDisableIMDS)
272283
{
273284
this->disableIMDS = shouldDisableIMDS;
285+
if (profile && Aws::Config::HasCachedConfigProfile(profile)) {
286+
this->profileName = Aws::String(profile);
287+
}
274288
setLegacyClientConfigurationParameters(*this);
275289
// Call EC2 Instance Metadata service only once
276290
Aws::String ec2MetadataRegion;
@@ -293,7 +307,6 @@ ClientConfiguration::ClientConfiguration(const char* profile, bool shouldDisable
293307
}
294308

295309
if (profile && Aws::Config::HasCachedConfigProfile(profile)) {
296-
this->profileName = Aws::String(profile);
297310
AWS_LOGSTREAM_DEBUG(CLIENT_CONFIG_TAG,
298311
"Use user specified profile: [" << this->profileName << "] for ClientConfiguration.");
299312
auto tmpRegion = Aws::Config::GetCachedConfigProfile(this->profileName).GetRegion();

0 commit comments

Comments
 (0)