mirror of https://github.com/docker/cli.git
support the same secret with different targets on service create
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
parent
8554b64b99
commit
ab5f829742
|
@ -44,9 +44,10 @@ func parseSecretString(secretString string) (string, string, error) {
|
||||||
// them to secret references to use with the spec
|
// them to secret references to use with the spec
|
||||||
func parseSecrets(client client.APIClient, requestedSecrets []string) ([]*swarmtypes.SecretReference, error) {
|
func parseSecrets(client client.APIClient, requestedSecrets []string) ([]*swarmtypes.SecretReference, error) {
|
||||||
lookupSecretNames := []string{}
|
lookupSecretNames := []string{}
|
||||||
needSecrets := make(map[string]*swarmtypes.SecretReference)
|
neededSecrets := make(map[string]*swarmtypes.SecretReference)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
neededLookup := map[string]string{}
|
||||||
for _, secret := range requestedSecrets {
|
for _, secret := range requestedSecrets {
|
||||||
n, t, err := parseSecretString(secret)
|
n, t, err := parseSecretString(secret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -60,7 +61,8 @@ func parseSecrets(client client.APIClient, requestedSecrets []string) ([]*swarmt
|
||||||
}
|
}
|
||||||
|
|
||||||
lookupSecretNames = append(lookupSecretNames, n)
|
lookupSecretNames = append(lookupSecretNames, n)
|
||||||
needSecrets[n] = secretRef
|
neededLookup[t] = n
|
||||||
|
neededSecrets[t] = secretRef
|
||||||
}
|
}
|
||||||
|
|
||||||
args := filters.NewArgs()
|
args := filters.NewArgs()
|
||||||
|
@ -82,12 +84,17 @@ func parseSecrets(client client.APIClient, requestedSecrets []string) ([]*swarmt
|
||||||
|
|
||||||
addedSecrets := []*swarmtypes.SecretReference{}
|
addedSecrets := []*swarmtypes.SecretReference{}
|
||||||
|
|
||||||
for secretName, secretRef := range needSecrets {
|
for target, secretName := range neededLookup {
|
||||||
id, ok := foundSecrets[secretName]
|
id, ok := foundSecrets[secretName]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("secret not found: %s", secretName)
|
return nil, fmt.Errorf("secret not found: %s", secretName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
secretRef, ok := neededSecrets[target]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("secret reference not found: %s", secretName)
|
||||||
|
}
|
||||||
|
|
||||||
// set the id for the ref to properly assign in swarm
|
// set the id for the ref to properly assign in swarm
|
||||||
// since swarm needs the ID instead of the name
|
// since swarm needs the ID instead of the name
|
||||||
secretRef.SecretID = id
|
secretRef.SecretID = id
|
||||||
|
|
Loading…
Reference in New Issue