From ab5f829742a58c6d9f3b168e6724f351f788d6f3 Mon Sep 17 00:00:00 2001 From: Evan Hazlett Date: Thu, 27 Oct 2016 17:18:12 -0700 Subject: [PATCH] support the same secret with different targets on service create Signed-off-by: Evan Hazlett --- command/service/parse.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/command/service/parse.go b/command/service/parse.go index f3061660a2..1a8e56b8c4 100644 --- a/command/service/parse.go +++ b/command/service/parse.go @@ -44,9 +44,10 @@ func parseSecretString(secretString string) (string, string, error) { // them to secret references to use with the spec func parseSecrets(client client.APIClient, requestedSecrets []string) ([]*swarmtypes.SecretReference, error) { lookupSecretNames := []string{} - needSecrets := make(map[string]*swarmtypes.SecretReference) + neededSecrets := make(map[string]*swarmtypes.SecretReference) ctx := context.Background() + neededLookup := map[string]string{} for _, secret := range requestedSecrets { n, t, err := parseSecretString(secret) if err != nil { @@ -60,7 +61,8 @@ func parseSecrets(client client.APIClient, requestedSecrets []string) ([]*swarmt } lookupSecretNames = append(lookupSecretNames, n) - needSecrets[n] = secretRef + neededLookup[t] = n + neededSecrets[t] = secretRef } args := filters.NewArgs() @@ -82,12 +84,17 @@ func parseSecrets(client client.APIClient, requestedSecrets []string) ([]*swarmt addedSecrets := []*swarmtypes.SecretReference{} - for secretName, secretRef := range needSecrets { + for target, secretName := range neededLookup { id, ok := foundSecrets[secretName] if !ok { 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 // since swarm needs the ID instead of the name secretRef.SecretID = id