From d2472c57c731a8c212319cf3c3af1b778bd03d4b Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Mon, 31 Jan 2022 18:37:31 -0700 Subject: [PATCH 1/2] using map[string]string and moved Secrets.New outside of Walk Signed-off-by: Richard Jones --- plan/task/transformsecret.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/plan/task/transformsecret.go b/plan/task/transformsecret.go index d4848338..a135abc8 100644 --- a/plan/task/transformsecret.go +++ b/plan/task/transformsecret.go @@ -48,32 +48,30 @@ func (c *transformSecretTask) Run(ctx context.Context, pctx *plancontext.Context return nil, errors.New(errStr) } - type pathSecret struct { - path cue.Path - secret *plancontext.Secret - } - - var pathsSecrets []pathSecret + pathToSecrets := make(map[string]string) // users could yaml.Unmarshal(input) and return a map // or yaml.Unmarshal(input).someKey and return a string // walk will ensure we convert every leaf functionPathSelectors := function.Path().Selectors() + function.Lookup("output").Walk(nil, func(v *compiler.Value) { if v.Kind() == cue.StringKind { plaintext, _ := v.String() - secret := pctx.Secrets.New(plaintext) newLeafSelectors := v.Path().Selectors()[len(functionPathSelectors):] newLeafSelectors = append(newLeafSelectors, cue.Str("contents")) newLeafPath := cue.MakePath(newLeafSelectors...) - pathsSecrets = append(pathsSecrets, pathSecret{newLeafPath, secret}) + p := newLeafPath.String() + pathToSecrets[p] = plaintext + } }) output := compiler.NewValue() - for _, ps := range pathsSecrets { - output.FillPath(ps.path, ps.secret.MarshalCUE()) + for p, s := range pathToSecrets { + secret := pctx.Secrets.New(s) + output.FillPath(cue.ParsePath(p), secret.MarshalCUE()) } return output, nil From 9d899a6282884d38b1875843e3c3626594822efb Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Mon, 31 Jan 2022 18:46:10 -0700 Subject: [PATCH 2/2] fixed lint issue Signed-off-by: Richard Jones --- plan/task/transformsecret.go | 1 - 1 file changed, 1 deletion(-) diff --git a/plan/task/transformsecret.go b/plan/task/transformsecret.go index a135abc8..3bc482ea 100644 --- a/plan/task/transformsecret.go +++ b/plan/task/transformsecret.go @@ -63,7 +63,6 @@ func (c *transformSecretTask) Run(ctx context.Context, pctx *plancontext.Context newLeafPath := cue.MakePath(newLeafSelectors...) p := newLeafPath.String() pathToSecrets[p] = plaintext - } })