Merge pull request #32124 from vdemeester/system-inspect-secret
Add support for `--type=secret` in `docker inspect` Upstream-commit: ee61f28cc37d78cd40943c37c24716e5a0a635d9 Component: engine
This commit is contained in:
@ -4,14 +4,13 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/docker/docker/cli/command/inspect"
|
||||
apiclient "github.com/docker/docker/client"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type inspectOptions struct {
|
||||
@ -46,7 +45,7 @@ func NewInspectCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||
func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
|
||||
var elementSearcher inspect.GetRefFunc
|
||||
switch opts.inspectType {
|
||||
case "", "container", "image", "node", "network", "service", "volume", "task", "plugin":
|
||||
case "", "container", "image", "node", "network", "service", "volume", "task", "plugin", "secret":
|
||||
elementSearcher = inspectAll(context.Background(), dockerCli, opts.size, opts.inspectType)
|
||||
default:
|
||||
return errors.Errorf("%q is not a valid value for --type", opts.inspectType)
|
||||
@ -102,6 +101,12 @@ func inspectPlugin(ctx context.Context, dockerCli *command.DockerCli) inspect.Ge
|
||||
}
|
||||
}
|
||||
|
||||
func inspectSecret(ctx context.Context, dockerCli *command.DockerCli) inspect.GetRefFunc {
|
||||
return func(ref string) (interface{}, []byte, error) {
|
||||
return dockerCli.Client().SecretInspectWithRaw(ctx, ref)
|
||||
}
|
||||
}
|
||||
|
||||
func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool, typeConstraint string) inspect.GetRefFunc {
|
||||
var inspectAutodetect = []struct {
|
||||
objectType string
|
||||
@ -145,6 +150,11 @@ func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool,
|
||||
objectType: "plugin",
|
||||
objectInspector: inspectPlugin(ctx, dockerCli),
|
||||
},
|
||||
{
|
||||
objectType: "secret",
|
||||
isSwarmObject: true,
|
||||
objectInspector: inspectSecret(ctx, dockerCli),
|
||||
},
|
||||
}
|
||||
|
||||
// isSwarmManager does an Info API call to verify that the daemon is
|
||||
|
||||
@ -2511,7 +2511,7 @@ _docker_inspect() {
|
||||
;;
|
||||
--type)
|
||||
if [ -z "$preselected_type" ] ; then
|
||||
COMPREPLY=( $( compgen -W "container image network node plugin service volume" -- "$cur" ) )
|
||||
COMPREPLY=( $( compgen -W "container image network node plugin secret service volume" -- "$cur" ) )
|
||||
return
|
||||
fi
|
||||
;;
|
||||
@ -2534,6 +2534,7 @@ _docker_inspect() {
|
||||
$(__docker_networks)
|
||||
$(__docker_nodes)
|
||||
$(__docker_plugins_installed)
|
||||
$(__docker_secrets)
|
||||
$(__docker_services)
|
||||
$(__docker_volumes)
|
||||
" -- "$cur" ) )
|
||||
@ -2553,6 +2554,9 @@ _docker_inspect() {
|
||||
plugin)
|
||||
__docker_complete_plugins_installed
|
||||
;;
|
||||
secret)
|
||||
__docker_complete_secrets
|
||||
;;
|
||||
service)
|
||||
__docker_complete_services
|
||||
;;
|
||||
|
||||
@ -2729,6 +2729,8 @@ __docker_subcommand() {
|
||||
__docker_complete_nodes && ret=0
|
||||
elif [[ ${words[(r)--type=plugin]} == --type=plugin ]]; then
|
||||
__docker_complete_plugins && ret=0
|
||||
elif [[ ${words[(r)--type=service]} == --type=secrets ]]; then
|
||||
__docker_complete_secrets && ret=0
|
||||
elif [[ ${words[(r)--type=service]} == --type=service ]]; then
|
||||
__docker_complete_services && ret=0
|
||||
elif [[ ${words[(r)--type=volume]} == --type=volume ]]; then
|
||||
@ -2739,6 +2741,7 @@ __docker_subcommand() {
|
||||
__docker_complete_networks
|
||||
__docker_complete_nodes
|
||||
__docker_complete_plugins
|
||||
__docker_complete_secrets
|
||||
__docker_complete_services
|
||||
__docker_complete_volumes && ret=0
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user