Add support for `--type=secret` in `docker inspect`

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2017-03-27 09:58:09 +02:00
parent ca1aca0afe
commit ba785f32f8
1 changed files with 13 additions and 3 deletions

View File

@ -4,13 +4,12 @@ import (
"fmt" "fmt"
"strings" "strings"
"golang.org/x/net/context"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/docker/docker/cli/command/inspect" "github.com/docker/docker/cli/command/inspect"
apiclient "github.com/docker/docker/client" apiclient "github.com/docker/docker/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type inspectOptions struct { type inspectOptions struct {
@ -45,7 +44,7 @@ func NewInspectCommand(dockerCli *command.DockerCli) *cobra.Command {
func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error { func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
var elementSearcher inspect.GetRefFunc var elementSearcher inspect.GetRefFunc
switch opts.inspectType { 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) elementSearcher = inspectAll(context.Background(), dockerCli, opts.size, opts.inspectType)
default: default:
return fmt.Errorf("%q is not a valid value for --type", opts.inspectType) return fmt.Errorf("%q is not a valid value for --type", opts.inspectType)
@ -101,6 +100,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 { func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool, typeConstraint string) inspect.GetRefFunc {
var inspectAutodetect = []struct { var inspectAutodetect = []struct {
objectType string objectType string
@ -144,6 +149,11 @@ func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool,
objectType: "plugin", objectType: "plugin",
objectInspector: inspectPlugin(ctx, dockerCli), objectInspector: inspectPlugin(ctx, dockerCli),
}, },
{
objectType: "secret",
isSwarmObject: true,
objectInspector: inspectSecret(ctx, dockerCli),
},
} }
// isSwarmManager does an Info API call to verify that the daemon is // isSwarmManager does an Info API call to verify that the daemon is