Skip to content

Commit

Permalink
Merge pull request #47 from anGie44/f-custom-user-agent-info
Browse files Browse the repository at this point in the history
add to user-agent request header with env var data
  • Loading branch information
anGie44 authored Aug 18, 2020
2 parents cc3a73c + 8bdd19e commit ce5e27f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import (
)

const (
// AppendUserAgentEnvVar is a conventionally used environment variable
// containing additional HTTP User-Agent information.
// If present and its value is non-empty, it is directly appended to the
// User-Agent header for HTTP requests.
AppendUserAgentEnvVar = "TF_APPEND_USER_AGENT"
// Maximum network retries.
// We depend on the AWS Go SDK DefaultRetryer exponential backoff.
// Ensure that if the AWS Config MaxRetries is set high (which it is by
Expand Down Expand Up @@ -93,6 +98,13 @@ func GetSession(c *Config) (*session.Session, error) {
sess.Handlers.Build.PushBack(request.MakeAddToUserAgentHandler(product.Name, product.Version, product.Extra...))
}

// Add custom input from ENV to the User-Agent request header
// Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/9149
if v := os.Getenv(AppendUserAgentEnvVar); v != "" {
log.Printf("[DEBUG] Using additional User-Agent Info: %s", v)
sess.Handlers.Build.PushBack(request.MakeAddToUserAgentFreeFormHandler(v))
}

// Generally, we want to configure a lower retry theshold for networking issues
// as the session retry threshold is very high by default and can mask permanent
// networking failures, such as a non-existent service endpoint.
Expand Down

0 comments on commit ce5e27f

Please sign in to comment.