@@ -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,45 @@ 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,
332+ config.credentialProviderConfig .stsCredentialsProviderConfig .roleArn = ClientConfiguration::LoadConfigFromEnvOrProfileCaseSensitive (AWS_IAM_ROLE_ARN_ENV_VAR,
331333 config.profileName ,
332334 AWS_IAM_ROLE_ARN_CONFIG_FILE_OPTION,
333335 {}, /* allowed values */
334- " " /* default value */ );
336+ " " /* default value */ ,
337+ [](const Aws::String& envValue) -> Aws::String { return envValue; });
335338
336- config.credentialProviderConfig .stsCredentialsProviderConfig .sessionName = ClientConfiguration::LoadConfigFromEnvOrProfile (AWS_IAM_ROLE_SESSION_NAME_ENV_VAR,
339+ // there was a typo in the original environment variable, this exists for backwards compatibility
340+ if (config.credentialProviderConfig .stsCredentialsProviderConfig .roleArn .empty ()) {
341+ config.credentialProviderConfig .stsCredentialsProviderConfig .roleArn = ClientConfiguration::LoadConfigFromEnvOrProfileCaseSensitive (AWS_IAM_ROLE_ARN_ENV_VAR_COMPAT,
337342 config.profileName ,
338- AWS_IAM_ROLE_SESSION_NAME_CONFIG_FILE_OPTION ,
343+ AWS_IAM_ROLE_ARN_CONFIG_FILE_OPTION ,
339344 {}, /* allowed values */
340- " " /* default value */ );
345+ " " /* default value */ ,
346+ [](const Aws::String& envValue) -> Aws::String { return envValue; });
347+ }
341348
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 */ );
349+ config.credentialProviderConfig .stsCredentialsProviderConfig .sessionName = ClientConfiguration::LoadConfigFromEnvOrProfileCaseSensitive (AWS_IAM_ROLE_SESSION_NAME_ENV_VAR,
350+ config.profileName ,
351+ AWS_IAM_ROLE_SESSION_NAME_CONFIG_FILE_OPTION,
352+ {}, /* allowed values */
353+ " " /* default value */ ,
354+ [](const Aws::String& envValue) -> Aws::String { return envValue; });
355+
356+ // there was a typo in the original environment variable, this exists for backwards compatibility
357+ if (config.credentialProviderConfig .stsCredentialsProviderConfig .sessionName .empty ()) {
358+ config.credentialProviderConfig .stsCredentialsProviderConfig .sessionName = ClientConfiguration::LoadConfigFromEnvOrProfileCaseSensitive (AWS_IAM_ROLE_SESSION_NAME_ENV_VAR_COMPAT,
359+ config.profileName ,
360+ AWS_IAM_ROLE_SESSION_NAME_CONFIG_FILE_OPTION,
361+ {}, /* allowed values */
362+ " " /* default value */ ,
363+ [](const Aws::String& envValue) -> Aws::String { return envValue; });
364+ }
365+
366+ config.credentialProviderConfig .stsCredentialsProviderConfig .tokenFilePath = ClientConfiguration::LoadConfigFromEnvOrProfile (AWS_WEB_IDENTITY_TOKEN_FILE_ENV_VAR,
367+ config.profileName ,
368+ AWS_WEB_IDENTITY_TOKEN_FILE_CONFIG_FILE_OPTION,
369+ {}, /* allowed values */
370+ " " /* default value */ );
347371}
348372
349373ClientConfiguration::ClientConfiguration ()
@@ -558,29 +582,36 @@ Aws::String ClientConfiguration::LoadConfigFromEnvOrProfile(const Aws::String& e
558582 const Aws::Vector<Aws::String>& allowedValues,
559583 const Aws::String& defaultValue)
560584{
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 << " ]" ;
585+ return LoadConfigFromEnvOrProfileCaseSensitive (envKey, profile, profileProperty, allowedValues, defaultValue);
586+ }
587+ Aws::String ClientConfiguration::LoadConfigFromEnvOrProfileCaseSensitive (const Aws::String& envKey, const Aws::String& profile,
588+ const Aws::String& profileProperty,
589+ const Aws::Vector<Aws::String>& allowedValues,
590+ const Aws::String& defaultValue,
591+ const std::function<Aws::String(const char *)>& envValueMapping) {
592+ Aws::String option = Aws::Environment::GetEnv (envKey.c_str ());
593+ if (option.empty ()) {
594+ option = Aws::Config::GetCachedConfigValue (profile, profileProperty);
595+ }
596+ option = envValueMapping (option.c_str ());
597+ if (option.empty ()) {
598+ return defaultValue;
599+ }
577600
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;
601+ if (!allowedValues.empty () && std::find (allowedValues.cbegin (), allowedValues.cend (), option) == allowedValues.cend ()) {
602+ Aws::OStringStream expectedStr;
603+ expectedStr << " [" ;
604+ for (const auto & allowed : allowedValues) {
605+ expectedStr << allowed << " ;" ;
582606 }
583- return option;
607+ expectedStr << " ]" ;
608+
609+ AWS_LOGSTREAM_WARN (CLIENT_CONFIG_TAG, " Unrecognised value for " << envKey << " : " << option <<
610+ " . Using default instead: " << defaultValue <<
611+ " . Expected empty or one of: " << expectedStr.str ());
612+ option = defaultValue;
613+ }
614+ return option;
584615}
585616
586617} // namespace Client
0 commit comments