2016-10-19 12:22:02 -04:00
|
|
|
package secret
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/docker/docker/cli"
|
|
|
|
"github.com/docker/docker/cli/command"
|
|
|
|
"github.com/spf13/cobra"
|
2016-11-09 19:59:01 -05:00
|
|
|
"golang.org/x/net/context"
|
2016-10-19 12:22:02 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type removeOptions struct {
|
2016-11-22 11:18:28 -05:00
|
|
|
names []string
|
2016-10-19 12:22:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func newSecretRemoveCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
2016-11-22 11:18:28 -05:00
|
|
|
Use: "rm SECRET [SECRET]",
|
2016-10-19 12:22:02 -04:00
|
|
|
Short: "Remove a secret",
|
|
|
|
Args: cli.RequiresMinArgs(1),
|
|
|
|
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)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func runSecretRemove(dockerCli *command.DockerCli, opts removeOptions) error {
|
|
|
|
client := dockerCli.Client()
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2016-11-22 11:18:28 -05:00
|
|
|
ids, err := getCliRequestedSecretIDs(ctx, client, opts.names)
|
2016-11-01 23:32:21 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, id := range ids {
|
2016-10-19 12:22:02 -04:00
|
|
|
if err := client.SecretRemove(ctx, id); err != nil {
|
2016-11-22 11:18:28 -05:00
|
|
|
fmt.Fprintf(dockerCli.Out(), "WARN: %s\n", err)
|
2016-10-19 12:22:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintln(dockerCli.Out(), id)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|