Add context store config options and expose context commands
This will allow plugins to have custom typed endpoints, as well as create/remove/update contexts with the exact same results as the main CLI (thinking of things like `docker ee login https://my-ucp-server --context ucp-prod)` Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
This commit is contained in:
@ -25,6 +25,11 @@ type Config struct {
|
||||
endpointTypes map[string]TypeGetter
|
||||
}
|
||||
|
||||
// SetEndpoint set an endpoint typing information
|
||||
func (c Config) SetEndpoint(name string, getter TypeGetter) {
|
||||
c.endpointTypes[name] = getter
|
||||
}
|
||||
|
||||
// NewConfig creates a config object
|
||||
func NewConfig(contextType TypeGetter, endpoints ...NamedTypeGetter) Config {
|
||||
res := Config{
|
||||
|
||||
31
cli/context/store/storeconfig_test.go
Normal file
31
cli/context/store/storeconfig_test.go
Normal file
@ -0,0 +1,31 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
type testCtx struct{}
|
||||
type testEP1 struct{}
|
||||
type testEP2 struct{}
|
||||
type testEP3 struct{}
|
||||
|
||||
func TestConfigModification(t *testing.T) {
|
||||
cfg := NewConfig(func() interface{} { return &testCtx{} }, EndpointTypeGetter("ep1", func() interface{} { return &testEP1{} }))
|
||||
assert.Equal(t, &testCtx{}, cfg.contextType())
|
||||
assert.Equal(t, &testEP1{}, cfg.endpointTypes["ep1"]())
|
||||
cfgCopy := cfg
|
||||
|
||||
// modify existing endpoint
|
||||
cfg.SetEndpoint("ep1", func() interface{} { return &testEP2{} })
|
||||
// add endpoint
|
||||
cfg.SetEndpoint("ep2", func() interface{} { return &testEP3{} })
|
||||
assert.Equal(t, &testCtx{}, cfg.contextType())
|
||||
assert.Equal(t, &testEP2{}, cfg.endpointTypes["ep1"]())
|
||||
assert.Equal(t, &testEP3{}, cfg.endpointTypes["ep2"]())
|
||||
// check it applied on already initialized store
|
||||
assert.Equal(t, &testCtx{}, cfgCopy.contextType())
|
||||
assert.Equal(t, &testEP2{}, cfgCopy.endpointTypes["ep1"]())
|
||||
assert.Equal(t, &testEP3{}, cfgCopy.endpointTypes["ep2"]())
|
||||
}
|
||||
Reference in New Issue
Block a user