Skip to content

Commit 72264bc

Browse files
committed
cli/command: remove unused EndpointDefaultResolver interface
this was added as part of 520be05, but is not used anywhere, so we may as well simplify things a bit. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent c41c914 commit 72264bc

3 files changed

Lines changed: 21 additions & 56 deletions

File tree

cli/command/cli.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...Initialize
214214
cli.contextStore = &ContextStoreWithDefault{
215215
Store: baseContextStore,
216216
Resolver: func() (*DefaultContext, error) {
217-
return ResolveDefaultContext(opts.Common, cli.contextStoreConfig)
217+
return ResolveDefaultContext(opts.Common)
218218
},
219219
}
220220
cli.currentContext, err = resolveContextName(opts.Common, cli.configFile, cli.contextStore)
@@ -238,11 +238,10 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...Initialize
238238

239239
// NewAPIClientFromFlags creates a new APIClient from command line flags
240240
func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.ConfigFile) (client.APIClient, error) {
241-
storeConfig := DefaultContextStoreConfig()
242241
contextStore := &ContextStoreWithDefault{
243-
Store: store.New(config.ContextStoreDir(), storeConfig),
242+
Store: store.New(config.ContextStoreDir(), DefaultContextStoreConfig()),
244243
Resolver: func() (*DefaultContext, error) {
245-
return ResolveDefaultContext(opts, storeConfig)
244+
return ResolveDefaultContext(opts)
246245
},
247246
}
248247
contextName, err := resolveContextName(opts, configFile, contextStore)

cli/command/defaultcontextstore.go

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -29,66 +29,32 @@ type ContextStoreWithDefault struct {
2929
Resolver DefaultContextResolver
3030
}
3131

32-
// EndpointDefaultResolver is implemented by any EndpointMeta object
33-
// which wants to be able to populate the store with whatever their default is.
34-
type EndpointDefaultResolver interface {
35-
// ResolveDefault returns values suitable for storing in store.Metadata.Endpoints
36-
// and store.ContextTLSData.Endpoints.
37-
//
38-
// An error is only returned for something fatal, not simply
39-
// the lack of a default (e.g. because the config file which
40-
// would contain it is missing). If there is no default then
41-
// returns nil, nil, nil.
42-
ResolveDefault() (interface{}, *store.EndpointTLSData, error)
43-
}
44-
4532
// ResolveDefaultContext creates a Metadata for the current CLI invocation parameters
46-
func ResolveDefaultContext(opts *cliflags.CommonOptions, config store.Config) (*DefaultContext, error) {
47-
contextTLSData := store.ContextTLSData{
48-
Endpoints: make(map[string]store.EndpointTLSData),
49-
}
50-
contextMetadata := store.Metadata{
51-
Endpoints: make(map[string]interface{}),
52-
Metadata: DockerContext{
53-
Description: "",
54-
},
55-
Name: DefaultContextName,
56-
}
57-
33+
func ResolveDefaultContext(opts *cliflags.CommonOptions) (*DefaultContext, error) {
5834
dockerEP, err := resolveDefaultDockerEndpoint(opts)
5935
if err != nil {
6036
return nil, err
6137
}
62-
contextMetadata.Endpoints[docker.DockerEndpoint] = dockerEP.EndpointMeta
63-
if dockerEP.TLSData != nil {
64-
contextTLSData.Endpoints[docker.DockerEndpoint] = *dockerEP.TLSData.ToStoreTLSData()
65-
}
6638

67-
if err := config.ForeachEndpointType(func(n string, get store.TypeGetter) error {
68-
if n == docker.DockerEndpoint { // handled above
69-
return nil
70-
}
71-
ep := get()
72-
if i, ok := ep.(EndpointDefaultResolver); ok {
73-
meta, tls, err := i.ResolveDefault()
74-
if err != nil {
75-
return err
76-
}
77-
if meta == nil {
78-
return nil
79-
}
80-
contextMetadata.Endpoints[n] = meta
81-
if tls != nil {
82-
contextTLSData.Endpoints[n] = *tls
83-
}
39+
contextTLSData := store.ContextTLSData{}
40+
if dockerEP.TLSData != nil {
41+
contextTLSData.Endpoints = map[string]store.EndpointTLSData{
42+
docker.DockerEndpoint: *dockerEP.TLSData.ToStoreTLSData(),
8443
}
85-
// Nothing to be done
86-
return nil
87-
}); err != nil {
88-
return nil, err
8944
}
9045

91-
return &DefaultContext{Meta: contextMetadata, TLS: contextTLSData}, nil
46+
return &DefaultContext{
47+
Meta: store.Metadata{
48+
Endpoints: map[string]interface{}{
49+
docker.DockerEndpoint: dockerEP.EndpointMeta,
50+
},
51+
Metadata: DockerContext{
52+
Description: "",
53+
},
54+
Name: DefaultContextName,
55+
},
56+
TLS: contextTLSData,
57+
}, nil
9258
}
9359

9460
// List implements store.Store's List

cli/command/defaultcontextstore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestDefaultContextInitializer(t *testing.T) {
6060
TLSOptions: &tlsconfig.Options{
6161
CAFile: "./testdata/ca.pem",
6262
},
63-
}, DefaultContextStoreConfig())
63+
})
6464
assert.NilError(t, err)
6565
assert.Equal(t, "default", ctx.Meta.Name)
6666
assert.DeepEqual(t, "ssh://someswarmserver", ctx.Meta.Endpoints[docker.DockerEndpoint].(docker.EndpointMeta).Host)

0 commit comments

Comments
 (0)