inspect.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package secret
  2. import (
  3. "github.com/docker/docker/cli"
  4. "github.com/docker/docker/cli/command"
  5. "github.com/docker/docker/cli/command/inspect"
  6. "github.com/spf13/cobra"
  7. "golang.org/x/net/context"
  8. )
  9. type inspectOptions struct {
  10. names []string
  11. format string
  12. }
  13. func newSecretInspectCommand(dockerCli *command.DockerCli) *cobra.Command {
  14. opts := inspectOptions{}
  15. cmd := &cobra.Command{
  16. Use: "inspect [OPTIONS] SECRET [SECRET...]",
  17. Short: "Display detailed information on one or more secrets",
  18. Args: cli.RequiresMinArgs(1),
  19. RunE: func(cmd *cobra.Command, args []string) error {
  20. opts.names = args
  21. return runSecretInspect(dockerCli, opts)
  22. },
  23. }
  24. cmd.Flags().StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template")
  25. return cmd
  26. }
  27. func runSecretInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
  28. client := dockerCli.Client()
  29. ctx := context.Background()
  30. ids, err := getCliRequestedSecretIDs(ctx, client, opts.names)
  31. if err != nil {
  32. return err
  33. }
  34. getRef := func(id string) (interface{}, []byte, error) {
  35. return client.SecretInspectWithRaw(ctx, id)
  36. }
  37. return inspect.Inspect(dockerCli.Out(), ids, opts.format, getRef)
  38. }