diff --git a/.changelog/4f0e4753f9534938a41748143638981c.json b/.changelog/4f0e4753f9534938a41748143638981c.json new file mode 100644 index 00000000000..e2f100fd60b --- /dev/null +++ b/.changelog/4f0e4753f9534938a41748143638981c.json @@ -0,0 +1,8 @@ +{ + "id": "4f0e4753-f953-4938-a417-48143638981c", + "type": "feature", + "description": "Modify logic of retrieving user agent appID from env config", + "modules": [ + "config" + ] +} \ No newline at end of file diff --git a/config/env_config.go b/config/env_config.go index 63ecd02b384..a142a45c544 100644 --- a/config/env_config.go +++ b/config/env_config.go @@ -69,6 +69,7 @@ const ( awsRetryMaxAttempts = "AWS_MAX_ATTEMPTS" awsRetryMode = "AWS_RETRY_MODE" + awsSdkAppID = "AWS_SDK_UA_APP_ID" ) var ( @@ -248,6 +249,9 @@ type EnvConfig struct { // // aws_retry_mode=standard RetryMode aws.RetryMode + + // aws sdk app ID that can be added to user agent header string + AppID string } // loadEnvConfig reads configuration values from the OS's environment variables. @@ -288,6 +292,8 @@ func NewEnvConfig() (EnvConfig, error) { cfg.RoleARN = os.Getenv(awsRoleARNEnvVar) cfg.RoleSessionName = os.Getenv(awsRoleSessionNameEnvVar) + cfg.AppID = os.Getenv(awsSdkAppID) + if err := setEndpointDiscoveryTypeFromEnvVal(&cfg.EnableEndpointDiscovery, []string{awsEnableEndpointDiscoveryEnvVar}); err != nil { return cfg, err } @@ -335,6 +341,10 @@ func (c EnvConfig) getDefaultsMode(ctx context.Context) (aws.DefaultsMode, bool, return c.DefaultsMode, true, nil } +func (c EnvConfig) getAppID(context.Context) (string, bool, error) { + return c.AppID, len(c.AppID) > 0, nil +} + // GetRetryMaxAttempts returns the value of AWS_MAX_ATTEMPTS if was specified, // and not 0. func (c EnvConfig) GetRetryMaxAttempts(ctx context.Context) (int, bool, error) { diff --git a/config/resolve.go b/config/resolve.go index b037053503d..1187e8c4803 100644 --- a/config/resolve.go +++ b/config/resolve.go @@ -113,10 +113,6 @@ func resolveAppID(ctx context.Context, cfg *aws.Config, configs configs) error { return err } - // if app ID is set in env var, it should precedence shared config value - if appID := os.Getenv(`AWS_SDK_UA_APP_ID`); len(appID) > 0 { - ID = appID - } cfg.AppID = ID return nil }