1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #29955 from vieux/improve_secret_Create

remove -f on secret create and unify usage with other commands
This commit is contained in:
Tibor Vass 2017-01-09 10:22:39 -08:00 committed by GitHub
commit 3e298f46a2
3 changed files with 8 additions and 22 deletions

View file

@ -27,17 +27,17 @@ func newSecretCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
} }
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "create [OPTIONS] SECRET", Use: "create [OPTIONS] SECRET file|-",
Short: "Create a secret from a file or STDIN as content", Short: "Create a secret from a file or STDIN as content",
Args: cli.ExactArgs(1), Args: cli.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
createOpts.name = args[0] createOpts.name = args[0]
createOpts.file = args[1]
return runSecretCreate(dockerCli, createOpts) return runSecretCreate(dockerCli, createOpts)
}, },
} }
flags := cmd.Flags() flags := cmd.Flags()
flags.VarP(&createOpts.labels, "label", "l", "Secret labels") flags.VarP(&createOpts.labels, "label", "l", "Secret labels")
flags.StringVarP(&createOpts.file, "file", "f", "", "Read from a file or STDIN ('-')")
return cmd return cmd
} }
@ -46,10 +46,6 @@ func runSecretCreate(dockerCli *command.DockerCli, options createOptions) error
client := dockerCli.Client() client := dockerCli.Client()
ctx := context.Background() ctx := context.Background()
if options.file == "" {
return fmt.Errorf("Please specify either a file name or STDIN ('-') with --file")
}
var in io.Reader = dockerCli.In() var in io.Reader = dockerCli.In()
if options.file != "-" { if options.file != "-" {
file, err := system.OpenSequential(options.file) file, err := system.OpenSequential(options.file)

View file

@ -16,12 +16,11 @@ keywords: ["secret, create"]
# secret create # secret create
```Markdown ```Markdown
Usage: docker secret create [OPTIONS] SECRET Usage: docker secret create [OPTIONS] SECRET file|-
Create a secret from a file or STDIN as content Create a secret from a file or STDIN as content
Options: Options:
-f, --file string Read from a file or STDIN ('-')
--help Print usage --help Print usage
-l, --label list Secret labels (default []) -l, --label list Secret labels (default [])
``` ```
@ -34,7 +33,7 @@ command on a manager node.
### Create a secret ### Create a secret
```bash ```bash
$ echo <secret> | docker secret create -f - my_secret $ echo <secret> | docker secret create my_secret -
mhv17xfe3gh6xc4rij5orpfds mhv17xfe3gh6xc4rij5orpfds
$ docker secret ls $ docker secret ls
@ -45,7 +44,7 @@ mhv17xfe3gh6xc4rij5orpfds my_secret 2016-10-27 23:25:43.90918108
### Create a secret with a file ### Create a secret with a file
```bash ```bash
$ docker secret create -f secret.json my_secret $ docker secret create my_secret ./secret.json
mhv17xfe3gh6xc4rij5orpfds mhv17xfe3gh6xc4rij5orpfds
$ docker secret ls $ docker secret ls
@ -56,7 +55,7 @@ mhv17xfe3gh6xc4rij5orpfds my_secret 2016-10-27 23:25:43.90918108
### Create a secret with labels ### Create a secret with labels
```bash ```bash
$ docker secret create -f secret.json --label env=dev --label rev=20161102 my_secret $ docker secret create --label env=dev --label rev=20161102 my_secret ./secret.json
jtn7g6aukl5ky7nr9gvwafoxh jtn7g6aukl5ky7nr9gvwafoxh
$ docker secret inspect my_secret $ docker secret inspect my_secret

View file

@ -121,20 +121,11 @@ func (s *DockerSwarmSuite) TestSecretCreateWithFile(c *check.C) {
c.Assert(err, checker.IsNil, check.Commentf("failed to write to temporary file")) c.Assert(err, checker.IsNil, check.Commentf("failed to write to temporary file"))
testName := "test_secret" testName := "test_secret"
out, err := d.Cmd("secret", "create", "--file", testFile.Name(), testName) out, err := d.Cmd("secret", "create", testName, testFile.Name())
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "", check.Commentf(out)) c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "", check.Commentf(out))
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
secret := d.GetSecret(c, id) secret := d.GetSecret(c, id)
c.Assert(secret.Spec.Name, checker.Equals, testName) c.Assert(secret.Spec.Name, checker.Equals, testName)
testName = "test_secret_2"
out, err = d.Cmd("secret", "create", testName, "-f", testFile.Name())
c.Assert(err, checker.IsNil)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "", check.Commentf(out))
id = strings.TrimSpace(out)
secret = d.GetSecret(c, id)
c.Assert(secret.Spec.Name, checker.Equals, testName)
} }