@@ -45,9 +45,11 @@ static const char* AWS_METADATA_SERVICE_TIMEOUT_ENV_VAR = "AWS_METADATA_SERVICE_
4545static const char * AWS_METADATA_SERVICE_TIMEOUT_CONFIG_VAR = " metadata_service_timeout" ;
4646static const char * AWS_METADATA_SERVICE_NUM_ATTEMPTS_ENV_VAR = " AWS_METADATA_SERVICE_NUM_ATTEMPTS" ;
4747static const char * AWS_METADATA_SERVICE_NUM_ATTEMPTS_CONFIG_VAR = " metadata_service_num_attempts" ;
48- static const char * AWS_IAM_ROLE_ARN_ENV_VAR = " AWS_IAM_ROLE_ARN" ;
48+ static const char * AWS_IAM_ROLE_ARN_ENV_VAR = " AWS_ROLE_ARN" ;
49+ static const char * AWS_IAM_ROLE_ARN_ENV_VAR_COMPAT = " AWS_IAM_ROLE_ARN" ;
4950static const char * AWS_IAM_ROLE_ARN_CONFIG_FILE_OPTION = " role_arn" ;
50- static const char * AWS_IAM_ROLE_SESSION_NAME_ENV_VAR = " AWS_IAM_ROLE_SESSION_NAME" ;
51+ static const char * AWS_IAM_ROLE_SESSION_NAME_ENV_VAR = " AWS_ROLE_SESSION_NAME" ;
52+ static const char * AWS_IAM_ROLE_SESSION_NAME_ENV_VAR_COMPAT = " AWS_IAM_ROLE_SESSION_NAME" ;
5153static const char * AWS_IAM_ROLE_SESSION_NAME_CONFIG_FILE_OPTION = " role_session_name" ;
5254static const char * AWS_WEB_IDENTITY_TOKEN_FILE_ENV_VAR = " AWS_WEB_IDENTITY_TOKEN_FILE" ;
5355static const char * AWS_WEB_IDENTITY_TOKEN_FILE_CONFIG_FILE_OPTION = " web_identity_token_file" ;
@@ -327,23 +329,34 @@ void setConfigFromEnvOrProfile(ClientConfiguration &config)
327329 // Uses default retry mode with the specified max attempts from metadata_service_num_attempts
328330 config.credentialProviderConfig .imdsConfig .imdsRetryStrategy = InitRetryStrategy (attempts, " " );
329331
330- config.credentialProviderConfig .stsCredentialsProviderConfig .roleArn = ClientConfiguration::LoadConfigFromEnvOrProfile (AWS_IAM_ROLE_ARN_ENV_VAR,
331- config.profileName ,
332- AWS_IAM_ROLE_ARN_CONFIG_FILE_OPTION,
333- {}, /* allowed values */
334- " " /* default value */ );
335-
336- config.credentialProviderConfig .stsCredentialsProviderConfig .sessionName = ClientConfiguration::LoadConfigFromEnvOrProfile (AWS_IAM_ROLE_SESSION_NAME_ENV_VAR,
337- config.profileName ,
338- AWS_IAM_ROLE_SESSION_NAME_CONFIG_FILE_OPTION,
339- {}, /* allowed values */
340- " " /* default value */ );
341-
342- config.credentialProviderConfig .stsCredentialsProviderConfig .tokenFilePath = ClientConfiguration::LoadConfigFromEnvOrProfile (AWS_WEB_IDENTITY_TOKEN_FILE_ENV_VAR,
343- config.profileName ,
344- AWS_WEB_IDENTITY_TOKEN_FILE_CONFIG_FILE_OPTION,
345- {}, /* allowed values */
346- " " /* default value */ );
332+ config.credentialProviderConfig .stsCredentialsProviderConfig .roleArn = ClientConfiguration::LoadConfigFromEnvOrProfileCaseSensitive (
333+ AWS_IAM_ROLE_ARN_ENV_VAR_COMPAT, config.profileName , AWS_IAM_ROLE_ARN_CONFIG_FILE_OPTION, {}, /* allowed values */
334+ " " /* default value */ , [](const Aws::String& envValue) -> Aws::String { return envValue; });
335+
336+ // there was a typo in the original environment variable, this exists for backwards compatibility
337+ if (config.credentialProviderConfig .stsCredentialsProviderConfig .roleArn .empty ()) {
338+ config.credentialProviderConfig .stsCredentialsProviderConfig .roleArn = ClientConfiguration::LoadConfigFromEnvOrProfileCaseSensitive (
339+ AWS_IAM_ROLE_ARN_ENV_VAR, config.profileName , AWS_IAM_ROLE_ARN_CONFIG_FILE_OPTION, {}, /* allowed values */
340+ " " /* default value */ , [](const Aws::String& envValue) -> Aws::String { return envValue; });
341+ }
342+
343+ config.credentialProviderConfig .stsCredentialsProviderConfig .sessionName = ClientConfiguration::LoadConfigFromEnvOrProfileCaseSensitive (
344+ AWS_IAM_ROLE_SESSION_NAME_ENV_VAR_COMPAT, config.profileName , AWS_IAM_ROLE_SESSION_NAME_CONFIG_FILE_OPTION, {}, /* allowed values */
345+ " " /* default value */ , [](const Aws::String& envValue) -> Aws::String { return envValue; });
346+
347+ // there was a typo in the original environment variable, this exists for backwards compatibility
348+ if (config.credentialProviderConfig .stsCredentialsProviderConfig .sessionName .empty ()) {
349+ config.credentialProviderConfig .stsCredentialsProviderConfig .sessionName =
350+ ClientConfiguration::LoadConfigFromEnvOrProfileCaseSensitive (
351+ AWS_IAM_ROLE_SESSION_NAME_ENV_VAR, config.profileName , AWS_IAM_ROLE_SESSION_NAME_CONFIG_FILE_OPTION, {}, /* allowed values */
352+ " " /* default value */ , [](const Aws::String& envValue) -> Aws::String { return envValue; });
353+ }
354+
355+ config.credentialProviderConfig .stsCredentialsProviderConfig .tokenFilePath =
356+ ClientConfiguration::LoadConfigFromEnvOrProfileCaseSensitive (
357+ AWS_WEB_IDENTITY_TOKEN_FILE_ENV_VAR, config.profileName , AWS_WEB_IDENTITY_TOKEN_FILE_CONFIG_FILE_OPTION,
358+ {}, /* allowed values */
359+ " " /* default value */ , [](const Aws::String& envValue) -> Aws::String { return envValue; });
347360}
348361
349362ClientConfiguration::ClientConfiguration ()
@@ -558,29 +571,35 @@ Aws::String ClientConfiguration::LoadConfigFromEnvOrProfile(const Aws::String& e
558571 const Aws::Vector<Aws::String>& allowedValues,
559572 const Aws::String& defaultValue)
560573{
561- Aws::String option = Aws::Environment::GetEnv (envKey.c_str ());
562- if (option.empty ()) {
563- option = Aws::Config::GetCachedConfigValue (profile, profileProperty);
564- }
565- option = Aws::Utils::StringUtils::ToLower (option.c_str ());
566- if (option.empty ()) {
567- return defaultValue;
568- }
569-
570- if (!allowedValues.empty () && std::find (allowedValues.cbegin (), allowedValues.cend (), option) == allowedValues.cend ()) {
571- Aws::OStringStream expectedStr;
572- expectedStr << " [" ;
573- for (const auto & allowed : allowedValues) {
574- expectedStr << allowed << " ;" ;
575- }
576- expectedStr << " ]" ;
574+ return LoadConfigFromEnvOrProfileCaseSensitive (envKey, profile, profileProperty, allowedValues, defaultValue);
575+ }
576+ Aws::String ClientConfiguration::LoadConfigFromEnvOrProfileCaseSensitive (const Aws::String& envKey, const Aws::String& profile,
577+ const Aws::String& profileProperty,
578+ const Aws::Vector<Aws::String>& allowedValues,
579+ const Aws::String& defaultValue,
580+ const std::function<Aws::String(const char *)>& envValueMapping) {
581+ Aws::String option = Aws::Environment::GetEnv (envKey.c_str ());
582+ if (option.empty ()) {
583+ option = Aws::Config::GetCachedConfigValue (profile, profileProperty);
584+ }
585+ option = envValueMapping (option.c_str ());
586+ if (option.empty ()) {
587+ return defaultValue;
588+ }
577589
578- AWS_LOGSTREAM_WARN (CLIENT_CONFIG_TAG, " Unrecognised value for " << envKey << " : " << option <<
579- " . Using default instead: " << defaultValue <<
580- " . Expected empty or one of: " << expectedStr.str ());
581- option = defaultValue;
590+ if (!allowedValues.empty () && std::find (allowedValues.cbegin (), allowedValues.cend (), option) == allowedValues.cend ()) {
591+ Aws::OStringStream expectedStr;
592+ expectedStr << " [" ;
593+ for (const auto & allowed : allowedValues) {
594+ expectedStr << allowed << " ;" ;
582595 }
583- return option;
596+ expectedStr << " ]" ;
597+
598+ AWS_LOGSTREAM_WARN (CLIENT_CONFIG_TAG, " Unrecognised value for " << envKey << " : " << option << " . Using default instead: "
599+ << defaultValue << " . Expected empty or one of: " << expectedStr.str ());
600+ option = defaultValue;
601+ }
602+ return option;
584603}
585604
586605} // namespace Client
0 commit comments