diff --git a/go.mod b/go.mod index 8056e6378c88..fd9ed7c14046 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/creack/pty v1.1.24 github.com/davecgh/go-spew v1.1.1 github.com/distribution/reference v0.6.0 - github.com/docker/cli v29.1.2+incompatible + github.com/docker/cli v29.2.0+incompatible github.com/docker/cli-docs-tool v0.11.0 github.com/docker/docker v28.5.2+incompatible github.com/docker/go-units v0.5.0 diff --git a/go.sum b/go.sum index 55b623389755..1d70c8b5c2cb 100644 --- a/go.sum +++ b/go.sum @@ -98,8 +98,8 @@ github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5Qvfr github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= -github.com/docker/cli v29.1.2+incompatible h1:s4QI7drXpIo78OM+CwuthPsO5kCf8cpNsck5PsLVTH8= -github.com/docker/cli v29.1.2+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= +github.com/docker/cli v29.2.0+incompatible h1:9oBd9+YM7rxjZLfyMGxjraKBKE4/nVyvVfN4qNl9XRM= +github.com/docker/cli v29.2.0+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= github.com/docker/cli-docs-tool v0.11.0 h1:7d8QARFb7QEobizqxmEM7fOteZEHwH/zWgHQtHZEcfE= github.com/docker/cli-docs-tool v0.11.0/go.mod h1:ma8BKiisUo8D6W05XEYIh3oa1UbgrZhi1nowyKFJa8Q= github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk= diff --git a/vendor/github.com/docker/cli/cli/command/cli.go b/vendor/github.com/docker/cli/cli/command/cli.go index b1e9453343a1..42d01b95644e 100644 --- a/vendor/github.com/docker/cli/cli/command/cli.go +++ b/vendor/github.com/docker/cli/cli/command/cli.go @@ -60,6 +60,7 @@ type Cli interface { type DockerCli struct { configFile *configfile.ConfigFile options *cliflags.ClientOptions + clientOpts []client.Opt in *streams.In out *streams.Out err *streams.Out @@ -72,7 +73,6 @@ type DockerCli struct { dockerEndpoint docker.Endpoint contextStoreConfig *store.Config initTimeout time.Duration - userAgent string res telemetryResource // baseCtx is the base context used for internal operations. In the future @@ -533,8 +533,7 @@ func (cli *DockerCli) initialize() error { return } if cli.client == nil { - ops := []client.Opt{client.WithUserAgent(cli.userAgent)} - if cli.client, cli.initErr = newAPIClientFromEndpoint(cli.dockerEndpoint, cli.configFile, ops...); cli.initErr != nil { + if cli.client, cli.initErr = newAPIClientFromEndpoint(cli.dockerEndpoint, cli.configFile, cli.clientOpts...); cli.initErr != nil { return } } diff --git a/vendor/github.com/docker/cli/cli/command/cli_options.go b/vendor/github.com/docker/cli/cli/command/cli_options.go index f787956c5b7e..469932f9c399 100644 --- a/vendor/github.com/docker/cli/cli/command/cli_options.go +++ b/vendor/github.com/docker/cli/cli/command/cli_options.go @@ -104,6 +104,16 @@ func WithInitializeClient(makeClient func(*DockerCli) (client.APIClient, error)) } } +// WithAPIClientOptions configures additional [client.Opt] to use when +// initializing the API client. These options have no effect if a custom +// client is set (through [WithAPIClient] or [WithInitializeClient]). +func WithAPIClientOptions(c ...client.Opt) CLIOption { + return func(cli *DockerCli) error { + cli.clientOpts = append(cli.clientOpts, c...) + return nil + } +} + // envOverrideHTTPHeaders is the name of the environment-variable that can be // used to set custom HTTP headers to be sent by the client. This environment // variable is the equivalent to the HttpHeaders field in the configuration @@ -221,7 +231,7 @@ func WithUserAgent(userAgent string) CLIOption { if userAgent == "" { return errors.New("user agent cannot be blank") } - cli.userAgent = userAgent + cli.clientOpts = append(cli.clientOpts, client.WithUserAgent(userAgent)) return nil } } diff --git a/vendor/github.com/docker/cli/cli/command/registry.go b/vendor/github.com/docker/cli/cli/command/registry.go index 87c81c6da5da..452e2d7354cc 100644 --- a/vendor/github.com/docker/cli/cli/command/registry.go +++ b/vendor/github.com/docker/cli/cli/command/registry.go @@ -200,7 +200,7 @@ func RetrieveAuthTokenFromImage(cfg *configfile.ConfigFile, image string) (strin return "", err } - encodedAuth, err := authconfig.Encode(registrytypes.AuthConfig{ + return authconfig.Encode(registrytypes.AuthConfig{ Username: authConfig.Username, Password: authConfig.Password, ServerAddress: authConfig.ServerAddress, @@ -210,10 +210,6 @@ func RetrieveAuthTokenFromImage(cfg *configfile.ConfigFile, image string) (strin IdentityToken: authConfig.IdentityToken, RegistryToken: authConfig.RegistryToken, }) - if err != nil { - return "", err - } - return encodedAuth, nil } // getAuthConfigKey special-cases using the full index address of the official diff --git a/vendor/github.com/docker/cli/templates/templates.go b/vendor/github.com/docker/cli/templates/templates.go index e339050abb3f..1145e82c82ad 100644 --- a/vendor/github.com/docker/cli/templates/templates.go +++ b/vendor/github.com/docker/cli/templates/templates.go @@ -6,6 +6,9 @@ package templates import ( "bytes" "encoding/json" + "fmt" + "reflect" + "sort" "strings" "text/template" ) @@ -15,7 +18,7 @@ import ( var basicFunctions = template.FuncMap{ "json": formatJSON, "split": strings.Split, - "join": strings.Join, + "join": joinElements, "title": strings.Title, //nolint:nolintlint,staticcheck // strings.Title is deprecated, but we only use it for ASCII, so replacing with golang.org/x/text is out of scope "lower": strings.ToLower, "upper": strings.ToUpper, @@ -97,3 +100,40 @@ func formatJSON(v any) string { // Remove the trailing new line added by the encoder return strings.TrimSpace(buf.String()) } + +// joinElements joins a slice of items with the given separator. It uses +// [strings.Join] if it's a slice of strings, otherwise uses [fmt.Sprint] +// to join each item to the output. +func joinElements(elems any, sep string) (string, error) { + if elems == nil { + return "", nil + } + + if ss, ok := elems.([]string); ok { + return strings.Join(ss, sep), nil + } + + switch rv := reflect.ValueOf(elems); rv.Kind() { //nolint:exhaustive // ignore: too many options to make exhaustive + case reflect.Array, reflect.Slice: + var b strings.Builder + for i := range rv.Len() { + if i > 0 { + b.WriteString(sep) + } + _, _ = fmt.Fprint(&b, rv.Index(i).Interface()) + } + return b.String(), nil + + case reflect.Map: + var out []string + for _, k := range rv.MapKeys() { + out = append(out, fmt.Sprint(rv.MapIndex(k).Interface())) + } + // Not ideal, but trying to keep a consistent order + sort.Strings(out) + return strings.Join(out, sep), nil + + default: + return "", fmt.Errorf("expected slice, got %T", elems) + } +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 362aad49d1d5..df33f3b62809 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -219,7 +219,7 @@ github.com/davecgh/go-spew/spew # github.com/distribution/reference v0.6.0 ## explicit; go 1.20 github.com/distribution/reference -# github.com/docker/cli v29.1.2+incompatible +# github.com/docker/cli v29.2.0+incompatible ## explicit github.com/docker/cli/cli github.com/docker/cli/cli-plugins/metadata