Skip to content

Commit 5348dbf

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 8fc956c commit 5348dbf

File tree

3 files changed

+20
-57
lines changed

3 files changed

+20
-57
lines changed

cli/command/cli.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...Initialize
234234
cli.contextStore = &ContextStoreWithDefault{
235235
Store: store.New(config.ContextStoreDir(), cli.contextStoreConfig),
236236
Resolver: func() (*DefaultContext, error) {
237-
return ResolveDefaultContext(cli.options, cli.contextStoreConfig)
237+
return ResolveDefaultContext(cli.options)
238238
},
239239
}
240240
return nil
@@ -245,12 +245,10 @@ func NewAPIClientFromFlags(opts *cliflags.ClientOptions, configFile *configfile.
245245
if opts.Context != "" && len(opts.Hosts) > 0 {
246246
return nil, errors.New("conflicting options: either specify --host or --context, not both")
247247
}
248-
249-
storeConfig := DefaultContextStoreConfig()
250248
contextStore := &ContextStoreWithDefault{
251-
Store: store.New(config.ContextStoreDir(), storeConfig),
249+
Store: store.New(config.ContextStoreDir(), DefaultContextStoreConfig()),
252250
Resolver: func() (*DefaultContext, error) {
253-
return ResolveDefaultContext(opts, storeConfig)
251+
return ResolveDefaultContext(opts)
254252
},
255253
}
256254
endpoint, err := resolveDockerEndpoint(contextStore, resolveContextName(opts, configFile))

cli/command/defaultcontextstore.go

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,66 +28,31 @@ type ContextStoreWithDefault struct {
2828
Resolver DefaultContextResolver
2929
}
3030

31-
// EndpointDefaultResolver is implemented by any EndpointMeta object
32-
// which wants to be able to populate the store with whatever their default is.
33-
type EndpointDefaultResolver interface {
34-
// ResolveDefault returns values suitable for storing in store.Metadata.Endpoints
35-
// and store.ContextTLSData.Endpoints.
36-
//
37-
// An error is only returned for something fatal, not simply
38-
// the lack of a default (e.g. because the config file which
39-
// would contain it is missing). If there is no default then
40-
// returns nil, nil, nil.
41-
ResolveDefault() (interface{}, *store.EndpointTLSData, error)
42-
}
43-
4431
// ResolveDefaultContext creates a Metadata for the current CLI invocation parameters
45-
func ResolveDefaultContext(opts *cliflags.ClientOptions, config store.Config) (*DefaultContext, error) {
46-
contextTLSData := store.ContextTLSData{
47-
Endpoints: make(map[string]store.EndpointTLSData),
48-
}
49-
contextMetadata := store.Metadata{
50-
Endpoints: make(map[string]interface{}),
51-
Metadata: DockerContext{
52-
Description: "",
53-
},
54-
Name: DefaultContextName,
55-
}
56-
32+
func ResolveDefaultContext(opts *cliflags.ClientOptions) (*DefaultContext, error) {
5733
dockerEP, err := resolveDefaultDockerEndpoint(opts)
5834
if err != nil {
5935
return nil, err
6036
}
61-
contextMetadata.Endpoints[docker.DockerEndpoint] = dockerEP.EndpointMeta
37+
contextTLSData := store.ContextTLSData{}
6238
if dockerEP.TLSData != nil {
63-
contextTLSData.Endpoints[docker.DockerEndpoint] = *dockerEP.TLSData.ToStoreTLSData()
64-
}
65-
66-
if err := config.ForeachEndpointType(func(n string, get store.TypeGetter) error {
67-
if n == docker.DockerEndpoint { // handled above
68-
return nil
39+
contextTLSData.Endpoints = map[string]store.EndpointTLSData{
40+
docker.DockerEndpoint: *dockerEP.TLSData.ToStoreTLSData(),
6941
}
70-
ep := get()
71-
if i, ok := ep.(EndpointDefaultResolver); ok {
72-
meta, tls, err := i.ResolveDefault()
73-
if err != nil {
74-
return err
75-
}
76-
if meta == nil {
77-
return nil
78-
}
79-
contextMetadata.Endpoints[n] = meta
80-
if tls != nil {
81-
contextTLSData.Endpoints[n] = *tls
82-
}
83-
}
84-
// Nothing to be done
85-
return nil
86-
}); err != nil {
87-
return nil, err
8842
}
8943

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

9358
// 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
@@ -61,7 +61,7 @@ func TestDefaultContextInitializer(t *testing.T) {
6161
TLSOptions: &tlsconfig.Options{
6262
CAFile: "./testdata/ca.pem",
6363
},
64-
}, DefaultContextStoreConfig())
64+
})
6565
assert.NilError(t, err)
6666
assert.Equal(t, "default", ctx.Meta.Name)
6767
assert.DeepEqual(t, "ssh://someswarmserver", ctx.Meta.Endpoints[docker.DockerEndpoint].(docker.EndpointMeta).Host)

0 commit comments

Comments
 (0)