Add support for `--type=secret` in `docker inspect`
| ... | ... |
@@ -4,14 +4,13 @@ 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/pkg/errors" |
| 14 | 12 |
"github.com/spf13/cobra" |
| 13 |
+ "golang.org/x/net/context" |
|
| 15 | 14 |
) |
| 16 | 15 |
|
| 17 | 16 |
type inspectOptions struct {
|
| ... | ... |
@@ -46,7 +45,7 @@ func NewInspectCommand(dockerCli *command.DockerCli) *cobra.Command {
|
| 46 | 46 |
func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
|
| 47 | 47 |
var elementSearcher inspect.GetRefFunc |
| 48 | 48 |
switch opts.inspectType {
|
| 49 |
- case "", "container", "image", "node", "network", "service", "volume", "task", "plugin": |
|
| 49 |
+ case "", "container", "image", "node", "network", "service", "volume", "task", "plugin", "secret": |
|
| 50 | 50 |
elementSearcher = inspectAll(context.Background(), dockerCli, opts.size, opts.inspectType) |
| 51 | 51 |
default: |
| 52 | 52 |
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 |
| 102 | 102 |
} |
| 103 | 103 |
} |
| 104 | 104 |
|
| 105 |
+func inspectSecret(ctx context.Context, dockerCli *command.DockerCli) inspect.GetRefFunc {
|
|
| 106 |
+ return func(ref string) (interface{}, []byte, error) {
|
|
| 107 |
+ return dockerCli.Client().SecretInspectWithRaw(ctx, ref) |
|
| 108 |
+ } |
|
| 109 |
+} |
|
| 110 |
+ |
|
| 105 | 111 |
func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool, typeConstraint string) inspect.GetRefFunc {
|
| 106 | 112 |
var inspectAutodetect = []struct {
|
| 107 | 113 |
objectType string |
| ... | ... |
@@ -145,6 +150,11 @@ func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool, |
| 145 | 145 |
objectType: "plugin", |
| 146 | 146 |
objectInspector: inspectPlugin(ctx, dockerCli), |
| 147 | 147 |
}, |
| 148 |
+ {
|
|
| 149 |
+ objectType: "secret", |
|
| 150 |
+ isSwarmObject: true, |
|
| 151 |
+ objectInspector: inspectSecret(ctx, dockerCli), |
|
| 152 |
+ }, |
|
| 148 | 153 |
} |
| 149 | 154 |
|
| 150 | 155 |
// 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 |
;; |
| ... | ... |
@@ -2729,6 +2729,8 @@ __docker_subcommand() {
|
| 2729 | 2729 |
__docker_complete_nodes && ret=0 |
| 2730 | 2730 |
elif [[ ${words[(r)--type=plugin]} == --type=plugin ]]; then
|
| 2731 | 2731 |
__docker_complete_plugins && ret=0 |
| 2732 |
+ elif [[ ${words[(r)--type=service]} == --type=secrets ]]; then
|
|
| 2733 |
+ __docker_complete_secrets && ret=0 |
|
| 2732 | 2734 |
elif [[ ${words[(r)--type=service]} == --type=service ]]; then
|
| 2733 | 2735 |
__docker_complete_services && ret=0 |
| 2734 | 2736 |
elif [[ ${words[(r)--type=volume]} == --type=volume ]]; then
|
| ... | ... |
@@ -2739,6 +2741,7 @@ __docker_subcommand() {
|
| 2739 | 2739 |
__docker_complete_networks |
| 2740 | 2740 |
__docker_complete_nodes |
| 2741 | 2741 |
__docker_complete_plugins |
| 2742 |
+ __docker_complete_secrets |
|
| 2742 | 2743 |
__docker_complete_services |
| 2743 | 2744 |
__docker_complete_volumes && ret=0 |
| 2744 | 2745 |
fi |