Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resourcex.Marshal #200

Open
danielrbradley opened this issue Mar 20, 2024 · 1 comment
Open

Add resourcex.Marshal #200

danielrbradley opened this issue Mar 20, 2024 · 1 comment
Labels
enhancement New feature or request kind/enhancement Improvements or new features

Comments

@danielrbradley
Copy link
Member

danielrbradley commented Mar 20, 2024

Add a mirror version of the Unmarshal method to turn a struct into a resource.PropertyMap.

As an optional extension, this would be great if it supported setting secrets and unknowns in a way that is also returned by the Unmarshal method e.g.

resourcex.Marshal(typedInputs,
  marshalOption.WithSecrets("prop.subProp"),
  marshalOption.WithSecretPaths(resource.PropertyPath{"prop", 0, "subProp"}),
  marshalOption.WithUnknown("prop.propWithoutValue"))
@iwahbe
Copy link
Member

iwahbe commented Mar 25, 2024

This essentially already exists, it's just not exposed.

The Unmarshal function is:

// Decode a property map to a `pulumi:"x"` annotated struct.
//
// The returned mapper can restore the metadata it removed when translating `dst` back to
// a property map. If the shape of `T` matches `m`, then this will be a no-op:
//
// var value T
// encoder, _ := Decode(m, &value)
// m, _ = encoder.Encode(value)
func Decode[T any](m resource.PropertyMap, dst T) (Encoder, mapper.MappingError) {
return decode(m, dst, false, false)
}

The resulting encoder does lossless marshaling with all marshalOptions applied:

func (e *ende) Encode(src any) (resource.PropertyMap, mapper.MappingError) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request kind/enhancement Improvements or new features
Projects
None yet
Development

No branches or pull requests

2 participants