mirror of https://github.com/docker/cli.git
review updates
- use Filters instead of Filter for secret list - UID, GID -> string - getSecrets -> getSecretsByName - updated test case for secrets with better source - use golang.org/x/context instead of context - for grpc conversion allocate with make - check for nil with task.Spec.GetContainer() Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
parent
91c08eab93
commit
9074333957
|
@ -35,7 +35,7 @@ func runSecretInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
|
|||
ctx := context.Background()
|
||||
|
||||
// attempt to lookup secret by name
|
||||
secrets, err := getSecrets(client, ctx, []string{opts.name})
|
||||
secrets, err := getSecretsByName(client, ctx, []string{opts.name})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ func runSecretRemove(dockerCli *command.DockerCli, opts removeOptions) error {
|
|||
ctx := context.Background()
|
||||
|
||||
// attempt to lookup secret by name
|
||||
secrets, err := getSecrets(client, ctx, opts.ids)
|
||||
secrets, err := getSecretsByName(client, ctx, opts.ids)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -9,13 +9,13 @@ import (
|
|||
"github.com/docker/docker/client"
|
||||
)
|
||||
|
||||
func getSecrets(client client.APIClient, ctx context.Context, names []string) ([]swarm.Secret, error) {
|
||||
func getSecretsByName(client client.APIClient, ctx context.Context, names []string) ([]swarm.Secret, error) {
|
||||
args := filters.NewArgs()
|
||||
for _, n := range names {
|
||||
args.Add("names", n)
|
||||
}
|
||||
|
||||
return client.SecretList(ctx, types.SecretListOptions{
|
||||
Filter: args,
|
||||
Filters: args,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -108,45 +108,45 @@ func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSecretOptionsSimple(t *testing.T) {
|
||||
var opt SecretOpt
|
||||
var opt opts.SecretOpt
|
||||
|
||||
testCase := "source=/foo,target=testing"
|
||||
testCase := "source=foo,target=testing"
|
||||
assert.NilError(t, opt.Set(testCase))
|
||||
|
||||
reqs := opt.Value()
|
||||
assert.Equal(t, len(reqs), 1)
|
||||
req := reqs[0]
|
||||
assert.Equal(t, req.source, "/foo")
|
||||
assert.Equal(t, req.target, "testing")
|
||||
assert.Equal(t, req.Source, "foo")
|
||||
assert.Equal(t, req.Target, "testing")
|
||||
}
|
||||
|
||||
func TestSecretOptionsCustomUidGid(t *testing.T) {
|
||||
var opt SecretOpt
|
||||
var opt opts.SecretOpt
|
||||
|
||||
testCase := "source=/foo,target=testing,uid=1000,gid=1001"
|
||||
testCase := "source=foo,target=testing,uid=1000,gid=1001"
|
||||
assert.NilError(t, opt.Set(testCase))
|
||||
|
||||
reqs := opt.Value()
|
||||
assert.Equal(t, len(reqs), 1)
|
||||
req := reqs[0]
|
||||
assert.Equal(t, req.source, "/foo")
|
||||
assert.Equal(t, req.target, "testing")
|
||||
assert.Equal(t, req.uid, "1000")
|
||||
assert.Equal(t, req.gid, "1001")
|
||||
assert.Equal(t, req.Source, "foo")
|
||||
assert.Equal(t, req.Target, "testing")
|
||||
assert.Equal(t, req.UID, "1000")
|
||||
assert.Equal(t, req.GID, "1001")
|
||||
}
|
||||
|
||||
func TestSecretOptionsCustomMode(t *testing.T) {
|
||||
var opt SecretOpt
|
||||
var opt opts.SecretOpt
|
||||
|
||||
testCase := "source=/foo,target=testing,uid=1000,gid=1001,mode=0444"
|
||||
testCase := "source=foo,target=testing,uid=1000,gid=1001,mode=0444"
|
||||
assert.NilError(t, opt.Set(testCase))
|
||||
|
||||
reqs := opt.Value()
|
||||
assert.Equal(t, len(reqs), 1)
|
||||
req := reqs[0]
|
||||
assert.Equal(t, req.source, "/foo")
|
||||
assert.Equal(t, req.target, "testing")
|
||||
assert.Equal(t, req.uid, "1000")
|
||||
assert.Equal(t, req.gid, "1001")
|
||||
assert.Equal(t, req.mode, os.FileMode(0444))
|
||||
assert.Equal(t, req.Source, "foo")
|
||||
assert.Equal(t, req.Target, "testing")
|
||||
assert.Equal(t, req.UID, "1000")
|
||||
assert.Equal(t, req.GID, "1001")
|
||||
assert.Equal(t, req.Mode, os.FileMode(0444))
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
swarmtypes "github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/client"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// parseSecrets retrieves the secrets from the requested names and converts
|
||||
|
@ -39,7 +39,7 @@ func parseSecrets(client client.APIClient, requestedSecrets []*types.SecretReque
|
|||
}
|
||||
|
||||
secrets, err := client.SecretList(ctx, types.SecretListOptions{
|
||||
Filter: args,
|
||||
Filters: args,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Reference in New Issue