command

package
v23.0.0-rc.2+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2023 License: Apache-2.0 Imports: 46 Imported by: 4,906

Documentation

Index

Constants

View Source
const (
	// DefaultContextName is the name reserved for the default context (config & env based)
	DefaultContextName = "default"
)

Variables

View Source
var (
	// NewInStream returns a new InStream object from a ReadCloser
	// Deprecated: Use github.com/docker/cli/cli/streams.NewIn instead
	NewInStream = streams.NewIn
	// NewOutStream returns a new OutStream object from a Writer
	// Deprecated: Use github.com/docker/cli/cli/streams.NewOut instead
	NewOutStream = streams.NewOut
)

Functions

func AddPlatformFlag

func AddPlatformFlag(flags *pflag.FlagSet, target *string)

AddPlatformFlag adds `platform` to a set of flags for API version 1.32 and later.

func AddTrustSigningFlags

func AddTrustSigningFlags(fs *pflag.FlagSet, v *bool, trusted bool)

AddTrustSigningFlags adds "signing" flags to the provided flagset

func AddTrustVerificationFlags

func AddTrustVerificationFlags(fs *pflag.FlagSet, v *bool, trusted bool)

AddTrustVerificationFlags adds content trust flags to the provided flagset

func ConfigureAuth

func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *types.AuthConfig, isDefaultRegistry bool) error

ConfigureAuth handles prompting of user's username and password if needed

func CopyToFile

func CopyToFile(outfile string, r io.Reader) error

CopyToFile writes the content of the reader to the specified file

func DefaultContextStoreConfig

func DefaultContextStoreConfig() store.Config

DefaultContextStoreConfig returns a new store.Config with the default set of endpoints configured.

func ElectAuthServer

func ElectAuthServer(_ context.Context, _ Cli) string

ElectAuthServer returns the default registry to use Deprecated: use registry.IndexServer instead

func EncodeAuthToBase64

func EncodeAuthToBase64(authConfig types.AuthConfig) (string, error)

EncodeAuthToBase64 serializes the auth configuration as JSON base64 payload

func GetDefaultAuthConfig

