support labels for secrets upon creation; review updates

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
Evan Hazlett 2016-11-03 17:01:54 -04:00
parent b3bbcc1ba6
commit 0bda23ec2b
2 changed files with 20 additions and 11 deletions

View File

@ -9,29 +9,37 @@ import (
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/cli"
"github.com/docker/docker/cli/command"
"github.com/docker/docker/opts"
runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/spf13/cobra"
)
type createOptions struct {
name string
labels opts.ListOpts
}
func newSecretCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
return &cobra.Command{
createOpts := createOptions{
labels: opts.NewListOpts(runconfigopts.ValidateEnv),
}
cmd := &cobra.Command{
Use: "create [name]",
Short: "Create a secret using stdin as content",
Args: cli.ExactArgs(1),
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts := createOptions{
name: args[0],
}
return runSecretCreate(dockerCli, opts)
createOpts.name = args[0]
return runSecretCreate(dockerCli, createOpts)
},
}
flags := cmd.Flags()
flags.VarP(&createOpts.labels, "label", "l", "Secret labels")
return cmd
}
func runSecretCreate(dockerCli *command.DockerCli, opts createOptions) error {
func runSecretCreate(dockerCli *command.DockerCli, options createOptions) error {
client := dockerCli.Client()
ctx := context.Background()
@ -42,7 +50,8 @@ func runSecretCreate(dockerCli *command.DockerCli, opts createOptions) error {
spec := swarm.SecretSpec{
Annotations: swarm.Annotations{
Name: opts.name,
Name: options.name,
Labels: runconfigopts.ConvertKVStringsToMap(options.labels.GetAll()),
},
Data: secretData,
}

View File

@ -19,7 +19,7 @@ func parseSecrets(client client.APIClient, requestedSecrets []*types.SecretReque
for _, secret := range requestedSecrets {
secretRef := &swarmtypes.SecretReference{
SecretName: secret.Source,
Target: swarmtypes.SecretReferenceFileTarget{
Target: &swarmtypes.SecretReferenceFileTarget{
Name: secret.Target,
UID: secret.UID,
GID: secret.GID,