Skip to content

client: add cluster-api-provider-aws to UserAgent for AWS API calls #167

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

Merged
merged 1 commit into from
Feb 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
Expand Down Expand Up @@ -154,6 +155,7 @@ func NewClient(ctrlRuntimeClient client.Client, secretName, namespace, region st
if err != nil {
return nil, err
}
s.Handlers.Build.PushBackNamed(addProviderVersionToUserAgent)

return &awsClient{
ec2Client: ec2.New(s),
Expand All @@ -178,10 +180,18 @@ func NewClientFromKeys(accessKey, secretAccessKey, region string) (Client, error
if err != nil {
return nil, err
}
s.Handlers.Build.PushBackNamed(addProviderVersionToUserAgent)

return &awsClient{
ec2Client: ec2.New(s),
elbClient: elb.New(s),
elbv2Client: elbv2.New(s),
}, nil
}

// addProviderVersionToUserAgent is a named handler that will add cluster-api-provider-aws
// version information to requests made by the AWS SDK.
var addProviderVersionToUserAgent = request.NamedHandler{
Name: "openshift.io/cluster-api-provider-aws",
Fn: request.MakeAddToUserAgentHandler("openshift.io cluster-api-provider-aws", "dummy"),
Copy link

@frobware frobware Feb 25, 2019

Choose a reason for hiding this comment

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

Maybe a dumb question but why does the name have '/' but Fn not?

Copy link
Member

Choose a reason for hiding this comment

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

None of that is a blocker for me. Though, we might even change the dummy literal into more customer legit string.

Copy link
Author

Choose a reason for hiding this comment

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

Maybe a dumb question but why does the name have '/' but Fn not?

https://docs.aws.amazon.com/sdk-for-go/api/aws/request/#MakeAddToUserAgentHandler
the useragent is generated based on Fn arguments:

name/version (extra0; extra1; ...)

therefore the arg to Fn doesn't use / in the name.

As for the Handler's Name, i didn't want to put spaces.

None of that is a blocker for me. Though, we might even change the dummy literal into more customer legit string.

The cluster-api-provider-aws has no usable variable for version. That's why it is dummy.

Copy link
Member

Choose a reason for hiding this comment

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

We can replace the dummy with version once we implemented the version subcommand.

@abhinavdahiya thanks for the rationale

}