2016-10-19 12:22:02 -04:00
|
|
|
package secret
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
2017-05-15 18:23:20 -04:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli"
|
|
|
|
"github.com/docker/cli/cli/command"
|
2017-05-15 18:23:20 -04:00
|
|
|
"github.com/docker/cli/cli/command/formatter"
|
2021-01-18 05:43:29 -05:00
|
|
|
flagsHelper "github.com/docker/cli/cli/flags"
|
2016-10-19 12:22:02 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
type inspectOptions struct {
|
2016-11-22 11:18:28 -05:00
|
|
|
names []string
|
2016-10-19 12:22:02 -04:00
|
|
|
format string
|
2017-05-15 18:23:20 -04:00
|
|
|
pretty bool
|
2016-10-19 12:22:02 -04:00
|
|
|
}
|
|
|
|
|
2017-04-01 03:07:22 -04:00
|
|
|
func newSecretInspectCommand(dockerCli command.Cli) *cobra.Command {
|
2016-10-19 12:22:02 -04:00
|
|
|
opts := inspectOptions{}
|
|
|
|
cmd := &cobra.Command{
|
2016-11-18 01:28:21 -05:00
|
|
|
Use: "inspect [OPTIONS] SECRET [SECRET...]",
|
|
|
|
Short: "Display detailed information on one or more secrets",
|
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)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-03-08 08:54:21 -05:00
|
|
|
cmd.Flags().StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp)
|
2017-05-15 18:23:20 -04:00
|
|
|
cmd.Flags().BoolVar(&opts.pretty, "pretty", false, "Print the information in a human friendly format")
|
2016-10-19 12:22:02 -04:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2017-04-01 03:07:22 -04:00
|
|
|
func runSecretInspect(dockerCli command.Cli, opts inspectOptions) error {
|
2016-10-19 12:22:02 -04:00
|
|
|
client := dockerCli.Client()
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2017-05-15 18:23:20 -04:00
|
|
|
if opts.pretty {
|
|
|
|
opts.format = "pretty"
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2017-05-15 18:23:20 -04:00
|
|
|
f := opts.format
|
|
|
|
|
|
|
|
// check if the user is trying to apply a template to the pretty format, which
|
|
|
|
// is not supported
|
|
|
|
if strings.HasPrefix(f, "pretty") && f != "pretty" {
|
|
|
|
return fmt.Errorf("Cannot supply extra formatting options to the pretty template")
|
|
|
|
}
|
|
|
|
|
|
|
|
secretCtx := formatter.Context{
|
|
|
|
Output: dockerCli.Out(),
|
2018-10-23 11:05:44 -04:00
|
|
|
Format: NewFormat(f, false),
|
2017-05-15 18:23:20 -04:00
|
|
|
}
|
2016-10-19 12:22:02 -04:00
|
|
|
|
2018-10-23 11:05:44 -04:00
|
|
|
if err := InspectFormatWrite(secretCtx, opts.names, getRef); err != nil {
|
2017-05-15 18:23:20 -04:00
|
|
|
return cli.StatusError{StatusCode: 1, Status: err.Error()}
|
|
|
|
}
|
|
|
|
return nil
|
2016-10-19 12:22:02 -04:00
|
|
|
}
|