Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify user agent header syntax and add support for app ID #2154

Merged
merged 16 commits into from
Jul 12, 2023
Merged

Conversation

wty-Bryant
Copy link
Contributor

@wty-Bryant wty-Bryant commented Jun 23, 2023

Modify http request User-Agent header syntax and add support for optional app ID section in the UA header.
Customer code could offer an App ID for identifying their applications, which can be obtained from following sources in descending priority:

  1. Client configuration
  2. Environment variables with name of AWS_SDK_UA_APP_ID
  3. Shared config profile field called sdk_ua_app_id

Once a service operation is called with app ID set, it will be concatenated to UA header string in format {app/appID}. One example UA string calling s3 service is shown here:
User-Agent: aws-sdk-go-v2/1.18.1 os/macos lang/go#1.19.5 md/GOOS#darwin md/GOARCH#amd64 api/s3#1.36.0 app/123

@wty-Bryant wty-Bryant requested a review from a team as a code owner June 23, 2023 19:38
"id": "22cf4628-6095-4d35-a4f6-cf1ba88a4ea6",
"type": "feature",
"description": "Modify user agent syntax and introduce support for sdk app ID section in UA header",
"modules": [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix: This will cause issues with the release, work with Luc or Isaiah to generate a rollup changelog entry.


// The AppID that could be retrieved from env var or shared config to be
// added to request's user agent header
AppID string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: We probably want to indicate this will end up in the user agent, we can also probably link to the relevant documentation from CLI if there is any.

@@ -15,7 +15,7 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
)

var expectedAgent = aws.SDKName + "/" + aws.SDKVersion + " os/" + getNormalizedOSName() + " lang/go/" + languageVersion + " md/GOOS/" + runtime.GOOS + " md/GOARCH/" + runtime.GOARCH
var expectedAgent = aws.SDKName + "/" + aws.SDKVersion + " os/" + getNormalizedOSName() + " lang/go#" + languageVersion + " md/GOOS#" + runtime.GOOS + " md/GOARCH#" + runtime.GOARCH

//var expectedSDKAgent = aws.SDKName + "/" + aws.SDKVersion + " os/" + getNormalizedOSName() + " lang/go/" + languageVersion + " md/GOOS/" + runtime.GOOS + " md/GOARCH/" + runtime.GOARCH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@@ -74,7 +79,7 @@ type requestUserAgent struct {
// X-Amz-User-Agent example:
//
// aws-sdk-go-v2/1.2.3 md/GOOS/linux md/GOARCH/amd64 lang/go/1.15
func newRequestUserAgent() *requestUserAgent {
func newRequestUserAgent(appID ...string) *requestUserAgent {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix: appId is singular, also this is forcing us to know/care about appId when creating the user agent structure.

There is already a SDKAgentKeyType of type ApplicationIdentifier for this purpose. We should revert this back and just make an explicit call in setting up the middleware to add two keys. I'll expand elsewhere.

func addClientUserAgent(stack *middleware.Stack) error {
return awsmiddleware.AddSDKAgentKeyValue(awsmiddleware.APIMetadata, "accessanalyzer", goModuleVersion)(stack)
func addClientUserAgent(stack *middleware.Stack, options Options) error {
return awsmiddleware.AddSDKAgentKeyValue(awsmiddleware.APIMetadata, "accessanalyzer", goModuleVersion, options.AppID)(stack)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than force AppId through this API and abuse variadic arguments we can just call it twice I believe.

e.g.

if err := awsmiddleware.AddSDKAgentKeyValue(awsmiddleware.APIMetadata, "accessanalyzer", goModuleVersion)(stack); err != nil { 
    return err
}

if options.AppID != nil {
    return awsmiddleware.AddSDKAgentKey(awsmiddleware.ApplicationIdentifier, options.AppID)(stack)
}

return nil

@wty-Bryant wty-Bryant requested a review from aajtodd June 28, 2023 17:26
aws/config.go Outdated
@@ -132,6 +132,13 @@ type Config struct {
// `config.LoadDefaultConfig`. You should not populate this structure
// programmatically, or rely on the values here within your applications.
RuntimeEnvironment RuntimeEnvironment

// The AppID could be retrieved from environment variable AWS_SDK_UA_APP_ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppId is an optional application specific identifier that can be set. When set it will be appended to the User-Agent header of every request in the form of App/{AppId}. This variable is sourced from environment variable AWS_SDK_UA_APP_ID or the shared config profile attribute sdk_ua_app_id. See https://docs.aws.amazon.com/sdkref/latest/guide/settings-reference.html for more information on environment variables and shared config settings.

AwsConfigField.builder()
.name(SDK_APP_ID)
.type(getUniversalSymbol("string"))
.documentation("The aws sdk app ID that could be retrieved from env var or shared config file" +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't match the current generated setting:

The sdk user agent app id to be added to http request's User-Agent header
AppID string

Maybe need to regenerate?

suggestion:

The (optional) application specific identifier appended to the User-Agent header.

@wty-Bryant wty-Bryant requested a review from aajtodd June 30, 2023 04:08
Copy link
Contributor

@aajtodd aajtodd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, but wait for second review and green light to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants