-
Notifications
You must be signed in to change notification settings - Fork 85
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
Adds JSON serialized PolicySet from bindings to cedar_policy::PolicySet conversion #1437
Conversation
Signed-off-by: Mudit Chaudhary <[email protected]>
Signed-off-by: Mudit Chaudhary <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you say a little bit more about why this function is required? As opposed to just using serde
to deserialize the string into a struct that includes PolicySet
as a field, and then using .parse()
on that PolicySet
/// Convert `cedar_policy::ffi::PolicySet` JSON to `cedar_policy::PolicySet` Object | ||
pub fn json_to_policyset( | ||
json_string: &str, | ||
) -> Result<crate::PolicySet, Box<dyn std::error::Error>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning Box<dyn Error>
instead of DetailedError
or something that impl
s miette::Diagnostic
diverges from what a lot of the rest of the FFI functions do, and loses structured error information. Is there a reason this API should have less structured error information (e.g., no help text, no source location) than other APIs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change this to match other FFI functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you say a little bit more about why this function is required? As opposed to just using
serde
to deserialize the string into a struct that includesPolicySet
as a field, and then using.parse()
on thatPolicySet
.parse
for PolicySet
has visibility pub (super)
so it is not visible to CedarJavaFFI
. If changing its visibility to public is acceptable, I can use that instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think changing the visibility is preferable to introducing a new function in this case.
@@ -225,6 +225,23 @@ pub enum SchemaToJsonAnswer { | |||
}, | |||
} | |||
|
|||
/// Convert `cedar_policy::ffi::PolicySet` JSON to `cedar_policy::PolicySet` Object | |||
pub fn json_to_policyset( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elsewhere (e.g., in ffi/is_authorized.rs
), function names with just json
take a serde_json::Value
, while functions like this that take a string have names with json_str
Signed-off-by: Mudit Chaudhary <[email protected]>
Signed-off-by: Mudit Chaudhary <[email protected]>
Description of changes
PolicySet
object from bindings (E.g., CedarJava) to acedar_policy::PolicySet
instancecedar_policy::PolicySet
's methods (E.g., to_json) in bindingsIssue #, if available
Checklist for requesting a review
The change in this PR is (choose one, and delete the other options):
cedar-policy
(e.g., changes to the signature of an existing API).cedar-policy
(e.g., addition of a new API).cedar-policy
.cedar-policy-core
,cedar-validator
, etc.)I confirm that this PR (choose one, and delete the other options):
I confirm that
cedar-spec
(choose one, and delete the other options):cedar-spec
, and how you have tested that your updates are correct.)cedar-spec
. (Post your PR anyways, and we'll discuss in the comments.)I confirm that
docs.cedarpolicy.com
(choose one, and delete the other options):cedar-docs
. PRs should be targeted at astaging-X.Y
branch, notmain
.)