Skip to content

Commit

Permalink
Detect single value advanced config/secret syntax
Browse files Browse the repository at this point in the history
Fixes docker#2058 allowing the use of the advanced source=x syntax for config and secret values when there is no comma

Before this change the following would fail with config not found:
	docker service create --name hello1 --config source=myconfig nginx:alpine
And the following would fail with secret not found:
	docker service create --name hello2 --secret source=mysecret nginx:alpine

Signed-off-by: Nick Adcock <[email protected]>
  • Loading branch information
zappy-shu committed Jan 7, 2020
1 parent f7f4a19 commit da3c1dd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion opts/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (o *ConfigOpt) Set(value string) error {
}

// support a simple syntax of --config foo
if len(fields) == 1 {
if len(fields) == 1 && !strings.Contains(fields[0], "=") {
options.File.Name = fields[0]
options.ConfigName = fields[0]
o.values = append(o.values, options)
Expand Down
2 changes: 1 addition & 1 deletion opts/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (o *SecretOpt) Set(value string) error {
}

// support a simple syntax of --secret foo
if len(fields) == 1 {
if len(fields) == 1 && !strings.Contains(fields[0], "=") {
options.File.Name = fields[0]
options.SecretName = fields[0]
o.values = append(o.values, options)
Expand Down
12 changes: 12 additions & 0 deletions opts/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ func TestSecretOptionsSimple(t *testing.T) {
assert.Check(t, is.Equal("0", req.File.GID))
}

func TestSecretOptionsSingle(t *testing.T) {
var opt SecretOpt

testCase := "source=foo"
assert.NilError(t, opt.Set(testCase))

reqs := opt.Value()
assert.Assert(t, is.Len(reqs, 1))
req := reqs[0]
assert.Check(t, is.Equal("foo", req.SecretName))
}

func TestSecretOptionsSourceTarget(t *testing.T) {
var opt SecretOpt

Expand Down

0 comments on commit da3c1dd

Please sign in to comment.