cli/command/context: don't pass CLI if we only need context-store

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-06-20 13:36:54 +02:00
parent 7d723e2ba7
commit 8181aa8879
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
3 changed files with 10 additions and 11 deletions

View File

@ -80,7 +80,7 @@ func RunCreate(cli command.Cli, o *CreateOptions) error {
case o.From != "":
err = createFromExistingContext(s, o.From, o)
default:
err = createNewContext(o, cli, s)
err = createNewContext(s, o)
}
if err == nil {
fmt.Fprintln(cli.Out(), o.Name)
@ -89,11 +89,11 @@ func RunCreate(cli command.Cli, o *CreateOptions) error {
return err
}
func createNewContext(o *CreateOptions, cli command.Cli, s store.Writer) error {
func createNewContext(contextStore store.ReaderWriter, o *CreateOptions) error {
if o.Docker == nil {
return errors.New("docker endpoint configuration is required")
}
dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(cli, o.Docker)
dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(contextStore, o.Docker)
if err != nil {
return errors.Wrap(err, "unable to create docker endpoint config")
}
@ -115,10 +115,10 @@ func createNewContext(o *CreateOptions, cli command.Cli, s store.Writer) error {
if err := validateEndpoints(contextMetadata); err != nil {
return err
}
if err := s.CreateOrUpdate(contextMetadata); err != nil {
if err := contextStore.CreateOrUpdate(contextMetadata); err != nil {
return err
}
return s.ResetTLSMaterial(o.Name, &contextTLSData)
return contextStore.ResetTLSMaterial(o.Name, &contextTLSData)
}
func checkContextNameForCreation(s store.Reader, name string) error {

View File

@ -5,7 +5,6 @@ import (
"strconv"
"strings"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/context"
"github.com/docker/cli/cli/context/docker"
"github.com/docker/cli/cli/context/store"
@ -86,12 +85,12 @@ func validateConfig(config map[string]string, allowedKeys map[string]struct{}) e
return errors.New(strings.Join(errs, "\n"))
}
func getDockerEndpoint(dockerCli command.Cli, config map[string]string) (docker.Endpoint, error) {
func getDockerEndpoint(contextStore store.Reader, config map[string]string) (docker.Endpoint, error) {
if err := validateConfig(config, allowedDockerConfigKeys); err != nil {
return docker.Endpoint{}, err
}
if contextName, ok := config[keyFrom]; ok {
metadata, err := dockerCli.ContextStore().GetMetadata(contextName)
metadata, err := contextStore.GetMetadata(contextName)
if err != nil {
return docker.Endpoint{}, err
}
@ -126,8 +125,8 @@ func getDockerEndpoint(dockerCli command.Cli, config map[string]string) (docker.
return ep, nil
}
func getDockerEndpointMetadataAndTLS(dockerCli command.Cli, config map[string]string) (docker.EndpointMeta, *store.EndpointTLSData, error) {
ep, err := getDockerEndpoint(dockerCli, config)
func getDockerEndpointMetadataAndTLS(contextStore store.Reader, config map[string]string) (docker.EndpointMeta, *store.EndpointTLSData, error) {
ep, err := getDockerEndpoint(contextStore, config)
if err != nil {
return docker.EndpointMeta{}, nil, err
}

View File

@ -84,7 +84,7 @@ func RunUpdate(cli command.Cli, o *UpdateOptions) error {
tlsDataToReset := make(map[string]*store.EndpointTLSData)
if o.Docker != nil {
dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(cli, o.Docker)
dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(s, o.Docker)
if err != nil {
return errors.Wrap(err, "unable to create docker endpoint config")
}