Browse code

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

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Vincent Demeester authored on 2017/03/27 16:58:09
Showing 3 changed files
... ...
@@ -4,13 +4,12 @@ import (
4 4
 	"fmt"
5 5
 	"strings"
6 6
 
7
-	"golang.org/x/net/context"
8
-
9 7
 	"github.com/docker/docker/cli"
10 8
 	"github.com/docker/docker/cli/command"
11 9
 	"github.com/docker/docker/cli/command/inspect"
12 10
 	apiclient "github.com/docker/docker/client"
13 11
 	"github.com/spf13/cobra"
12
+	"golang.org/x/net/context"
14 13
 )
15 14
 
16 15
 type inspectOptions struct {
... ...
@@ -45,7 +44,7 @@ func NewInspectCommand(dockerCli *command.DockerCli) *cobra.Command {
45 45
 func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
46 46
 	var elementSearcher inspect.GetRefFunc
47 47
 	switch opts.inspectType {
48
-	case "", "container", "image", "node", "network", "service", "volume", "task", "plugin":
48
+	case "", "container", "image", "node", "network", "service", "volume", "task", "plugin", "secret":
49 49
 		elementSearcher = inspectAll(context.Background(), dockerCli, opts.size, opts.inspectType)
50 50
 	default:
51 51
 		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
101 101
 	}
102 102
 }
103 103
 
104
+func inspectSecret(ctx context.Context, dockerCli *command.DockerCli) inspect.GetRefFunc {
105
+	return func(ref string) (interface{}, []byte, error) {
106
+		return dockerCli.Client().SecretInspectWithRaw(ctx, ref)
107
+	}
108
+}
109
+
104 110
 func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool, typeConstraint string) inspect.GetRefFunc {
105 111
 	var inspectAutodetect = []struct {
106 112
 		objectType      string
... ...
@@ -144,6 +149,11 @@ func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool,
144 144
 			objectType:      "plugin",
145 145
 			objectInspector: inspectPlugin(ctx, dockerCli),
146 146
 		},
147
+		{
148
+			objectType:      "secret",
149
+			isSwarmObject:   true,
150
+			objectInspector: inspectSecret(ctx, dockerCli),
151
+		},
147 152
 	}
148 153
 
149 154
 	// isSwarmManager does an Info API call to verify that the daemon is
... ...
@@ -2511,7 +2511,7 @@ _docker_inspect() {
2511 2511
 			;;
2512 2512
 		--type)
2513 2513
 			if [ -z "$preselected_type" ] ; then
2514
-				COMPREPLY=( $( compgen -W "container image network node plugin service volume" -- "$cur" ) )
2514
+				COMPREPLY=( $( compgen -W "container image network node plugin secret service volume" -- "$cur" ) )
2515 2515
 				return
2516 2516
 			fi
2517 2517
 			;;
... ...
@@ -2534,6 +2534,7 @@ _docker_inspect() {
2534 2534
 						$(__docker_networks)
2535 2535
 						$(__docker_nodes)
2536 2536
 						$(__docker_plugins_installed)
2537
+						$(__docker_secrets)
2537 2538
 						$(__docker_services)
2538 2539
 						$(__docker_volumes)
2539 2540
 					" -- "$cur" ) )
... ...
@@ -2553,6 +2554,9 @@ _docker_inspect() {
2553 2553
 				plugin)
2554 2554
 					__docker_complete_plugins_installed
2555 2555
 					;;
2556
+				secret)
2557
+					__docker_complete_secrets
2558
+					;;
2556 2559
 				service)
2557 2560
 					__docker_complete_services
2558 2561
 					;;
... ...
@@ -2713,6 +2713,8 @@ __docker_subcommand() {
2713 2713
                         __docker_complete_nodes && ret=0
2714 2714
                     elif [[ ${words[(r)--type=plugin]} == --type=plugin ]]; then
2715 2715
                         __docker_complete_plugins && ret=0
2716
+                    elif [[ ${words[(r)--type=service]} == --type=secrets ]]; then
2717
+                        __docker_complete_secrets && ret=0
2716 2718
                     elif [[ ${words[(r)--type=service]} == --type=service ]]; then
2717 2719
                         __docker_complete_services && ret=0
2718 2720
                     elif [[ ${words[(r)--type=volume]} == --type=volume ]]; then
... ...
@@ -2723,6 +2725,7 @@ __docker_subcommand() {
2723 2723
                         __docker_complete_networks
2724 2724
                         __docker_complete_nodes
2725 2725
                         __docker_complete_plugins
2726
+                        __docker_complete_secrets
2726 2727
                         __docker_complete_services
2727 2728
                         __docker_complete_volumes && ret=0
2728 2729
                     fi