mirror of https://github.com/docker/cli.git
more review updates
- use /secrets for swarm secret create route - do not specify omitempty for secret and secret reference - simplify lookup for secret ids - do not use pointer for secret grpc conversion Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
parent
3f9494f1d6
commit
4e8f1a7dd9
|
@ -191,19 +191,6 @@ func convertNetworks(networks []string) []swarm.NetworkAttachmentConfig {
|
|||
return nets
|
||||
}
|
||||
|
||||
func convertSecrets(secrets []string) []*swarm.SecretReference {
|
||||
sec := []*swarm.SecretReference{}
|
||||
for _, s := range secrets {
|
||||
sec = append(sec, &swarm.SecretReference{
|
||||
SecretID: s,
|
||||
Mode: swarm.SecretReferenceFile,
|
||||
Target: "",
|
||||
})
|
||||
}
|
||||
|
||||
return sec
|
||||
}
|
||||
|
||||
type endpointOptions struct {
|
||||
mode string
|
||||
ports opts.ListOpts
|
||||
|
@ -417,7 +404,7 @@ func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) {
|
|||
Options: opts.dnsOptions.GetAll(),
|
||||
},
|
||||
StopGracePeriod: opts.stopGrace.Value(),
|
||||
Secrets: convertSecrets(opts.secrets),
|
||||
Secrets: nil,
|
||||
},
|
||||
Networks: convertNetworks(opts.networks.GetAll()),
|
||||
Resources: opts.resources.ToResourceRequirements(),
|
||||
|
|
|
@ -18,7 +18,7 @@ func parseSecretString(secretString string) (string, string, error) {
|
|||
tokens := strings.Split(secretString, ":")
|
||||
|
||||
secretName := strings.TrimSpace(tokens[0])
|
||||
targetName := ""
|
||||
targetName := secretName
|
||||
|
||||
if secretName == "" {
|
||||
return "", "", fmt.Errorf("invalid secret name provided")
|
||||
|
@ -29,8 +29,6 @@ func parseSecretString(secretString string) (string, string, error) {
|
|||
if targetName == "" {
|
||||
return "", "", fmt.Errorf("invalid presentation name provided")
|
||||
}
|
||||
} else {
|
||||
targetName = secretName
|
||||
}
|
||||
|
||||
// ensure target is a filename only; no paths allowed
|
||||
|
@ -77,22 +75,22 @@ func parseSecrets(client client.APIClient, requestedSecrets []string) ([]*swarmt
|
|||
return nil, err
|
||||
}
|
||||
|
||||
foundSecrets := make(map[string]*swarmtypes.Secret)
|
||||
foundSecrets := make(map[string]string)
|
||||
for _, secret := range secrets {
|
||||
foundSecrets[secret.Spec.Annotations.Name] = &secret
|
||||
foundSecrets[secret.Spec.Annotations.Name] = secret.ID
|
||||
}
|
||||
|
||||
addedSecrets := []*swarmtypes.SecretReference{}
|
||||
|
||||
for secretName, secretRef := range needSecrets {
|
||||
s, ok := foundSecrets[secretName]
|
||||
id, ok := foundSecrets[secretName]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("secret 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 = s.ID
|
||||
secretRef.SecretID = id
|
||||
addedSecrets = append(addedSecrets, secretRef)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue