2016-10-19 12:22:02 -04:00
|
|
|
package secret
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
2016-10-19 12:22:02 -04:00
|
|
|
"fmt"
|
2016-11-29 01:28:46 -05:00
|
|
|
"strings"
|
2016-10-19 12:22:02 -04:00
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli"
|
|
|
|
"github.com/docker/cli/cli/command"
|
2017-03-09 13:23:45 -05:00
|
|
|
"github.com/pkg/errors"
|
2016-10-19 12:22:02 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
type removeOptions struct {
|
2016-11-22 11:18:28 -05:00
|
|
|
names []string
|
2016-10-19 12:22:02 -04:00
|
|
|
}
|
|
|
|
|
2017-04-01 03:07:22 -04:00
|
|
|
func newSecretRemoveCommand(dockerCli command.Cli) *cobra.Command {
|
2016-10-19 12:22:02 -04:00
|
|
|
return &cobra.Command{
|
2016-11-29 10:44:12 -05:00
|
|
|
Use: "rm SECRET [SECRET...]",
|
|
|
|
Aliases: []string{"remove"},
|
|
|
|
Short: "Remove one or more secrets",
|
|
|
|
Args: cli.RequiresMinArgs(1),
|
2016-10-19 12:22:02 -04:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
opts := removeOptions{
|
2016-11-22 11:18:28 -05:00
|
|
|
names: args,
|
2016-10-19 12:22:02 -04:00
|
|
|
}
|
|
|
|
return runSecretRemove(dockerCli, opts)
|
|
|
|
},
|
2022-03-30 09:27:25 -04:00
|
|
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
|
|
return completeNames(dockerCli)(cmd, args, toComplete)
|
|
|
|
},
|
2016-10-19 12:22:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-01 03:07:22 -04:00
|
|
|
func runSecretRemove(dockerCli command.Cli, opts removeOptions) error {
|
2016-10-19 12:22:02 -04:00
|
|
|
client := dockerCli.Client()
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2016-11-29 01:28:46 -05:00
|
|
|
var errs []string
|
|
|
|
|
2016-12-07 14:06:07 -05:00
|
|
|
for _, name := range opts.names {
|
|
|
|
if err := client.SecretRemove(ctx, name); err != nil {
|
2016-11-29 01:28:46 -05:00
|
|
|
errs = append(errs, err.Error())
|
|
|
|
continue
|
2016-10-19 12:22:02 -04:00
|
|
|
}
|
|
|
|
|
2016-12-07 14:06:07 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), name)
|
2016-10-19 12:22:02 -04:00
|
|
|
}
|
|
|
|
|
2016-11-29 01:28:46 -05:00
|
|
|
if len(errs) > 0 {
|
2017-03-09 13:23:45 -05:00
|
|
|
return errors.Errorf("%s", strings.Join(errs, "\n"))
|
2016-11-29 01:28:46 -05:00
|
|
|
}
|
|
|
|
|
2016-10-19 12:22:02 -04:00
|
|
|
return nil
|
|
|
|
}
|