Skip to content

Commit

Permalink
support the same secret with different targets on service create
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Hazlett <[email protected]>
  • Loading branch information
ehazlett committed Nov 9, 2016
1 parent 8554b64 commit ab5f829
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions command/service/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit ab5f829

Please sign in to comment.