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

Commit

Permalink
Customize SDK requests to AWS API with user-agent
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Jul 2, 2020
1 parent bad350b commit 98c4f8c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions builder.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ endif

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

BINARY=dist/docker-ecs
Expand Down
11 changes: 3 additions & 8 deletions cmd/commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@ package commands
import (
"fmt"

"github.com/spf13/cobra"
)
"github.com/docker/ecs-plugin/internal"

var (
// Version is the git tag that this was built from.
Version = "unknown"
// GitCommit is the commit that this was built from.
GitCommit = "unknown"
"github.com/spf13/cobra"
)

func VersionCommand() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Show version.",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Fprintf(cmd.OutOrStdout(), "Docker ECS plugin %s (%s)\n", Version, GitCommit)
fmt.Fprintf(cmd.OutOrStdout(), "Docker ECS plugin %s (%s)\n", internal.Version, internal.GitCommit)
return nil
},
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/commands/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"strings"
"testing"

"github.com/docker/ecs-plugin/internal"

"gotest.tools/v3/assert"
)

Expand All @@ -14,5 +16,5 @@ func TestVersion(t *testing.T) {
root.SetOut(&out)
root.SetArgs([]string{"version"})
root.Execute()
assert.Check(t, strings.Contains(out.String(), Version))
assert.Check(t, strings.Contains(out.String(), internal.Version))
}
3 changes: 2 additions & 1 deletion cmd/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"github.com/docker/ecs-plugin/cmd/commands"
"github.com/docker/ecs-plugin/internal"

"github.com/docker/cli/cli-plugins/manager"
"github.com/docker/cli/cli-plugins/plugin"
Expand All @@ -16,7 +17,7 @@ func main() {
}, manager.Metadata{
SchemaVersion: "0.1.0",
Vendor: "Docker Inc.",
Version: commands.Version,
Version: internal.Version,
Experimental: true,
})
}
8 changes: 8 additions & 0 deletions internal/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package internal

var (
// Version is the git tag that this was built from.
Version = "unknown"
// GitCommit is the commit that this was built from.
GitCommit = "unknown"
)
7 changes: 7 additions & 0 deletions pkg/amazon/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"strings"
"time"

"github.com/docker/ecs-plugin/internal"

"github.com/aws/aws-sdk-go/aws/request"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudformation"
Expand Down Expand Up @@ -39,6 +43,9 @@ type sdk struct {
}

func NewAPI(sess *session.Session) API {
sess.Handlers.Build.PushBack(func(r *request.Request) {
request.AddToUserAgent(r, fmt.Sprintf("Docker CLI %s", internal.Version))
})
return sdk{
ECS: ecs.New(sess),
EC2: ec2.New(sess),
Expand Down

0 comments on commit 98c4f8c

Please sign in to comment.