Skip to content

Commit

Permalink
Merge pull request #2314 from aws/feat-optimize-ua-appID
Browse files Browse the repository at this point in the history
Optimize logic of retrieving user agent appID from env config
  • Loading branch information
wty-Bryant authored Oct 13, 2023
2 parents 6e4fae3 + fcbf63c commit 1cc8d04
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .changelog/4f0e4753f9534938a41748143638981c.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
10 changes: 10 additions & 0 deletions config/env_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const (

awsRetryMaxAttempts = "AWS_MAX_ATTEMPTS"
awsRetryMode = "AWS_RETRY_MODE"
awsSdkAppID = "AWS_SDK_UA_APP_ID"
)

var (
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 0 additions & 4 deletions config/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 1cc8d04

Please sign in to comment.