2016-11-01 23:32:21 -04:00
|
|
|
package secret
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
|
|
|
"github.com/docker/docker/api/types/swarm"
|
|
|
|
"github.com/docker/docker/client"
|
2016-11-09 19:59:01 -05:00
|
|
|
"golang.org/x/net/context"
|
2016-11-01 23:32:21 -04:00
|
|
|
)
|
|
|
|
|
2016-11-12 01:14:34 -05:00
|
|
|
func getSecretsByName(ctx context.Context, client client.APIClient, names []string) ([]swarm.Secret, error) {
|
2016-11-01 23:32:21 -04:00
|
|
|
args := filters.NewArgs()
|
|
|
|
for _, n := range names {
|
|
|
|
args.Add("names", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
return client.SecretList(ctx, types.SecretListOptions{
|
2016-11-03 14:09:13 -04:00
|
|
|
Filters: args,
|
2016-11-01 23:32:21 -04:00
|
|
|
})
|
|
|
|
}
|
2016-11-22 11:18:28 -05:00
|
|
|
|
|
|
|
func getCliRequestedSecretIDs(ctx context.Context, client client.APIClient, names []string) ([]string, error) {
|
|
|
|
ids := names
|
|
|
|
|
|
|
|
// attempt to lookup secret by name
|
|
|
|
secrets, err := getSecretsByName(ctx, client, ids)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
lookup := make(map[string]struct{})
|
|
|
|
for _, id := range ids {
|
|
|
|
lookup[id] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(secrets) > 0 {
|
|
|
|
ids = []string{}
|
|
|
|
|
|
|
|
for _, s := range secrets {
|
|
|
|
if _, ok := lookup[s.Spec.Annotations.Name]; ok {
|
|
|
|
ids = append(ids, s.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ids, nil
|
|
|
|
}
|