Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli/command: remove unused args from ResolveDefaultContext() #3715

Merged
merged 3 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/command/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...Initialize
cli.contextStore = &ContextStoreWithDefault{
Store: baseContextStore,
Resolver: func() (*DefaultContext, error) {
return ResolveDefaultContext(opts.Common, cli.ConfigFile(), cli.contextStoreConfig, cli.Err())
return ResolveDefaultContext(opts.Common, cli.contextStoreConfig)
},
}
cli.currentContext, err = resolveContextName(opts.Common, cli.configFile, cli.contextStore)
Expand Down Expand Up @@ -244,7 +244,7 @@ func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.
contextStore := &ContextStoreWithDefault{
Store: store.New(config.ContextStoreDir(), storeConfig),
Resolver: func() (*DefaultContext, error) {
return ResolveDefaultContext(opts, configFile, storeConfig, io.Discard)
return ResolveDefaultContext(opts, storeConfig)
},
}
contextName, err := resolveContextName(opts, configFile, contextStore)
Expand Down
16 changes: 0 additions & 16 deletions cli/command/cli_options.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package command

import (
"fmt"
"io"
"os"
"strconv"

"github.com/docker/cli/cli/context/docker"
"github.com/docker/cli/cli/context/store"
"github.com/docker/cli/cli/streams"
"github.com/moby/term"
)
Expand Down Expand Up @@ -82,19 +79,6 @@ func WithContentTrust(enabled bool) DockerCliOption {
}
}

// WithContextEndpointType add support for an additional typed endpoint in the context store
// Plugins should use this to store additional endpoints configuration in the context store
func WithContextEndpointType(endpointName string, endpointType store.TypeGetter) DockerCliOption {
return func(cli *DockerCli) error {
switch endpointName {
case docker.DockerEndpoint:
return fmt.Errorf("cannot change %q endpoint type", endpointName)
}
cli.contextStoreConfig.SetEndpoint(endpointName, endpointType)
return nil
}
}

// WithDefaultContextStoreConfig configures the cli to use the default context store configuration.
func WithDefaultContextStoreConfig() DockerCliOption {
return func(cli *DockerCli) error {
Expand Down
29 changes: 13 additions & 16 deletions cli/command/context/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,24 @@ func createNewContext(o *CreateOptions, cli command.Cli, s store.Writer) error {
if o.Docker == nil {
return errors.New("docker endpoint configuration is required")
}
contextMetadata := newContextMetadata(o)
contextTLSData := store.ContextTLSData{
Endpoints: make(map[string]store.EndpointTLSData),
}
dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(cli, o.Docker)
if err != nil {
return errors.Wrap(err, "unable to create docker endpoint config")
}
contextMetadata.Endpoints[docker.DockerEndpoint] = dockerEP
contextMetadata := store.Metadata{
Endpoints: map[string]interface{}{
docker.DockerEndpoint: dockerEP,
},
Metadata: command.DockerContext{
Description: o.Description,
},
Name: o.Name,
}
contextTLSData := store.ContextTLSData{}
if dockerTLS != nil {
contextTLSData.Endpoints[docker.DockerEndpoint] = *dockerTLS
contextTLSData.Endpoints = map[string]store.EndpointTLSData{
docker.DockerEndpoint: *dockerTLS,
}
}
if err := validateEndpoints(contextMetadata); err != nil {
return err
Expand Down Expand Up @@ -161,13 +168,3 @@ func (d *descriptionDecorator) GetMetadata(name string) (store.Metadata, error)
c.Metadata = typedContext
return c, nil
}

func newContextMetadata(o *CreateOptions) store.Metadata {
return store.Metadata{
Endpoints: make(map[string]interface{}),
Metadata: command.DockerContext{
Description: o.Description,
},
Name: o.Name,
}
}
6 changes: 2 additions & 4 deletions cli/command/defaultcontextstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package command

import (
"fmt"
"io"

"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/context/docker"
"github.com/docker/cli/cli/context/store"
cliflags "github.com/docker/cli/cli/flags"
Expand Down Expand Up @@ -45,7 +43,7 @@ type EndpointDefaultResolver interface {
}

// ResolveDefaultContext creates a Metadata for the current CLI invocation parameters
func ResolveDefaultContext(opts *cliflags.CommonOptions, config *configfile.ConfigFile, storeconfig store.Config, stderr io.Writer) (*DefaultContext, error) {
func ResolveDefaultContext(opts *cliflags.CommonOptions, config store.Config) (*DefaultContext, error) {
contextTLSData := store.ContextTLSData{
Endpoints: make(map[string]store.EndpointTLSData),
}
Expand All @@ -66,7 +64,7 @@ func ResolveDefaultContext(opts *cliflags.CommonOptions, config *configfile.Conf
contextTLSData.Endpoints[docker.DockerEndpoint] = *dockerEP.TLSData.ToStoreTLSData()
}

if err := storeconfig.ForeachEndpointType(func(n string, get store.TypeGetter) error {
if err := config.ForeachEndpointType(func(n string, get store.TypeGetter) error {
if n == docker.DockerEndpoint { // handled above
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cli/command/defaultcontextstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestDefaultContextInitializer(t *testing.T) {
TLSOptions: &tlsconfig.Options{
CAFile: "./testdata/ca.pem",
},
}, cli.ConfigFile(), DefaultContextStoreConfig(), cli.Err())
}, DefaultContextStoreConfig())
assert.NilError(t, err)
assert.Equal(t, "default", ctx.Meta.Name)
assert.DeepEqual(t, "ssh://someswarmserver", ctx.Meta.Endpoints[docker.DockerEndpoint].(docker.EndpointMeta).Host)
Expand Down