Implement WithDefaultContextStoreConfig() DockerCliOption

Just a minor refactor to make this slightly cleaner

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2021-03-03 12:09:20 +01:00
parent d35b50c0c3
commit cc08fc1af0
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 11 additions and 2 deletions

View File

@ -422,12 +422,13 @@ type ClientInfo struct {
// It applies by default the standard streams, and the content trust from // It applies by default the standard streams, and the content trust from
// environment. // environment.
func NewDockerCli(ops ...DockerCliOption) (*DockerCli, error) { func NewDockerCli(ops ...DockerCliOption) (*DockerCli, error) {
cli := &DockerCli{}
defaultOps := []DockerCliOption{ defaultOps := []DockerCliOption{
WithContentTrustFromEnv(), WithContentTrustFromEnv(),
WithDefaultContextStoreConfig(),
} }
cli.contextStoreConfig = DefaultContextStoreConfig()
ops = append(defaultOps, ops...) ops = append(defaultOps, ops...)
cli := &DockerCli{}
if err := cli.Apply(ops...); err != nil { if err := cli.Apply(ops...); err != nil {
return nil, err return nil, err
} }

View File

@ -94,3 +94,11 @@ func WithContextEndpointType(endpointName string, endpointType store.TypeGetter)
return nil return nil
} }
} }
// WithDefaultContextStoreConfig configures the cli to use the default context store configuration.
func WithDefaultContextStoreConfig() DockerCliOption {
return func(cli *DockerCli) error {
cli.contextStoreConfig = DefaultContextStoreConfig()
return nil
}
}