Skip to content

Commit

Permalink
move Patch handling to eval pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
nyobe committed Jan 15, 2025
1 parent 4fa0993 commit be5df41
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ func (e *evalContext) evaluateBuiltinRotate(x *expr, repr *rotateExpr) *value {
inputsPath += ".inputs"
}

e.patchOutputs = append(e.patchOutputs, &esc.Patch{
e.patchOutputs = append(e.patchOutputs, &Patch{
// rotation output is written back to the fn's `state` input
DocPath: x.path + "." + inputsPath + ".state",
Replacement: newState,
Expand Down
11 changes: 6 additions & 5 deletions patch.go → eval/patch.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package esc
package eval

import (
"github.com/pulumi/esc"
"github.com/pulumi/esc/syntax/encoding"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"gopkg.in/yaml.v3"
Expand All @@ -9,7 +10,7 @@ import (
// Patch represents a value that should be written back to the environment at the given path.
type Patch struct {
DocPath string
Replacement Value
Replacement esc.Value
}

// ApplyPatches applies a set of patches values to an environment definition.
Expand Down Expand Up @@ -48,16 +49,16 @@ func ApplyPatches(source []byte, patches []*Patch) ([]byte, error) {
}

// valueToSecretJSON converts a Value into a plain-old-JSON value, but secret values are wrapped with fn::secret
func valueToSecretJSON(v Value) any {
func valueToSecretJSON(v esc.Value) any {
ret := func() any {
switch pv := v.Value.(type) {
case []Value:
case []esc.Value:
a := make([]any, len(pv))
for i, v := range pv {
a[i] = valueToSecretJSON(v)
}
return a
case map[string]Value:
case map[string]esc.Value:
m := make(map[string]any, len(pv))
for k, v := range pv {
m[k] = valueToSecretJSON(v)
Expand Down
2 changes: 1 addition & 1 deletion eval/rotate_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ values:
require.Len(t, diags, 0)

// writeback state patches
update, err := esc.ApplyPatches([]byte(def), patches)
update, err := ApplyPatches([]byte(def), patches)
require.NoError(t, err)

encryptedYaml, err := EncryptSecrets(context.Background(), "<stdin>", update, rot128{})
Expand Down

0 comments on commit be5df41

Please sign in to comment.