Files
moby/client/pkg/security/security_opts.go
Sebastiaan van Stijn 31f7f62d6c client/pkg/security: simplify
This utility is used to split the SecurityOptions field from the
"/info" response into a slice of security.Option. It's effectively
only used by the CLI to present the `docker info` output, but has
a use in buildx to parse the response.

We can assume the daemon returns a valid response, remove the error-
conditions and fallback for legacy daemon versions (< 1.13), and limit
it to parsing the response only.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-03 11:36:44 +01:00

41 lines
777 B
Go

package security
import (
"strings"
)
// Option contains the name and options of a security option
type Option struct {
Name string
Options []KeyValue
}
// KeyValue holds a key/value pair.
type KeyValue struct {
Key, Value string
}
// DecodeOptions decodes a security options string slice to a
// type-safe [Option].
func DecodeOptions(opts []string) []Option {
so := make([]Option, 0, len(opts))
for _, opt := range opts {
secopt := Option{}
for _, s := range strings.Split(opt, ",") {
k, v, _ := strings.Cut(s, "=")
if k == "" {
continue
}
if k == "name" {
secopt.Name = v
continue
}
secopt.Options = append(secopt.Options, KeyValue{Key: k, Value: v})
}
if secopt.Name != "" {
so = append(so, secopt)
}
}
return so
}