mirror of https://github.com/docker/cli.git
support labels for secrets upon creation; review updates
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
parent
b3bbcc1ba6
commit
0bda23ec2b
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue