From 4e8f1a7dd9926802a6bd9c292ea4bc3d2339a9eb Mon Sep 17 00:00:00 2001 From: Evan Hazlett Date: Thu, 27 Oct 2016 00:41:32 -0700 Subject: [PATCH] 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 --- command/service/opts.go | 15 +-------------- command/service/parse.go | 12 +++++------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/command/service/opts.go b/command/service/opts.go index a4fd08881c..3ef24ee33c 100644 --- a/command/service/opts.go +++ b/command/service/opts.go @@ -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(), diff --git a/command/service/parse.go b/command/service/parse.go index 596d8e50d8..f3061660a2 100644 --- a/command/service/parse.go +++ b/command/service/parse.go @@ -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) }