2016-10-19 12:22:02 -04:00
|
|
|
package secret
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/cli"
|
|
|
|
"github.com/docker/docker/cli/command"
|
|
|
|
"github.com/docker/docker/cli/command/inspect"
|
|
|
|
"github.com/spf13/cobra"
|
2016-11-09 19:59:01 -05:00
|
|
|
"golang.org/x/net/context"
|
2016-10-19 12:22:02 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type inspectOptions struct {
|
2016-11-22 11:18:28 -05:00
|
|
|
names []string
|
2016-10-19 12:22:02 -04:00
|
|
|
format string
|
|
|
|
}
|
|
|
|
|
|
|
|
func newSecretInspectCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|
|
|
opts := inspectOptions{}
|
|
|
|
cmd := &cobra.Command{
|
2016-11-22 11:18:28 -05:00
|
|
|
Use: "inspect SECRET [SECRET]",
|
2016-10-19 12:22:02 -04:00
|
|
|
Short: "Inspect a secret",
|
2016-11-22 11:18:28 -05:00
|
|
|
Args: cli.RequiresMinArgs(1),
|
2016-10-19 12:22:02 -04:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2016-11-22 11:18:28 -05:00
|
|
|
opts.names = args
|
2016-10-19 12:22:02 -04:00
|
|
|
return runSecretInspect(dockerCli, opts)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Flags().StringVarP(&opts.format, "format", "f", "", "Format the output using the given go template")
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func runSecretInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
|
|
|
|
client := dockerCli.Client()
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2016-11-22 11:18:28 -05:00
|
|
|
ids, err := getCliRequestedSecretIDs(ctx, client, opts.names)
|
2016-11-01 23:32:21 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-11-22 11:18:28 -05:00
|
|
|
getRef := func(id string) (interface{}, []byte, error) {
|
2016-11-01 23:32:21 -04:00
|
|
|
return client.SecretInspectWithRaw(ctx, id)
|
2016-10-19 12:22:02 -04:00
|
|
|
}
|
|
|
|
|
2016-11-22 11:18:28 -05:00
|
|
|
return inspect.Inspect(dockerCli.Out(), ids, opts.format, getRef)
|
2016-10-19 12:22:02 -04:00
|
|
|
}
|