2016-10-19 16:22:02 +00:00
|
|
|
package secret
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-11-29 06:28:46 +00:00
|
|
|
"strings"
|
2016-10-19 16:22:02 +00:00
|
|
|
|
|
|
|
"github.com/docker/docker/cli"
|
|
|
|
"github.com/docker/docker/cli/command"
|
|
|
|
"github.com/spf13/cobra"
|
2016-11-10 00:59:01 +00:00
|
|
|
"golang.org/x/net/context"
|
2016-10-19 16:22:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type removeOptions struct {
|
2016-11-22 16:18:28 +00:00
|
|
|
names []string
|
2016-10-19 16:22:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newSecretRemoveCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
2016-11-29 15:44:12 +00:00
|
|
|
Use: "rm SECRET [SECRET...]",
|
|
|
|
Aliases: []string{"remove"},
|
|
|
|
Short: "Remove one or more secrets",
|
|
|
|
Args: cli.RequiresMinArgs(1),
|
2016-10-19 16:22:02 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
opts := removeOptions{
|
2016-11-22 16:18:28 +00:00
|
|
|
names: args,
|
2016-10-19 16:22:02 +00:00
|
|
|
}
|
|
|
|
return runSecretRemove(dockerCli, opts)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func runSecretRemove(dockerCli *command.DockerCli, opts removeOptions) error {
|
|
|
|
client := dockerCli.Client()
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2016-11-29 06:28:46 +00:00
|
|
|
var errs []string
|
|
|
|
|
2016-12-07 19:06:07 +00:00
|
|
|
for _, name := range opts.names {
|
|
|
|
if err := client.SecretRemove(ctx, name); err != nil {
|
2016-11-29 06:28:46 +00:00
|
|
|
errs = append(errs, err.Error())
|
|
|
|
continue
|
2016-10-19 16:22:02 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 19:06:07 +00:00
|
|
|
fmt.Fprintln(dockerCli.Out(), name)
|
2016-10-19 16:22:02 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 06:28:46 +00:00
|
|
|
if len(errs) > 0 {
|
|
|
|
return fmt.Errorf("%s", strings.Join(errs, "\n"))
|
|
|
|
}
|
|
|
|
|
2016-10-19 16:22:02 +00:00
|
|
|
return nil
|
|
|
|
}
|