Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

Commit 98c4f8c

Browse files
committed
Customize SDK requests to AWS API with user-agent
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent bad350b commit 98c4f8c

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

builder.Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ endif
88

99
STATIC_FLAGS=CGO_ENABLED=0
1010
LDFLAGS := "-s -w \
11-
-X github.com/docker/ecs-plugin/cmd/commands.GitCommit=$(COMMIT) \
12-
-X github.com/docker/ecs-plugin/cmd/commands.Version=$(TAG)"
11+
-X github.com/docker/ecs-plugin/internal.GitCommit=$(COMMIT) \
12+
-X github.com/docker/ecs-plugin/internal.Version=$(TAG)"
1313
GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
1414

1515
BINARY=dist/docker-ecs

cmd/commands/version.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,17 @@ package commands
33
import (
44
"fmt"
55

6-
"github.com/spf13/cobra"
7-
)
6+
"github.com/docker/ecs-plugin/internal"
87

9-
var (
10-
// Version is the git tag that this was built from.
11-
Version = "unknown"
12-
// GitCommit is the commit that this was built from.
13-
GitCommit = "unknown"
8+
"github.com/spf13/cobra"
149
)
1510

1611
func VersionCommand() *cobra.Command {
1712
return &cobra.Command{
1813
Use: "version",
1914
Short: "Show version.",
2015
RunE: func(cmd *cobra.Command, args []string) error {
21-
fmt.Fprintf(cmd.OutOrStdout(), "Docker ECS plugin %s (%s)\n", Version, GitCommit)
16+
fmt.Fprintf(cmd.OutOrStdout(), "Docker ECS plugin %s (%s)\n", internal.Version, internal.GitCommit)
2217
return nil
2318
},
2419
}

cmd/commands/version_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"strings"
66
"testing"
77

8+
"github.com/docker/ecs-plugin/internal"
9+
810
"gotest.tools/v3/assert"
911
)
1012

@@ -14,5 +16,5 @@ func TestVersion(t *testing.T) {
1416
root.SetOut(&out)
1517
root.SetArgs([]string{"version"})
1618
root.Execute()
17-
assert.Check(t, strings.Contains(out.String(), Version))
19+
assert.Check(t, strings.Contains(out.String(), internal.Version))
1820
}

cmd/main/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"github.com/docker/ecs-plugin/cmd/commands"
5+
"github.com/docker/ecs-plugin/internal"
56

67
"github.com/docker/cli/cli-plugins/manager"
78
"github.com/docker/cli/cli-plugins/plugin"
@@ -16,7 +17,7 @@ func main() {
1617
}, manager.Metadata{
1718
SchemaVersion: "0.1.0",
1819
Vendor: "Docker Inc.",
19-
Version: commands.Version,
20+
Version: internal.Version,
2021
Experimental: true,
2122
})
2223
}

internal/version.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package internal
2+
3+
var (
4+
// Version is the git tag that this was built from.
5+
Version = "unknown"
6+
// GitCommit is the commit that this was built from.
7+
GitCommit = "unknown"
8+
)

pkg/amazon/sdk/sdk.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import (
66
"strings"
77
"time"
88

9+
"github.com/docker/ecs-plugin/internal"
10+
11+
"github.com/aws/aws-sdk-go/aws/request"
12+
913
"github.com/aws/aws-sdk-go/aws"
1014
"github.com/aws/aws-sdk-go/aws/session"
1115
"github.com/aws/aws-sdk-go/service/cloudformation"
@@ -39,6 +43,9 @@ type sdk struct {
3943
}
4044

4145
func NewAPI(sess *session.Session) API {
46+
sess.Handlers.Build.PushBack(func(r *request.Request) {
47+
request.AddToUserAgent(r, fmt.Sprintf("Docker CLI %s", internal.Version))
48+
})
4249
return sdk{
4350
ECS: ecs.New(sess),
4451
EC2: ec2.New(sess),

0 commit comments

Comments
 (0)