Skip to content

Commit dbe7819

Browse files
authored
Merge pull request docker#11333 from milas/hack-user-agent
feat(cli): report more useful User-Agent on engine API requests
2 parents 6f62bcc + b621948 commit dbe7819

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

cmd/main.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/docker/cli/cli-plugins/plugin"
2525
"github.com/docker/cli/cli/command"
2626
"github.com/docker/compose/v2/cmd/cmdtrace"
27+
"github.com/docker/docker/client"
2728
"github.com/spf13/cobra"
2829

2930
"github.com/docker/compose/v2/cmd/compatibility"
@@ -42,6 +43,9 @@ func pluginMain() {
4243
if err := plugin.PersistentPreRunE(cmd, args); err != nil {
4344
return err
4445
}
46+
// compose-specific initialization
47+
dockerCliPostInitialize(dockerCli)
48+
4549
// TODO(milas): add an env var to enable logging from the
4650
// OTel components for debugging purposes
4751
_ = cmdtrace.Setup(cmd, dockerCli, os.Args[1:])
@@ -67,6 +71,22 @@ func pluginMain() {
6771
})
6872
}
6973

74+
// dockerCliPostInitialize performs Compose-specific configuration for the
75+
// command.Cli instance provided by the plugin.Run() initialization.
76+
//
77+
// NOTE: This must be called AFTER plugin.PersistentPreRunE.
78+
func dockerCliPostInitialize(dockerCli command.Cli) {
79+
// HACK(milas): remove once docker/cli#4574 is merged; for now,
80+
// set it in a rather roundabout way by grabbing the underlying
81+
// concrete client and manually invoking an option on it
82+
_ = dockerCli.Apply(func(cli *command.DockerCli) error {
83+
if mobyClient, ok := cli.Client().(*client.Client); ok {
84+
_ = client.WithUserAgent("compose/" + internal.Version)(mobyClient)
85+
}
86+
return nil
87+
})
88+
}
89+
7090
func main() {
7191
if plugin.RunningStandalone() {
7292
os.Args = append([]string{"docker"}, compatibility.Convert(os.Args[1:])...)

0 commit comments

Comments
 (0)