mirror of
https://github.com/docker/compose.git
synced 2026-08-27 03:45:29 +00:00
replace passing parameters by context with singletons
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
9301c298ef
commit
48402585fd
47 changed files with 169 additions and 205 deletions
|
|
@ -40,7 +40,7 @@ func unaryServerInterceptor(clictx context.Context) grpc.UnaryServerInterceptor
|
|||
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
|
||||
currentContext, err := getIncomingContext(ctx)
|
||||
if err != nil {
|
||||
currentContext, err = getConfigContext(clictx)
|
||||
currentContext, err = getConfigContext()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ func streamServerInterceptor(clictx context.Context) grpc.StreamServerIntercepto
|
|||
return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
|
||||
currentContext, err := getIncomingContext(ss.Context())
|
||||
if err != nil {
|
||||
currentContext, err = getConfigContext(clictx)
|
||||
currentContext, err = getConfigContext()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -77,8 +77,8 @@ func streamServerInterceptor(clictx context.Context) grpc.StreamServerIntercepto
|
|||
}
|
||||
|
||||
// Returns the current context from the configuration file
|
||||
func getConfigContext(ctx context.Context) (string, error) {
|
||||
configDir := config.Dir(ctx)
|
||||
func getConfigContext() (string, error) {
|
||||
configDir := config.Dir()
|
||||
configFile, err := config.LoadFile(configDir)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
@ -100,9 +100,9 @@ func getIncomingContext(ctx context.Context) (string, error) {
|
|||
// configureContext populates the request context with objects the client
|
||||
// needs: the context store and the api client
|
||||
func configureContext(ctx context.Context, currentContext string, method string) (context.Context, error) {
|
||||
configDir := config.Dir(ctx)
|
||||
configDir := config.Dir()
|
||||
|
||||
ctx = apicontext.WithCurrentContext(ctx, currentContext)
|
||||
apicontext.WithCurrentContext(currentContext)
|
||||
|
||||
// The contexts service doesn't need the client
|
||||
if !strings.Contains(method, "/com.docker.api.protos.context.v1.Contexts") {
|
||||
|
|
@ -118,7 +118,7 @@ func configureContext(ctx context.Context, currentContext string, method string)
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ctx = store.WithContextStore(ctx, s)
|
||||
store.WithContextStore(s)
|
||||
|
||||
return ctx, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ func testContext(t *testing.T) context.Context {
|
|||
})
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = config.WithDir(ctx, dir)
|
||||
config.WithDir(dir)
|
||||
err = ioutil.WriteFile(path.Join(dir, "config.json"), []byte(`{"currentContext": "default"}`), 0644)
|
||||
assert.NilError(t, err)
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ func callStream(ctx context.Context, t *testing.T, interceptor grpc.StreamServer
|
|||
}, &grpc.StreamServerInfo{
|
||||
FullMethod: "/com.docker.api.protos.context.v1.Contexts/test",
|
||||
}, func(srv interface{}, stream grpc.ServerStream) error {
|
||||
currentContext = apicontext.CurrentContext(stream.Context())
|
||||
currentContext = apicontext.Current()
|
||||
return nil
|
||||
})
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ func callUnary(ctx context.Context, t *testing.T, interceptor grpc.UnaryServerIn
|
|||
resp, err := interceptor(ctx, nil, &grpc.UnaryServerInfo{
|
||||
FullMethod: "/com.docker.api.protos.context.v1.Contexts/test",
|
||||
}, func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
currentContext = apicontext.CurrentContext(ctx)
|
||||
currentContext = apicontext.Current()
|
||||
return nil, nil
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ func (cp *contextsProxy) SetCurrent(ctx context.Context, request *contextsv1.Set
|
|||
}
|
||||
|
||||
func (cp *contextsProxy) List(ctx context.Context, request *contextsv1.ListRequest) (*contextsv1.ListResponse, error) {
|
||||
s := store.ContextStore(ctx)
|
||||
s := store.Instance()
|
||||
configFile, err := config.LoadFile(cp.configDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ type proxy struct {
|
|||
|
||||
// New creates a new proxy server
|
||||
func New(ctx context.Context) Proxy {
|
||||
configDir := config.Dir(ctx)
|
||||
configDir := config.Dir()
|
||||
return &proxy{
|
||||
configDir: configDir,
|
||||
streams: map[string]*streams.Stream{},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue