| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 | /*   Copyright 2020 Docker, Inc.   Licensed under the Apache License, Version 2.0 (the "License");   you may not use this file except in compliance with the License.   You may obtain a copy of the License at       http://www.apache.org/licenses/LICENSE-2.0   Unless required by applicable law or agreed to in writing, software   distributed under the License is distributed on an "AS IS" BASIS,   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the License for the specific language governing permissions and   limitations under the License.*/package contextimport (	"context"	"github.com/spf13/cobra"	"github.com/docker/api/cli/mobycli"	"github.com/docker/api/context/store")type descriptionCreateOpts struct {	description string}func createCommand() *cobra.Command {	const longHelp = `Create a new contextCreate docker engine context: $ docker context create CONTEXT [flags]Create Azure Container Instances context:$ docker context create aci CONTEXT [flags](see docker context create aci --help)Docker endpoint config:NAME                DESCRIPTIONfrom                Copy named context's Docker endpoint configurationhost                Docker endpoint on which to connectca                  Trust certs signed only by this CAcert                Path to TLS certificate filekey                 Path to TLS key fileskip-tls-verify     Skip TLS certificate validationKubernetes endpoint config:NAME                 DESCRIPTIONfrom                 Copy named context's Kubernetes endpoint configurationconfig-file          Path to a Kubernetes config filecontext-override     Overrides the context set in the kubernetes config filenamespace-override   Overrides the namespace set in the kubernetes config fileExample:$ docker context create my-context --description "some description" --docker "host=tcp://myserver:2376,ca=~/ca-file,cert=~/cert-file,key=~/key-file"`	cmd := &cobra.Command{		Use:   "create CONTEXT",		Short: "Create new context",		RunE: func(cmd *cobra.Command, args []string) error {			return mobycli.ExecCmd(cmd)		},		Long: longHelp,	}	cmd.AddCommand(		createAciCommand(),		createAwsCommand(),		createLocalCommand(),		createExampleCommand(),	)	flags := cmd.Flags()	flags.String("description", "", "Description of the context")	flags.String(		"default-stack-orchestrator", "",		"Default orchestrator for stack operations to use with this context (swarm|kubernetes|all)")	flags.StringToString("docker", nil, "set the docker endpoint")	flags.StringToString("kubernetes", nil, "set the kubernetes endpoint")	flags.String("from", "", "create context from a named context")	return cmd}func createLocalCommand() *cobra.Command {	var opts descriptionCreateOpts	cmd := &cobra.Command{		Use:    "local CONTEXT",		Short:  "Create a context for accessing local engine",		Args:   cobra.ExactArgs(1),		Hidden: true,		RunE: func(cmd *cobra.Command, args []string) error {			return createDockerContext(cmd.Context(), args[0], store.LocalContextType, opts.description, store.LocalContext{})		},	}	addDescriptionFlag(cmd, &opts.description)	return cmd}func createExampleCommand() *cobra.Command {	var opts descriptionCreateOpts	cmd := &cobra.Command{		Use:    "example CONTEXT",		Short:  "Create a test context returning fixed output",		Args:   cobra.ExactArgs(1),		Hidden: true,		RunE: func(cmd *cobra.Command, args []string) error {			return createDockerContext(cmd.Context(), args[0], store.ExampleContextType, opts.description, store.ExampleContext{})		},	}	addDescriptionFlag(cmd, &opts.description)	return cmd}func createDockerContext(ctx context.Context, name string, contextType string, description string, data interface{}) error {	s := store.ContextStore(ctx)	result := s.Create(		name,		contextType,		description,		data,	)	return result}func contextExists(ctx context.Context, name string) bool {	s := store.ContextStore(ctx)	return s.ContextExists(name)}func addDescriptionFlag(cmd *cobra.Command, descriptionOpt *string) {	cmd.Flags().StringVar(descriptionOpt, "description", "", "Description of the context")}
 |