Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions unstable/propertyvalue/propertyvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ func RemoveSecrets(pv resource.PropertyValue) resource.PropertyValue {
return Transform(unsecret, pv)
}

func RemoveSecretsAndOutputs(pv resource.PropertyValue) resource.PropertyValue {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing secrets and outputs?

Copy link
Contributor Author

@VenelinMartinov VenelinMartinov Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The detailed diff algorithm does not care about secrets and outputs, so this allows us to not have to handle them in the code. Expanded on the explanation in the PR description.

return Transform(func(pv resource.PropertyValue) resource.PropertyValue {
if pv.IsSecret() {
return pv.SecretValue().Element
}
if pv.IsOutput() {
o := pv.OutputValue()
if !o.Known {
return resource.NewComputedProperty(resource.Computed{Element: resource.NewStringProperty("")})
}
return o.Element
}
return pv
}, pv)
}

func extendPath(p resource.PropertyPath, segment any) resource.PropertyPath {
rp := make(resource.PropertyPath, len(p)+1)
copy(rp, p)
Expand Down
20 changes: 20 additions & 0 deletions unstable/propertyvalue/propertyvalue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ func TestRemoveSecrets(t *testing.T) {
})
}

func TestRemoveSecretsAndOutputs(t *testing.T) {
t.Parallel()
rapid.Check(t, func(t *rapid.T) {
randomPV := rtesting.PropertyValueGenerator(5 /* maxDepth */).Draw(t, "pv")
result := RemoveSecretsAndOutputs(randomPV)
if result.ContainsSecrets() {
t.Fatalf("RemoveSecretsAndOutputs(randomPV).ContainsSecrets()")
}

visitor := func(path resource.PropertyPath, val resource.PropertyValue) (resource.PropertyValue, error) {
require.False(t, val.IsSecret())
require.False(t, val.IsOutput())
return val, nil
}

_, err := TransformPropertyValue(resource.PropertyPath{}, visitor, result)
require.NoError(t, err)
})
}

func TestIsNilArray(t *testing.T) {
t.Parallel()

Expand Down
Loading