mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
support the same secret with different targets on service create
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
parent
00237a9624
commit
111e497dc6
1 changed files with 10 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue