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:
Evan Hazlett 2016-10-27 00:41:32 -07:00
parent 3f9494f1d6
commit 4e8f1a7dd9
2 changed files with 6 additions and 21 deletions

View File

@ -191,19 +191,6 @@ func convertNetworks(networks []string) []swarm.NetworkAttachmentConfig {
return nets 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 { type endpointOptions struct {
mode string mode string
ports opts.ListOpts ports opts.ListOpts
@ -417,7 +404,7 @@ func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) {
Options: opts.dnsOptions.GetAll(), Options: opts.dnsOptions.GetAll(),
}, },
StopGracePeriod: opts.stopGrace.Value(), StopGracePeriod: opts.stopGrace.Value(),
Secrets: convertSecrets(opts.secrets), Secrets: nil,
}, },
Networks: convertNetworks(opts.networks.GetAll()), Networks: convertNetworks(opts.networks.GetAll()),
Resources: opts.resources.ToResourceRequirements(), Resources: opts.resources.ToResourceRequirements(),

View File

@ -18,7 +18,7 @@ func parseSecretString(secretString string) (string, string, error) {
tokens := strings.Split(secretString, ":") tokens := strings.Split(secretString, ":")
secretName := strings.TrimSpace(tokens[0]) secretName := strings.TrimSpace(tokens[0])
targetName := "" targetName := secretName
if secretName == "" { if secretName == "" {
return "", "", fmt.Errorf("invalid secret name provided") return "", "", fmt.Errorf("invalid secret name provided")
@ -29,8 +29,6 @@ func parseSecretString(secretString string) (string, string, error) {
if targetName == "" { if targetName == "" {
return "", "", fmt.Errorf("invalid presentation name provided") return "", "", fmt.Errorf("invalid presentation name provided")
} }
} else {
targetName = secretName
} }
// ensure target is a filename only; no paths allowed // ensure target is a filename only; no paths allowed
@ -77,22 +75,22 @@ func parseSecrets(client client.APIClient, requestedSecrets []string) ([]*swarmt
return nil, err return nil, err
} }
foundSecrets := make(map[string]*swarmtypes.Secret) foundSecrets := make(map[string]string)
for _, secret := range secrets { for _, secret := range secrets {
foundSecrets[secret.Spec.Annotations.Name] = &secret foundSecrets[secret.Spec.Annotations.Name] = secret.ID
} }
addedSecrets := []*swarmtypes.SecretReference{} addedSecrets := []*swarmtypes.SecretReference{}
for secretName, secretRef := range needSecrets { for secretName, secretRef := range needSecrets {
s, 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)
} }
// 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 = s.ID secretRef.SecretID = id
addedSecrets = append(addedSecrets, secretRef) addedSecrets = append(addedSecrets, secretRef)
} }