Skip to content

Commit 48e6829

Browse files
committed
Reject unknown fields when converting from Struct to Object
This is mostly useful when a function loads its input from the RunFunctionRequest. Crossplane isn't (yet) aware of input schema and will send anything the user supplies. Right now that could include extra unknown, misindented, or typod fields and those will be silently ignored by the function. With this change in place they will result in an error. This code will also be used to load desired and observed resource state, but it's unlikely for those to be invalid. This is a small behavior change, but I feel okay with it. The new behavior is safer, probably won't affect anyone, and we're pre 1.0. crossplane-contrib/function-patch-and-transform#91 (comment) Signed-off-by: Nic Cope <nicc@rk0n.org>
1 parent f1c048d commit 48e6829

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

resource/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func AsObject(s *structpb.Struct, o runtime.Object) error {
9191
if err != nil {
9292
return errors.Wrapf(err, "cannot marshal %T to JSON", s)
9393
}
94-
return errors.Wrapf(json.Unmarshal(b, o), "cannot unmarshal JSON from %T into %T", s, o)
94+
return errors.Wrapf(json.Unmarshal(b, o, json.RejectUnknownMembers(true)), "cannot unmarshal JSON from %T into %T", s, o)
9595
}
9696

9797
// AsStruct gets the supplied struct from the supplied Kubernetes object.

0 commit comments

Comments
 (0)