func GetDefaultAuthConfig(cli Cli, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (types.AuthConfig, error)

GetDefaultAuthConfig gets the default auth config given a serverAddress If credentials for given serverAddress exists in the credential store, the configuration will be populated with values in it

func NewAPIClientFromFlags

func NewAPIClientFromFlags(opts *cliflags.ClientOptions, configFile *configfile.ConfigFile) (client.APIClient, error)

NewAPIClientFromFlags creates a new APIClient from command line flags

func PrettyPrint

func PrettyPrint(i interface{}) string

PrettyPrint outputs arbitrary data for human formatted output by uppercasing the first letter.

func PromptForConfirmation

func PromptForConfirmation(ins io.Reader, outs io.Writer, message string) bool

PromptForConfirmation requests and checks confirmation from user. This will display the provided message followed by ' y/N '. If the user input 'y' or 'Y' it returns true other false. If no message is provided "Are you sure you want to proceed? y/N " will be used instead.

func PruneFilters

func PruneFilters(dockerCli Cli, pruneFilters filters.Args) filters.Args

PruneFilters returns consolidated prune filters obtained from config.json and cli

func RegisterDefaultStoreEndpoints

func RegisterDefaultStoreEndpoints(ep ...store.NamedTypeGetter)

RegisterDefaultStoreEndpoints registers a new named endpoint metadata type with the default context store config, so that endpoint will be supported by stores using the config returned by DefaultContextStoreConfig.

func RegistryAuthenticationPrivilegedFunc

func RegistryAuthenticationPrivilegedFunc(cli Cli, index *registrytypes.IndexInfo, cmdName string) types.RequestPrivilegeFunc

RegistryAuthenticationPrivilegedFunc returns a RequestPrivilegeFunc from the specified registry index info for the given command.

func ResolveAuthConfig

func ResolveAuthConfig(_ context.Context, cli Cli, index *registrytypes.IndexInfo) types.AuthConfig

ResolveAuthConfig is like registry.ResolveAuthConfig, but if using the default index, it uses the default index name for the daemon's platform, not the client's platform.

func RetrieveAuthTokenFromImage

func RetrieveAuthTokenFromImage(ctx context.Context, cli Cli, image string) (string, error)

RetrieveAuthTokenFromImage retrieves an encoded auth token given a complete image

func ShowHelp

func ShowHelp(err io.Writer) func(*cobra.Command, []string) error

ShowHelp shows the command help.

func StringSliceReplaceAt

func StringSliceReplaceAt(s, old, new []string, requireIndex int) ([]string, bool)

StringSliceReplaceAt replaces the sub-slice old, with the sub-slice new, in the string slice s, returning a new slice and a boolean indicating if the replacement happened. requireIdx is the index at which old needs to be found at (or -1 to disregard that).

func UserAgent

func UserAgent() string

UserAgent returns the user agent string used for making API requests

func ValidateOutputPath

func ValidateOutputPath(path string) error

ValidateOutputPath validates the output paths of the `export` and `save` commands.

func ValidateOutputPathFileMode

func ValidateOutputPathFileMode(fileMode os.FileMode) error

ValidateOutputPathFileMode validates the output paths of the `cp` command and serves as a helper to `ValidateOutputPath`

Types

type Cli

type Cli interface {
	Client() client.APIClient
	Out() *streams.Out
	Err() io.Writer
	In() *streams.In
	SetIn(in *streams.In)
	Apply(ops ...DockerCliOption) error
	ConfigFile() *configfile.ConfigFile
	ServerInfo() ServerInfo
	NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (notaryclient.Repository, error)
	DefaultVersion() string
	CurrentVersion() string
	ManifestStore() manifeststore.Store
	RegistryClient(bool) registryclient.RegistryClient
	ContentTrustEnabled() bool
	BuildKitEnabled() (bool, error)
	ContextStore() store.Store
	CurrentContext() string
	DockerEndpoint() docker.Endpoint
}

Cli represents the docker command line client.

type ContextStoreWithDefault

type ContextStoreWithDefault struct {
	store.Store
	Resolver DefaultContextResolver
}

ContextStoreWithDefault implements the store.Store interface with a support for the default context

func (*ContextStoreWithDefault) CreateOrUpdate

func (s *ContextStoreWithDefault) CreateOrUpdate(meta store.Metadata) error

CreateOrUpdate is not allowed for the default context and fails

func (*ContextStoreWithDefault) GetMetadata

func (s *ContextStoreWithDefault) GetMetadata(name string) (store.Metadata, error)

GetMetadata implements store.Store's GetMetadata

func (*ContextStoreWithDefault) GetStorageInfo

func (s *ContextStoreWithDefault) GetStorageInfo(contextName string) store.StorageInfo

GetStorageInfo implements store.Store's GetStorageInfo

func (*ContextStoreWithDefault) GetTLSData

func (s *ContextStoreWithDefault) GetTLSData(contextName, endpointName, fileName string) ([]byte, error)

GetTLSData implements store.Store's GetTLSData

func (*ContextStoreWithDefault) List

List implements store.Store's List

func (*ContextStoreWithDefault) ListTLSFiles

func (s *ContextStoreWithDefault) ListTLSFiles(name string) (map[string]store.EndpointFiles, error)

ListTLSFiles implements store.Store's ListTLSFiles

func (*ContextStoreWithDefault) Remove

func (s *ContextStoreWithDefault) Remove(name string) error

Remove is not allowed for the default context and fails

func (*ContextStoreWithDefault) ResetEndpointTLSMaterial

func (s *ContextStoreWithDefault) ResetEndpointTLSMaterial(contextName string, endpointName string, data *store.EndpointTLSData) error

ResetEndpointTLSMaterial is not implemented for default context and fails

func (*ContextStoreWithDefault) ResetTLSMaterial

func (s *ContextStoreWithDefault) ResetTLSMaterial(name string, data *store.ContextTLSData) error

ResetTLSMaterial is not implemented for default context and fails

type DefaultContext

type DefaultContext struct {
	Meta store.Metadata
	TLS  store.ContextTLSData
}

DefaultContext contains the default context data for all endpoints

func ResolveDefaultContext

func ResolveDefaultContext(opts *cliflags.ClientOptions, config store.Config) (*DefaultContext, error)

ResolveDefaultContext creates a Metadata for the current CLI invocation parameters

type DefaultContextResolver

type DefaultContextResolver func() (*DefaultContext, error)

DefaultContextResolver is a function which resolves the default context base on the configuration and the env variables

type DockerCli

type DockerCli struct {
	// contains filtered or unexported fields
}

DockerCli is an instance the docker command line client. Instances of the client can be returned from NewDockerCli.

func NewDockerCli

func NewDockerCli(ops ...DockerCliOption) (*DockerCli, error)

NewDockerCli returns a DockerCli instance with all operators applied on it. It applies by default the standard streams, and the content trust from environment.

func (*DockerCli) Apply

func (cli *DockerCli) Apply(ops ...DockerCliOption) error

Apply all the operation on the cli

func (*DockerCli) BuildKitEnabled

func (cli *DockerCli) BuildKitEnabled() (bool