From cdcb6813f238d172a7bd31f1f1acc2e2cde634bc Mon Sep 17 00:00:00 2001 From: Tianyi Wang Date: Fri, 13 Oct 2023 12:50:27 -0400 Subject: [PATCH 1/3] Optimize and Merge user agent appID resolving from env config --- config/env_config.go | 5 +++++ config/resolve.go | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/config/env_config.go b/config/env_config.go index 63ecd02b384..3d972a4bb7f 100644 --- a/config/env_config.go +++ b/config/env_config.go @@ -335,6 +335,11 @@ func (c EnvConfig) getDefaultsMode(ctx context.Context) (aws.DefaultsMode, bool, return c.DefaultsMode, true, nil } +func (c EnvConfig) getAppID(context.Context) (string, bool, error) { + appID := os.Getenv(`AWS_SDK_UA_APP_ID`) + return appID, len(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 } From 14bd3fcb06cf0dbe5fe9bf1331c3049574fa7d3c Mon Sep 17 00:00:00 2001 From: Tianyi Wang Date: Fri, 13 Oct 2023 12:53:11 -0400 Subject: [PATCH 2/3] Add and Merge changelog for prev commit --- .changelog/4f0e4753f9534938a41748143638981c.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .changelog/4f0e4753f9534938a41748143638981c.json 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 From fcbf63c7af2804182e6c00899a095d5ed987ebbc Mon Sep 17 00:00:00 2001 From: Tianyi Wang Date: Fri, 13 Oct 2023 14:21:36 -0400 Subject: [PATCH 3/3] Modify and Merge env config logic of retrieving UA appID --- config/env_config.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/config/env_config.go b/config/env_config.go index 3d972a4bb7f..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 } @@ -336,8 +342,7 @@ func (c EnvConfig) getDefaultsMode(ctx context.Context) (aws.DefaultsMode, bool, } func (c EnvConfig) getAppID(context.Context) (string, bool, error) { - appID := os.Getenv(`AWS_SDK_UA_APP_ID`) - return appID, len(appID) > 0, nil + return c.AppID, len(c.AppID) > 0, nil } // GetRetryMaxAttempts returns the value of AWS_MAX_ATTEMPTS if was specified,