Skip to content

Conversation

aaronjeline
Copy link

Description of changes

Adds methods for reading and writing individual Entity objects as JSON

Issue #, if available

#807

Checklist for requesting a review

The change in this PR is (choose one, and delete the other options):

  • A backwards-compatible change requiring a minor version bump to cedar-policy (e.g., addition of a new API).

I confirm that this PR (choose one, and delete the other options):

  • Updates the "Unreleased" section of the CHANGELOG with a description of my change (required for major/minor version bumps).

I confirm that cedar-spec (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar formal model or DRT infrastructure.

@aaronjeline aaronjeline linked an issue May 29, 2024 that may be closed by this pull request
2 tasks
schema,
self.extensions,
);
checker.validate_entity(&entity)?;
Copy link
Author

Choose a reason for hiding this comment

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

I think this API is a potential footgun, wonder if it can be reworked

Copy link
Contributor

Choose a reason for hiding this comment

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

validate_entity()?

Copy link
Author

Choose a reason for hiding this comment

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

Yes. It seems easy to forget to call that, or have a flow through a function that doesn't call it. Violates the parse-don't-validate guideline

Copy link
Contributor

Choose a reason for hiding this comment

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

That suggests an alternate API would have a different type for validated and not-yet-validated entities. The validated one would get the Entity name I presume.

@aaronjeline aaronjeline marked this pull request as ready for review May 29, 2024 16:43
Signed-off-by: Aaron Eline <[email protected]>

Co-authored-by: John Kastner <[email protected]>
Signed-off-by: Aaron Eline <[email protected]>

/// Parse an entity from an in-memory JSON value
/// If a schema is provided, it is handled identically to
/// [Entities](https://docs.rs/cedar-policy/latest/cedar_policy/struct.Entities.html#method.from_json_str)
Copy link
Contributor

@john-h-kastner-aws john-h-kastner-aws May 29, 2024

Choose a reason for hiding this comment

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

Why not just the auto doc link?

Copy link
Author

Choose a reason for hiding this comment

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

How do you auto-doc link to a specific method?

Copy link
Contributor

Choose a reason for hiding this comment

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

[Entities::from_json_str] i think

Aaron Eline added 2 commits May 30, 2024 10:25
Signed-off-by: Aaron Eline <[email protected]>
Signed-off-by: Aaron Eline <[email protected]>
@aaronjeline aaronjeline merged commit a57c28d into main May 30, 2024
@aaronjeline aaronjeline deleted the 807-wish-to-have-more-json-parsing-support-for-entities-or-entity-data-type branch May 30, 2024 15:33
khieta pushed a commit that referenced this pull request Aug 8, 2024
Signed-off-by: Aaron Eline <[email protected]>
Co-authored-by: John Kastner <[email protected]>
@khieta khieta mentioned this pull request Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wish to have more JSON parsing support for Entities or Entity data type
4 participants