mirror of
https://github.com/docker/compose.git
synced 2025-07-27 15:44:08 +02:00
Merge pull request #182 from rumpl/feat-context-server
Feat context server
This commit is contained in:
commit
574a378886
@ -33,7 +33,7 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
cliconfig "github.com/docker/api/cli/config"
|
"github.com/docker/api/config"
|
||||||
"github.com/docker/api/context/store"
|
"github.com/docker/api/context/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ func runUse(ctx context.Context, name string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := cliconfig.WriteCurrentContext(cliconfig.Dir(ctx), name); err != nil {
|
if err := config.WriteCurrentContext(config.Dir(ctx), name); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println(name)
|
fmt.Println(name)
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
apicontext "github.com/docker/api/context"
|
||||||
containersv1 "github.com/docker/api/protos/containers/v1"
|
containersv1 "github.com/docker/api/protos/containers/v1"
|
||||||
contextsv1 "github.com/docker/api/protos/contexts/v1"
|
contextsv1 "github.com/docker/api/protos/contexts/v1"
|
||||||
streamsv1 "github.com/docker/api/protos/streams/v1"
|
streamsv1 "github.com/docker/api/protos/streams/v1"
|
||||||
@ -45,12 +46,11 @@ func runServe(ctx context.Context, opts serveOpts) error {
|
|||||||
// nolint errcheck
|
// nolint errcheck
|
||||||
defer listener.Close()
|
defer listener.Close()
|
||||||
|
|
||||||
p := proxy.New()
|
p := proxy.New(apicontext.CurrentContext(ctx))
|
||||||
contextsService := server.NewContexts()
|
|
||||||
|
|
||||||
containersv1.RegisterContainersServer(s, p)
|
containersv1.RegisterContainersServer(s, p)
|
||||||
streamsv1.RegisterStreamingServer(s, p)
|
streamsv1.RegisterStreamingServer(s, p)
|
||||||
contextsv1.RegisterContextsServer(s, contextsService)
|
contextsv1.RegisterContextsServer(s, p.ContextsProxy())
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
|
@ -32,15 +32,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
"github.com/docker/api/config"
|
||||||
// ConfigFileName is the name of config file
|
|
||||||
ConfigFileName = "config.json"
|
|
||||||
// ConfigFileDir is the default folder where the config file is stored
|
|
||||||
ConfigFileDir = ".docker"
|
|
||||||
// ConfigFlagName is the name of the config flag
|
|
||||||
ConfigFlagName = "config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConfigFlags are the global CLI flags
|
// ConfigFlags are the global CLI flags
|
||||||
@ -51,7 +44,7 @@ type ConfigFlags struct {
|
|||||||
|
|
||||||
// AddConfigFlags adds persistent (global) flags
|
// AddConfigFlags adds persistent (global) flags
|
||||||
func (c *ConfigFlags) AddConfigFlags(flags *pflag.FlagSet) {
|
func (c *ConfigFlags) AddConfigFlags(flags *pflag.FlagSet) {
|
||||||
flags.StringVar(&c.Config, ConfigFlagName, confDir(), "Location of the client config files `DIRECTORY`")
|
flags.StringVar(&c.Config, config.ConfigFlagName, confDir(), "Location of the client config files `DIRECTORY`")
|
||||||
}
|
}
|
||||||
|
|
||||||
func confDir() string {
|
func confDir() string {
|
||||||
@ -60,5 +53,5 @@ func confDir() string {
|
|||||||
return env
|
return env
|
||||||
}
|
}
|
||||||
home, _ := os.UserHomeDir()
|
home, _ := os.UserHomeDir()
|
||||||
return filepath.Join(home, ConfigFileDir)
|
return filepath.Join(home, config.ConfigFileDir)
|
||||||
}
|
}
|
||||||
|
12
cli/main.go
12
cli/main.go
@ -38,10 +38,6 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/api/cli/cmd/login"
|
|
||||||
|
|
||||||
"github.com/docker/api/cli/dockerclassic"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -54,9 +50,11 @@ import (
|
|||||||
"github.com/docker/api/cli/cmd"
|
"github.com/docker/api/cli/cmd"
|
||||||
"github.com/docker/api/cli/cmd/compose"
|
"github.com/docker/api/cli/cmd/compose"
|
||||||
contextcmd "github.com/docker/api/cli/cmd/context"
|
contextcmd "github.com/docker/api/cli/cmd/context"
|
||||||
|
"github.com/docker/api/cli/cmd/login"
|
||||||
"github.com/docker/api/cli/cmd/run"
|
"github.com/docker/api/cli/cmd/run"
|
||||||
cliconfig "github.com/docker/api/cli/config"
|
"github.com/docker/api/cli/dockerclassic"
|
||||||
cliopts "github.com/docker/api/cli/options"
|
cliopts "github.com/docker/api/cli/options"
|
||||||
|
"github.com/docker/api/config"
|
||||||
apicontext "github.com/docker/api/context"
|
apicontext "github.com/docker/api/context"
|
||||||
"github.com/docker/api/context/store"
|
"github.com/docker/api/context/store"
|
||||||
)
|
)
|
||||||
@ -151,7 +149,7 @@ func main() {
|
|||||||
fatal(errors.New("config path cannot be empty"))
|
fatal(errors.New("config path cannot be empty"))
|
||||||
}
|
}
|
||||||
configDir := opts.Config
|
configDir := opts.Config
|
||||||
ctx = cliconfig.WithDir(ctx, configDir)
|
ctx = config.WithDir(ctx, configDir)
|
||||||
|
|
||||||
currentContext, err := determineCurrentContext(opts.Context, configDir)
|
currentContext, err := determineCurrentContext(opts.Context, configDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -206,7 +204,7 @@ func newSigContext() (context.Context, func()) {
|
|||||||
func determineCurrentContext(flag string, configDir string) (string, error) {
|
func determineCurrentContext(flag string, configDir string) (string, error) {
|
||||||
res := flag
|
res := flag
|
||||||
if res == "" {
|
if res == "" {
|
||||||
config, err := cliconfig.LoadFile(configDir)
|
config, err := config.LoadFile(configDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/docker/api/cli/config"
|
"github.com/docker/api/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
var contextSetConfig = []byte(`{
|
var contextSetConfig = []byte(`{
|
||||||
|
@ -27,6 +27,15 @@
|
|||||||
|
|
||||||
package config
|
package config
|
||||||
|
|
||||||
|
const (
|
||||||
|
// ConfigFileName is the name of config file
|
||||||
|
ConfigFileName = "config.json"
|
||||||
|
// ConfigFileDir is the default folder where the config file is stored
|
||||||
|
ConfigFileDir = ".docker"
|
||||||
|
// ConfigFlagName is the name of the config flag
|
||||||
|
ConfigFlagName = "config"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// currentContextKey is the key used in the Docker config file to set the
|
// currentContextKey is the key used in the Docker config file to set the
|
||||||
// default context
|
// default context
|
@ -62,6 +62,7 @@ type Context struct {
|
|||||||
|
|
||||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||||
ContextType string `protobuf:"bytes,2,opt,name=contextType,proto3" json:"contextType,omitempty"`
|
ContextType string `protobuf:"bytes,2,opt,name=contextType,proto3" json:"contextType,omitempty"`
|
||||||
|
Current bool `protobuf:"varint,3,opt,name=current,proto3" json:"current,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Context) Reset() {
|
func (x *Context) Reset() {
|
||||||
@ -110,6 +111,98 @@ func (x *Context) GetContextType() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *Context) GetCurrent() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.Current
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
type SetCurrentRequest struct {
|
||||||
|
state protoimpl.MessageState
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
|
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SetCurrentRequest) Reset() {
|
||||||
|
*x = SetCurrentRequest{}
|
||||||
|
if protoimpl.UnsafeEnabled {
|
||||||
|
mi := &file_protos_contexts_v1_contexts_proto_msgTypes[1]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SetCurrentRequest) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*SetCurrentRequest) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *SetCurrentRequest) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_protos_contexts_v1_contexts_proto_msgTypes[1]
|
||||||
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use SetCurrentRequest.ProtoReflect.Descriptor instead.
|
||||||
|
func (*SetCurrentRequest) Descriptor() ([]byte, []int) {
|
||||||
|
return file_protos_contexts_v1_contexts_proto_rawDescGZIP(), []int{1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SetCurrentRequest) GetName() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Name
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type SetCurrentResponse struct {
|
||||||
|
state protoimpl.MessageState
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SetCurrentResponse) Reset() {
|
||||||
|
*x = SetCurrentResponse{}
|
||||||
|
if protoimpl.UnsafeEnabled {
|
||||||
|
mi := &file_protos_contexts_v1_contexts_proto_msgTypes[2]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SetCurrentResponse) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*SetCurrentResponse) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *SetCurrentResponse) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_protos_contexts_v1_contexts_proto_msgTypes[2]
|
||||||
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use SetCurrentResponse.ProtoReflect.Descriptor instead.
|
||||||
|
func (*SetCurrentResponse) Descriptor() ([]byte, []int) {
|
||||||
|
return file_protos_contexts_v1_contexts_proto_rawDescGZIP(), []int{2}
|
||||||
|
}
|
||||||
|
|
||||||
type ListRequest struct {
|
type ListRequest struct {
|
||||||
state protoimpl.MessageState
|
state protoimpl.MessageState
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
@ -119,7 +212,7 @@ type ListRequest struct {
|
|||||||
func (x *ListRequest) Reset() {
|
func (x *ListRequest) Reset() {
|
||||||
*x = ListRequest{}
|
*x = ListRequest{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_protos_contexts_v1_contexts_proto_msgTypes[1]
|
mi := &file_protos_contexts_v1_contexts_proto_msgTypes[3]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@ -132,7 +225,7 @@ func (x *ListRequest) String() string {
|
|||||||
func (*ListRequest) ProtoMessage() {}
|
func (*ListRequest) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *ListRequest) ProtoReflect() protoreflect.Message {
|
func (x *ListRequest) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_protos_contexts_v1_contexts_proto_msgTypes[1]
|
mi := &file_protos_contexts_v1_contexts_proto_msgTypes[3]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@ -145,7 +238,7 @@ func (x *ListRequest) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use ListRequest.ProtoReflect.Descriptor instead.
|
// Deprecated: Use ListRequest.ProtoReflect.Descriptor instead.
|
||||||
func (*ListRequest) Descriptor() ([]byte, []int) {
|
func (*ListRequest) Descriptor() ([]byte, []int) {
|
||||||
return file_protos_contexts_v1_contexts_proto_rawDescGZIP(), []int{1}
|
return file_protos_contexts_v1_contexts_proto_rawDescGZIP(), []int{3}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListResponse struct {
|
type ListResponse struct {
|
||||||
@ -159,7 +252,7 @@ type ListResponse struct {
|
|||||||
func (x *ListResponse) Reset() {
|
func (x *ListResponse) Reset() {
|
||||||
*x = ListResponse{}
|
*x = ListResponse{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_protos_contexts_v1_contexts_proto_msgTypes[2]
|
mi := &file_protos_contexts_v1_contexts_proto_msgTypes[4]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@ -172,7 +265,7 @@ func (x *ListResponse) String() string {
|
|||||||
func (*ListResponse) ProtoMessage() {}
|
func (*ListResponse) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *ListResponse) ProtoReflect() protoreflect.Message {
|
func (x *ListResponse) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_protos_contexts_v1_contexts_proto_msgTypes[2]
|
mi := &file_protos_contexts_v1_contexts_proto_msgTypes[4]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@ -185,7 +278,7 @@ func (x *ListResponse) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use ListResponse.ProtoReflect.Descriptor instead.
|
// Deprecated: Use ListResponse.ProtoReflect.Descriptor instead.
|
||||||
func (*ListResponse) Descriptor() ([]byte, []int) {
|
func (*ListResponse) Descriptor() ([]byte, []int) {
|
||||||
return file_protos_contexts_v1_contexts_proto_rawDescGZIP(), []int{2}
|
return file_protos_contexts_v1_contexts_proto_rawDescGZIP(), []int{4}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ListResponse) GetContexts() []*Context {
|
func (x *ListResponse) GetContexts() []*Context {
|
||||||
@ -202,28 +295,41 @@ var file_protos_contexts_v1_contexts_proto_rawDesc = []byte{
|
|||||||
0x73, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x73, 0x2e, 0x70, 0x72,
|
0x73, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x73, 0x2e, 0x70, 0x72,
|
||||||
0x6f, 0x74, 0x6f, 0x12, 0x20, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e,
|
0x6f, 0x74, 0x6f, 0x12, 0x20, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e,
|
||||||
0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x65,
|
0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x65,
|
||||||
0x78, 0x74, 0x2e, 0x76, 0x31, 0x22, 0x3f, 0x0a, 0x07, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74,
|
0x78, 0x74, 0x2e, 0x76, 0x31, 0x22, 0x59, 0x0a, 0x07, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74,
|
||||||
0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
|
0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
|
||||||
0x6e, 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x54,
|
0x6e, 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x54,
|
||||||
0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x65,
|
0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x65,
|
||||||
0x78, 0x74, 0x54, 0x79, 0x70, 0x65, 0x22, 0x0d, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65,
|
0x78, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e,
|
||||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x55, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73,
|
0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74,
|
||||||
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x45, 0x0a, 0x08, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74,
|
0x22, 0x27, 0x0a, 0x11, 0x53, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x52, 0x65,
|
||||||
0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f,
|
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20,
|
||||||
0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e,
|
0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x14, 0x0a, 0x12, 0x53, 0x65, 0x74,
|
||||||
0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x65,
|
0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
|
||||||
0x78, 0x74, 0x52, 0x08, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x73, 0x32, 0x71, 0x0a, 0x08,
|
0x0d, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x55,
|
||||||
0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x73, 0x12, 0x65, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74,
|
0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x45,
|
||||||
0x12, 0x2d, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70,
|
0x0a, 0x08, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b,
|
||||||
|
0x32, 0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70,
|
||||||
0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74,
|
0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74,
|
||||||
0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
|
0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x52, 0x08, 0x63, 0x6f, 0x6e,
|
||||||
0x2e, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69,
|
0x74, 0x65, 0x78, 0x74, 0x73, 0x32, 0xea, 0x01, 0x0a, 0x08, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78,
|
||||||
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x2e,
|
0x74, 0x73, 0x12, 0x77, 0x0a, 0x0a, 0x53, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74,
|
||||||
0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42,
|
0x12, 0x33, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70,
|
||||||
0x2c, 0x5a, 0x2a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x6f,
|
0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74,
|
||||||
0x63, 0x6b, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f,
|
0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x52, 0x65,
|
||||||
0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70,
|
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x34, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b,
|
||||||
0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f,
|
||||||
|
0x6e, 0x74, 0x65, 0x78, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72,
|
||||||
|
0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x65, 0x0a, 0x04, 0x4c,
|
||||||
|
0x69, 0x73, 0x74, 0x12, 0x2d, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72,
|
||||||
|
0x2e, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x74,
|
||||||
|
0x65, 0x78, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65,
|
||||||
|
0x73, 0x74, 0x1a, 0x2e, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e,
|
||||||
|
0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x65,
|
||||||
|
0x78, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||||
|
0x73, 0x65, 0x42, 0x2c, 0x5a, 0x2a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d,
|
||||||
|
0x2f, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x72, 0x6f, 0x74,
|
||||||
|
0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31,
|
||||||
|
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -238,18 +344,22 @@ func file_protos_contexts_v1_contexts_proto_rawDescGZIP() []byte {
|
|||||||
return file_protos_contexts_v1_contexts_proto_rawDescData
|
return file_protos_contexts_v1_contexts_proto_rawDescData
|
||||||
}
|
}
|
||||||
|
|
||||||
var file_protos_contexts_v1_contexts_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
|
var file_protos_contexts_v1_contexts_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
|
||||||
var file_protos_contexts_v1_contexts_proto_goTypes = []interface{}{
|
var file_protos_contexts_v1_contexts_proto_goTypes = []interface{}{
|
||||||
(*Context)(nil), // 0: com.docker.api.protos.context.v1.Context
|
(*Context)(nil), // 0: com.docker.api.protos.context.v1.Context
|
||||||
(*ListRequest)(nil), // 1: com.docker.api.protos.context.v1.ListRequest
|
(*SetCurrentRequest)(nil), // 1: com.docker.api.protos.context.v1.SetCurrentRequest
|
||||||
(*ListResponse)(nil), // 2: com.docker.api.protos.context.v1.ListResponse
|
(*SetCurrentResponse)(nil), // 2: com.docker.api.protos.context.v1.SetCurrentResponse
|
||||||
|
(*ListRequest)(nil), // 3: com.docker.api.protos.context.v1.ListRequest
|
||||||
|
(*ListResponse)(nil), // 4: com.docker.api.protos.context.v1.ListResponse
|
||||||
}
|
}
|
||||||
var file_protos_contexts_v1_contexts_proto_depIdxs = []int32{
|
var file_protos_contexts_v1_contexts_proto_depIdxs = []int32{
|
||||||
0, // 0: com.docker.api.protos.context.v1.ListResponse.contexts:type_name -> com.docker.api.protos.context.v1.Context
|
0, // 0: com.docker.api.protos.context.v1.ListResponse.contexts:type_name -> com.docker.api.protos.context.v1.Context
|
||||||
1, // 1: com.docker.api.protos.context.v1.Contexts.List:input_type -> com.docker.api.protos.context.v1.ListRequest
|
1, // 1: com.docker.api.protos.context.v1.Contexts.SetCurrent:input_type -> com.docker.api.protos.context.v1.SetCurrentRequest
|
||||||
2, // 2: com.docker.api.protos.context.v1.Contexts.List:output_type -> com.docker.api.protos.context.v1.ListResponse
|
3, // 2: com.docker.api.protos.context.v1.Contexts.List:input_type -> com.docker.api.protos.context.v1.ListRequest
|
||||||
2, // [2:3] is the sub-list for method output_type
|
2, // 3: com.docker.api.protos.context.v1.Contexts.SetCurrent:output_type -> com.docker.api.protos.context.v1.SetCurrentResponse
|
||||||
1, // [1:2] is the sub-list for method input_type
|
4, // 4: com.docker.api.protos.context.v1.Contexts.List:output_type -> com.docker.api.protos.context.v1.ListResponse
|
||||||
|
3, // [3:5] is the sub-list for method output_type
|
||||||
|
1, // [1:3] is the sub-list for method input_type
|
||||||
1, // [1:1] is the sub-list for extension type_name
|
1, // [1:1] is the sub-list for extension type_name
|
||||||
1, // [1:1] is the sub-list for extension extendee
|
1, // [1:1] is the sub-list for extension extendee
|
||||||
0, // [0:1] is the sub-list for field type_name
|
0, // [0:1] is the sub-list for field type_name
|
||||||
@ -274,7 +384,7 @@ func file_protos_contexts_v1_contexts_proto_init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_protos_contexts_v1_contexts_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
file_protos_contexts_v1_contexts_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||||
switch v := v.(*ListRequest); i {
|
switch v := v.(*SetCurrentRequest); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
case 1:
|
case 1:
|
||||||
@ -286,6 +396,30 @@ func file_protos_contexts_v1_contexts_proto_init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_protos_contexts_v1_contexts_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
file_protos_contexts_v1_contexts_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||||
|
switch v := v.(*SetCurrentResponse); i {
|
||||||
|
case 0:
|
||||||
|
return &v.state
|
||||||
|
case 1:
|
||||||
|
return &v.sizeCache
|
||||||
|
case 2:
|
||||||
|
return &v.unknownFields
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_protos_contexts_v1_contexts_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
||||||
|
switch v := v.(*ListRequest); i {
|
||||||
|
case 0:
|
||||||
|
return &v.state
|
||||||
|
case 1:
|
||||||
|
return &v.sizeCache
|
||||||
|
case 2:
|
||||||
|
return &v.unknownFields
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_protos_contexts_v1_contexts_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
|
||||||
switch v := v.(*ListResponse); i {
|
switch v := v.(*ListResponse); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
@ -304,7 +438,7 @@ func file_protos_contexts_v1_contexts_proto_init() {
|
|||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
RawDescriptor: file_protos_contexts_v1_contexts_proto_rawDesc,
|
RawDescriptor: file_protos_contexts_v1_contexts_proto_rawDesc,
|
||||||
NumEnums: 0,
|
NumEnums: 0,
|
||||||
NumMessages: 3,
|
NumMessages: 5,
|
||||||
NumExtensions: 0,
|
NumExtensions: 0,
|
||||||
NumServices: 1,
|
NumServices: 1,
|
||||||
},
|
},
|
||||||
@ -330,6 +464,8 @@ const _ = grpc.SupportPackageIsVersion6
|
|||||||
//
|
//
|
||||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
|
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
|
||||||
type ContextsClient interface {
|
type ContextsClient interface {
|
||||||
|
// Sets the current request for all calls
|
||||||
|
SetCurrent(ctx context.Context, in *SetCurrentRequest, opts ...grpc.CallOption) (*SetCurrentResponse, error)
|
||||||
// Returns the list of existing contexts
|
// Returns the list of existing contexts
|
||||||
List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error)
|
List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error)
|
||||||
}
|
}
|
||||||
@ -342,6 +478,15 @@ func NewContextsClient(cc grpc.ClientConnInterface) ContextsClient {
|
|||||||
return &contextsClient{cc}
|
return &contextsClient{cc}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *contextsClient) SetCurrent(ctx context.Context, in *SetCurrentRequest, opts ...grpc.CallOption) (*SetCurrentResponse, error) {
|
||||||
|
out := new(SetCurrentResponse)
|
||||||
|
err := c.cc.Invoke(ctx, "/com.docker.api.protos.context.v1.Contexts/SetCurrent", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *contextsClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) {
|
func (c *contextsClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) {
|
||||||
out := new(ListResponse)
|
out := new(ListResponse)
|
||||||
err := c.cc.Invoke(ctx, "/com.docker.api.protos.context.v1.Contexts/List", in, out, opts...)
|
err := c.cc.Invoke(ctx, "/com.docker.api.protos.context.v1.Contexts/List", in, out, opts...)
|
||||||
@ -353,6 +498,8 @@ func (c *contextsClient) List(ctx context.Context, in *ListRequest, opts ...grpc
|
|||||||
|
|
||||||
// ContextsServer is the server API for Contexts service.
|
// ContextsServer is the server API for Contexts service.
|
||||||
type ContextsServer interface {
|
type ContextsServer interface {
|
||||||
|
// Sets the current request for all calls
|
||||||
|
SetCurrent(context.Context, *SetCurrentRequest) (*SetCurrentResponse, error)
|
||||||
// Returns the list of existing contexts
|
// Returns the list of existing contexts
|
||||||
List(context.Context, *ListRequest) (*ListResponse, error)
|
List(context.Context, *ListRequest) (*ListResponse, error)
|
||||||
}
|
}
|
||||||
@ -361,6 +508,9 @@ type ContextsServer interface {
|
|||||||
type UnimplementedContextsServer struct {
|
type UnimplementedContextsServer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*UnimplementedContextsServer) SetCurrent(context.Context, *SetCurrentRequest) (*SetCurrentResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method SetCurrent not implemented")
|
||||||
|
}
|
||||||
func (*UnimplementedContextsServer) List(context.Context, *ListRequest) (*ListResponse, error) {
|
func (*UnimplementedContextsServer) List(context.Context, *ListRequest) (*ListResponse, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method List not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method List not implemented")
|
||||||
}
|
}
|
||||||
@ -369,6 +519,24 @@ func RegisterContextsServer(s *grpc.Server, srv ContextsServer) {
|
|||||||
s.RegisterService(&_Contexts_serviceDesc, srv)
|
s.RegisterService(&_Contexts_serviceDesc, srv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _Contexts_SetCurrent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(SetCurrentRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(ContextsServer).SetCurrent(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/com.docker.api.protos.context.v1.Contexts/SetCurrent",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(ContextsServer).SetCurrent(ctx, req.(*SetCurrentRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
func _Contexts_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
func _Contexts_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
in := new(ListRequest)
|
in := new(ListRequest)
|
||||||
if err := dec(in); err != nil {
|
if err := dec(in); err != nil {
|
||||||
@ -391,6 +559,10 @@ var _Contexts_serviceDesc = grpc.ServiceDesc{
|
|||||||
ServiceName: "com.docker.api.protos.context.v1.Contexts",
|
ServiceName: "com.docker.api.protos.context.v1.Contexts",
|
||||||
HandlerType: (*ContextsServer)(nil),
|
HandlerType: (*ContextsServer)(nil),
|
||||||
Methods: []grpc.MethodDesc{
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "SetCurrent",
|
||||||
|
Handler: _Contexts_SetCurrent_Handler,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
MethodName: "List",
|
MethodName: "List",
|
||||||
Handler: _Contexts_List_Handler,
|
Handler: _Contexts_List_Handler,
|
||||||
|
@ -32,6 +32,8 @@ package com.docker.api.protos.context.v1;
|
|||||||
option go_package = "github.com/docker/api/protos/context/v1;v1";
|
option go_package = "github.com/docker/api/protos/context/v1;v1";
|
||||||
|
|
||||||
service Contexts {
|
service Contexts {
|
||||||
|
// Sets the current request for all calls
|
||||||
|
rpc SetCurrent(SetCurrentRequest) returns (SetCurrentResponse);
|
||||||
// Returns the list of existing contexts
|
// Returns the list of existing contexts
|
||||||
rpc List(ListRequest) returns (ListResponse);
|
rpc List(ListRequest) returns (ListResponse);
|
||||||
}
|
}
|
||||||
@ -39,10 +41,17 @@ service Contexts {
|
|||||||
message Context {
|
message Context {
|
||||||
string name = 1;
|
string name = 1;
|
||||||
string contextType = 2;
|
string contextType = 2;
|
||||||
|
bool current = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SetCurrentRequest {
|
||||||
|
string name = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SetCurrentResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListRequest {
|
message ListRequest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListResponse {
|
message ListResponse {
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/docker/api/context/store"
|
|
||||||
contextsv1 "github.com/docker/api/protos/contexts/v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
type cliServer struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewContexts returns a contexts server
|
|
||||||
func NewContexts() contextsv1.ContextsServer {
|
|
||||||
return &cliServer{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cs *cliServer) List(ctx context.Context, request *contextsv1.ListRequest) (*contextsv1.ListResponse, error) {
|
|
||||||
s := store.ContextStore(ctx)
|
|
||||||
contexts, err := s.List()
|
|
||||||
if err != nil {
|
|
||||||
return &contextsv1.ListResponse{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result := &contextsv1.ListResponse{}
|
|
||||||
|
|
||||||
for _, c := range contexts {
|
|
||||||
result.Contexts = append(result.Contexts, &contextsv1.Context{
|
|
||||||
Name: c.Name,
|
|
||||||
ContextType: c.Type,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/docker/api/containers"
|
"github.com/docker/api/containers"
|
||||||
containersv1 "github.com/docker/api/protos/containers/v1"
|
containersv1 "github.com/docker/api/protos/containers/v1"
|
||||||
|
"github.com/docker/api/server/proxy/streams"
|
||||||
)
|
)
|
||||||
|
|
||||||
func portsToGrpc(ports []containers.Port) []*containersv1.Port {
|
func portsToGrpc(ports []containers.Port) []*containersv1.Port {
|
||||||
@ -97,7 +98,10 @@ func (p *proxy) Exec(ctx context.Context, request *containersv1.ExecRequest) (*c
|
|||||||
return &containersv1.ExecResponse{}, errors.New("unknown stream id")
|
return &containersv1.ExecResponse{}, errors.New("unknown stream id")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := Client(ctx).ContainerService().Exec(ctx, request.GetId(), request.GetCommand(), &reader{stream}, &writer{stream})
|
io := &streams.IO{
|
||||||
|
Stream: stream,
|
||||||
|
}
|
||||||
|
err := Client(ctx).ContainerService().Exec(ctx, request.GetId(), request.GetCommand(), io, io)
|
||||||
|
|
||||||
return &containersv1.ExecResponse{}, err
|
return &containersv1.ExecResponse{}, err
|
||||||
}
|
}
|
||||||
@ -108,6 +112,8 @@ func (p *proxy) Logs(request *containersv1.LogsRequest, stream containersv1.Cont
|
|||||||
|
|
||||||
return c.ContainerService().Logs(ctx, request.GetContainerId(), containers.LogsRequest{
|
return c.ContainerService().Logs(ctx, request.GetContainerId(), containers.LogsRequest{
|
||||||
Follow: request.Follow,
|
Follow: request.Follow,
|
||||||
Writer: &logStream{stream},
|
Writer: &streams.Log{
|
||||||
|
Stream: stream,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
39
server/proxy/contexts.go
Normal file
39
server/proxy/contexts.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package proxy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/docker/api/config"
|
||||||
|
"github.com/docker/api/context/store"
|
||||||
|
contextsv1 "github.com/docker/api/protos/contexts/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
type contextsProxy struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cp *contextsProxy) SetCurrent(ctx context.Context, request *contextsv1.SetCurrentRequest) (*contextsv1.SetCurrentResponse, error) {
|
||||||
|
if err := config.WriteCurrentContext(config.Dir(ctx), request.GetName()); err != nil {
|
||||||
|
return &contextsv1.SetCurrentResponse{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &contextsv1.SetCurrentResponse{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cp *contextsProxy) List(ctx context.Context, request *contextsv1.ListRequest) (*contextsv1.ListResponse, error) {
|
||||||
|
s := store.ContextStore(ctx)
|
||||||
|
contexts, err := s.List()
|
||||||
|
if err != nil {
|
||||||
|
return &contextsv1.ListResponse{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := &contextsv1.ListResponse{}
|
||||||
|
|
||||||
|
for _, c := range contexts {
|
||||||
|
result.Contexts = append(result.Contexts, &contextsv1.Context{
|
||||||
|
Name: c.Name,
|
||||||
|
ContextType: c.Type,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
@ -1,25 +0,0 @@
|
|||||||
package proxy
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
|
|
||||||
containersv1 "github.com/docker/api/protos/containers/v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
type logStream struct {
|
|
||||||
stream grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func newStreamWriter(stream grpc.ServerStream) io.Writer {
|
|
||||||
return &logStream{
|
|
||||||
stream: stream,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *logStream) Write(p []byte) (n int, err error) {
|
|
||||||
return len(p), w.stream.SendMsg(&containersv1.LogsResponse{
|
|
||||||
Value: p,
|
|
||||||
})
|
|
||||||
}
|
|
@ -6,7 +6,9 @@ import (
|
|||||||
|
|
||||||
"github.com/docker/api/client"
|
"github.com/docker/api/client"
|
||||||
containersv1 "github.com/docker/api/protos/containers/v1"
|
containersv1 "github.com/docker/api/protos/containers/v1"
|
||||||
|
contextsv1 "github.com/docker/api/protos/contexts/v1"
|
||||||
streamsv1 "github.com/docker/api/protos/streams/v1"
|
streamsv1 "github.com/docker/api/protos/streams/v1"
|
||||||
|
"github.com/docker/api/server/proxy/streams"
|
||||||
)
|
)
|
||||||
|
|
||||||
type clientKey struct{}
|
type clientKey struct{}
|
||||||
@ -27,16 +29,25 @@ func Client(ctx context.Context) *client.Client {
|
|||||||
type Proxy interface {
|
type Proxy interface {
|
||||||
containersv1.ContainersServer
|
containersv1.ContainersServer
|
||||||
streamsv1.StreamingServer
|
streamsv1.StreamingServer
|
||||||
|
ContextsProxy() contextsv1.ContextsServer
|
||||||
}
|
}
|
||||||
|
|
||||||
type proxy struct {
|
type proxy struct {
|
||||||
|
currentContext string
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
streams map[string]*Stream
|
streams map[string]*streams.Stream
|
||||||
|
contextsProxy *contextsProxy
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new proxy server
|
// New creates a new proxy server
|
||||||
func New() Proxy {
|
func New(currentContext string) Proxy {
|
||||||
return &proxy{
|
return &proxy{
|
||||||
streams: map[string]*Stream{},
|
currentContext: currentContext,
|
||||||
|
streams: map[string]*streams.Stream{},
|
||||||
|
contextsProxy: &contextsProxy{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *proxy) ContextsProxy() contextsv1.ContextsServer {
|
||||||
|
return p.contextsProxy
|
||||||
|
}
|
||||||
|
@ -1,41 +1,14 @@
|
|||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/golang/protobuf/ptypes"
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
|
|
||||||
streamsv1 "github.com/docker/api/protos/streams/v1"
|
streamsv1 "github.com/docker/api/protos/streams/v1"
|
||||||
|
"github.com/docker/api/server/proxy/streams"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Stream is a bidirectional stream for container IO
|
|
||||||
type Stream struct {
|
|
||||||
streamsv1.Streaming_NewStreamServer
|
|
||||||
|
|
||||||
errm sync.Mutex
|
|
||||||
errChan chan<- error
|
|
||||||
}
|
|
||||||
|
|
||||||
// CloseWithError sends the result of an action to the errChan or nil
|
|
||||||
// if no erros
|
|
||||||
func (s *Stream) CloseWithError(err error) error {
|
|
||||||
s.errm.Lock()
|
|
||||||
defer s.errm.Unlock()
|
|
||||||
|
|
||||||
if s.errChan != nil {
|
|
||||||
if err != nil {
|
|
||||||
s.errChan <- err
|
|
||||||
}
|
|
||||||
close(s.errChan)
|
|
||||||
s.errChan = nil
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *proxy) NewStream(stream streamsv1.Streaming_NewStreamServer) error {
|
func (p *proxy) NewStream(stream streamsv1.Streaming_NewStreamServer) error {
|
||||||
var (
|
var (
|
||||||
ctx = stream.Context()
|
ctx = stream.Context()
|
||||||
@ -53,9 +26,9 @@ func (p *proxy) NewStream(stream streamsv1.Streaming_NewStreamServer) error {
|
|||||||
errc := make(chan error)
|
errc := make(chan error)
|
||||||
|
|
||||||
p.mu.Lock()
|
p.mu.Lock()
|
||||||
p.streams[id] = &Stream{
|
p.streams[id] = &streams.Stream{
|
||||||
Streaming_NewStreamServer: stream,
|
Streaming_NewStreamServer: stream,
|
||||||
errChan: errc,
|
ErrChan: errc,
|
||||||
}
|
}
|
||||||
p.mu.Unlock()
|
p.mu.Unlock()
|
||||||
|
|
||||||
@ -73,46 +46,3 @@ func (p *proxy) NewStream(stream streamsv1.Streaming_NewStreamServer) error {
|
|||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// io.Reader that forwards everything to the stream
|
|
||||||
type reader struct {
|
|
||||||
stream *Stream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r reader) Read(p []byte) (int, error) {
|
|
||||||
a, err := r.stream.Recv()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var m streamsv1.BytesMessage
|
|
||||||
err = ptypes.UnmarshalAny(a, &m)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return copy(p, m.Value), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// io.Writer that writes
|
|
||||||
type writer struct {
|
|
||||||
stream grpc.ServerStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *writer) Write(p []byte) (n int, err error) {
|
|
||||||
if len(p) == 0 {
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
message := streamsv1.BytesMessage{
|
|
||||||
Type: streamsv1.IOStream_STDOUT,
|
|
||||||
Value: p,
|
|
||||||
}
|
|
||||||
|
|
||||||
m, err := ptypes.MarshalAny(&message)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return len(message.Value), w.stream.SendMsg(m)
|
|
||||||
}
|
|
||||||
|
45
server/proxy/streams/io.go
Normal file
45
server/proxy/streams/io.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package streams
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/golang/protobuf/ptypes"
|
||||||
|
|
||||||
|
streamsv1 "github.com/docker/api/protos/streams/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IO implements an io.ReadWriter that forwards everything to the stream
|
||||||
|
type IO struct {
|
||||||
|
Stream *Stream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (io *IO) Read(p []byte) (int, error) {
|
||||||
|
a, err := io.Stream.Recv()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var m streamsv1.BytesMessage
|
||||||
|
err = ptypes.UnmarshalAny(a, &m)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy(p, m.Value), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (io *IO) Write(p []byte) (n int, err error) {
|
||||||
|
if len(p) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
message := streamsv1.BytesMessage{
|
||||||
|
Type: streamsv1.IOStream_STDOUT,
|
||||||
|
Value: p,
|
||||||
|
}
|
||||||
|
|
||||||
|
m, err := ptypes.MarshalAny(&message)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return len(message.Value), io.Stream.SendMsg(m)
|
||||||
|
}
|
26
server/proxy/streams/logs.go
Normal file
26
server/proxy/streams/logs.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package streams
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
|
containersv1 "github.com/docker/api/protos/containers/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Log implements an io.Writer that proxies logs over a gRPC stream
|
||||||
|
type Log struct {
|
||||||
|
Stream grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func newStreamWriter(stream grpc.ServerStream) io.Writer {
|
||||||
|
return &Log{
|
||||||
|
Stream: stream,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Log) Write(p []byte) (n int, err error) {
|
||||||
|
return len(p), w.Stream.SendMsg(&containersv1.LogsResponse{
|
||||||
|
Value: p,
|
||||||
|
})
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package proxy
|
package streams
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
31
server/proxy/streams/stream.go
Normal file
31
server/proxy/streams/stream.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package streams
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
streamsv1 "github.com/docker/api/protos/streams/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Stream is a bidirectional stream for container IO
|
||||||
|
type Stream struct {
|
||||||
|
streamsv1.Streaming_NewStreamServer
|
||||||
|
|
||||||
|
errm sync.Mutex
|
||||||
|
ErrChan chan<- error
|
||||||
|
}
|
||||||
|
|
||||||
|
// CloseWithError sends the result of an action to the errChan or nil
|
||||||
|
// if no erros
|
||||||
|
func (s *Stream) CloseWithError(err error) error {
|
||||||
|
s.errm.Lock()
|
||||||
|
defer s.errm.Unlock()
|
||||||
|
|
||||||
|
if s.ErrChan != nil {
|
||||||
|
if err != nil {
|
||||||
|
s.ErrChan <- err
|
||||||
|
}
|
||||||
|
close(s.ErrChan)
|
||||||
|
s.ErrChan = nil
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package proxy
|
package streams
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -54,7 +54,7 @@ func (bs *byteStream) RecvMsg(m interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getReader(t *testing.T, in []byte, errResult error) reader {
|
func getReader(t *testing.T, in []byte, errResult error) IO {
|
||||||
message := streamsv1.BytesMessage{
|
message := streamsv1.BytesMessage{
|
||||||
Type: streamsv1.IOStream_STDOUT,
|
Type: streamsv1.IOStream_STDOUT,
|
||||||
Value: in,
|
Value: in,
|
||||||
@ -62,8 +62,8 @@ func getReader(t *testing.T, in []byte, errResult error) reader {
|
|||||||
m, err := ptypes.MarshalAny(&message)
|
m, err := ptypes.MarshalAny(&message)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
return reader{
|
return IO{
|
||||||
stream: &Stream{
|
Stream: &Stream{
|
||||||
Streaming_NewStreamServer: &byteStream{
|
Streaming_NewStreamServer: &byteStream{
|
||||||
recvResult: m,
|
recvResult: m,
|
||||||
recvErr: errResult,
|
recvErr: errResult,
|
||||||
@ -109,7 +109,11 @@ func TestStreamWriter(t *testing.T) {
|
|||||||
expected := getAny(t, in)
|
expected := getAny(t, in)
|
||||||
|
|
||||||
bs := byteStream{}
|
bs := byteStream{}
|
||||||
w := writer{stream: &bs}
|
w := IO{
|
||||||
|
Stream: &Stream{
|
||||||
|
Streaming_NewStreamServer: &bs,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
n, err := w.Write(in)
|
n, err := w.Write(in)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
@ -40,7 +40,6 @@ import (
|
|||||||
|
|
||||||
"github.com/docker/api/client"
|
"github.com/docker/api/client"
|
||||||
apicontext "github.com/docker/api/context"
|
apicontext "github.com/docker/api/context"
|
||||||
"github.com/docker/api/context/store"
|
|
||||||
"github.com/docker/api/server/proxy"
|
"github.com/docker/api/server/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -127,8 +126,6 @@ func getContext(ctx context.Context) string {
|
|||||||
// configureContext populates the request context with objects the client
|
// configureContext populates the request context with objects the client
|
||||||
// needs: the context store and the api client
|
// needs: the context store and the api client
|
||||||
func configureContext(ctx context.Context, currentContext string) (context.Context, error) {
|
func configureContext(ctx context.Context, currentContext string) (context.Context, error) {
|
||||||
s := store.ContextStore(ctx)
|
|
||||||
ctx = store.WithContextStore(ctx, s)
|
|
||||||
if currentContext != "" {
|
if currentContext != "" {
|
||||||
ctx = apicontext.WithCurrentContext(ctx, currentContext)
|
ctx = apicontext.WithCurrentContext(ctx, currentContext)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user