|
@@ -1,20 +1,17 @@
|
|
package secret
|
|
package secret
|
|
|
|
|
|
import (
|
|
import (
|
|
- "fmt"
|
|
|
|
- "text/tabwriter"
|
|
|
|
- "time"
|
|
|
|
-
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/cli"
|
|
"github.com/docker/docker/cli"
|
|
"github.com/docker/docker/cli/command"
|
|
"github.com/docker/docker/cli/command"
|
|
- "github.com/docker/go-units"
|
|
|
|
|
|
+ "github.com/docker/docker/cli/command/formatter"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/cobra"
|
|
"golang.org/x/net/context"
|
|
"golang.org/x/net/context"
|
|
)
|
|
)
|
|
|
|
|
|
type listOptions struct {
|
|
type listOptions struct {
|
|
- quiet bool
|
|
|
|
|
|
+ quiet bool
|
|
|
|
+ format string
|
|
}
|
|
}
|
|
|
|
|
|
func newSecretListCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|
func newSecretListCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|
@@ -32,6 +29,7 @@ func newSecretListCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|
|
|
|
|
flags := cmd.Flags()
|
|
flags := cmd.Flags()
|
|
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs")
|
|
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs")
|
|
|
|
+ flags.StringVarP(&opts.format, "format", "", "", "Pretty-print secrets using a Go template")
|
|
|
|
|
|
return cmd
|
|
return cmd
|
|
}
|
|
}
|
|
@@ -44,25 +42,17 @@ func runSecretList(dockerCli *command.DockerCli, opts listOptions) error {
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
-
|
|
|
|
- w := tabwriter.NewWriter(dockerCli.Out(), 20, 1, 3, ' ', 0)
|
|
|
|
- if opts.quiet {
|
|
|
|
- for _, s := range secrets {
|
|
|
|
- fmt.Fprintf(w, "%s\n", s.ID)
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- fmt.Fprintf(w, "ID\tNAME\tCREATED\tUPDATED")
|
|
|
|
- fmt.Fprintf(w, "\n")
|
|
|
|
-
|
|
|
|
- for _, s := range secrets {
|
|
|
|
- created := units.HumanDuration(time.Now().UTC().Sub(s.Meta.CreatedAt)) + " ago"
|
|
|
|
- updated := units.HumanDuration(time.Now().UTC().Sub(s.Meta.UpdatedAt)) + " ago"
|
|
|
|
-
|
|
|
|
- fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", s.ID, s.Spec.Annotations.Name, created, updated)
|
|
|
|
|
|
+ format := opts.format
|
|
|
|
+ if len(format) == 0 {
|
|
|
|
+ if len(dockerCli.ConfigFile().SecretFormat) > 0 && !opts.quiet {
|
|
|
|
+ format = dockerCli.ConfigFile().SecretFormat
|
|
|
|
+ } else {
|
|
|
|
+ format = formatter.TableFormatKey
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- w.Flush()
|
|
|
|
-
|
|
|
|
- return nil
|
|
|
|
|
|
+ secretCtx := formatter.Context{
|
|
|
|
+ Output: dockerCli.Out(),
|
|
|
|
+ Format: formatter.NewSecretFormat(format, opts.quiet),
|
|
|
|
+ }
|
|
|
|
+ return formatter.SecretWrite(secretCtx, secrets)
|
|
}
|
|
}
|