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

Adding read/write json methods to entity #924

Conversation

aaronjeline
Copy link
Contributor

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.

Signed-off-by: Aaron Eline <aeline+github@amazon.com>
@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
Contributor 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
Contributor 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
cedar-policy/src/api.rs Outdated Show resolved Hide resolved
cedar-policy/src/api.rs Show resolved Hide resolved
Signed-off-by: Aaron Eline <aeline+github@amazon.com>

Co-authored-by: John Kastner <130772734+john-h-kastner-aws@users.noreply.github.com>
Signed-off-by: Aaron Eline <aeline+github@amazon.com>
@@ -263,6 +263,8 @@ impl Entity {
}

/// 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
Contributor 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

Signed-off-by: Aaron Eline <aeline+github@amazon.com>
Signed-off-by: Aaron Eline <aeline+github@amazon.com>
@aaronjeline aaronjeline merged commit a57c28d into main May 30, 2024
15 of 17 checks passed
@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 <aeline+github@amazon.com>
Co-authored-by: John Kastner <130772734+john-h-kastner-aws@users.noreply.github.com>
@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