From 32927718111b086126d660f915fa0f3382562e03 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 25 Jan 2022 16:10:39 -0700 Subject: [PATCH 1/2] moved FillPath outside of Walk Signed-off-by: Richard Jones --- plan/task/transformsecret.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/plan/task/transformsecret.go b/plan/task/transformsecret.go index c956e2e8..a0df981e 100644 --- a/plan/task/transformsecret.go +++ b/plan/task/transformsecret.go @@ -48,7 +48,13 @@ func (c *transformSecretTask) Run(ctx context.Context, pctx *plancontext.Context return nil, errors.New(errStr) } - output := compiler.NewValue() + type pathSecret struct { + path cue.Path + value *compiler.Value + } + + var pathsSecrets []pathSecret + // 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 @@ -60,9 +66,15 @@ func (c *transformSecretTask) Run(ctx context.Context, pctx *plancontext.Context newLeafSelectors := v.Path().Selectors()[len(functionPathSelectors):] newLeafSelectors = append(newLeafSelectors, cue.Str("contents")) newLeafPath := cue.MakePath(newLeafSelectors...) - output.FillPath(newLeafPath, secret.MarshalCUE()) + pathsSecrets = append(pathsSecrets, pathSecret{newLeafPath, secret.MarshalCUE()}) } }) + output := compiler.NewValue() + + for _, ps := range pathsSecrets { + output.FillPath(ps.path, ps.value) + } + return output, nil } From a3c9c008c24ce006bc95ef45ed5a7b2f9c559dd7 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 25 Jan 2022 16:49:27 -0700 Subject: [PATCH 2/2] moved secret.MarshalCUE to outside of Walk Signed-off-by: Richard Jones --- plan/task/transformsecret.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plan/task/transformsecret.go b/plan/task/transformsecret.go index a0df981e..d4848338 100644 --- a/plan/task/transformsecret.go +++ b/plan/task/transformsecret.go @@ -49,8 +49,8 @@ func (c *transformSecretTask) Run(ctx context.Context, pctx *plancontext.Context } type pathSecret struct { - path cue.Path - value *compiler.Value + path cue.Path + secret *plancontext.Secret } var pathsSecrets []pathSecret @@ -66,14 +66,14 @@ func (c *transformSecretTask) Run(ctx context.Context, pctx *plancontext.Context newLeafSelectors := v.Path().Selectors()[len(functionPathSelectors):] newLeafSelectors = append(newLeafSelectors, cue.Str("contents")) newLeafPath := cue.MakePath(newLeafSelectors...) - pathsSecrets = append(pathsSecrets, pathSecret{newLeafPath, secret.MarshalCUE()}) + pathsSecrets = append(pathsSecrets, pathSecret{newLeafPath, secret}) } }) output := compiler.NewValue() for _, ps := range pathsSecrets { - output.FillPath(ps.path, ps.value) + output.FillPath(ps.path, ps.secret.MarshalCUE()) } return output, nil