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

Cleanup in frontend code #740

Merged
merged 7 commits into from
Mar 25, 2024
Merged

Cleanup in frontend code #740

merged 7 commits into from
Mar 25, 2024

Conversation

khieta
Copy link
Contributor

@khieta khieta commented Mar 20, 2024

Description of changes

This PR fixes a few inconsistencies in our frontend, which will become visible once we make these structures public in #737. I believe that all of these changes are non-breaking because they affect private data structures... but please double check my work.

  • ValidateCall -> ValidationCall for consistency with AuthorizationCall
  • ValidateAnswer -> ValidationAnswer for consistency with AuthorizationAnswer
  • ParseFailed -> Failure since failures encompass more than just parsing (e.g., failure to convert a Schema to the internal ValidatorSchema type)
  • "notes" -> "validation errors"
  • Added support for returning validation warnings
  • Updated validate to call the public function in cedar_policy instead of the internal one in cedar_policy_validator
  • ValidationMode -> ValidationEnabled since "mode" usually refers to "strict" vs. "permissive"
  • Updated the schema field in ValidationCall to be a JsonValueWithNoDuplicateKeys for consistency with AuthorizationCall

A few other things I'd like to change, but didn't because they will be breaking (will make in a followup PR):

  • Rename InterfaceResponse, InterfaceDiagnostics to Response, Diagnostics. We are already redefining types (e.g., ValidationError) so I don't think this is too confusing.
  • Get rid of InterfaceResult and instead use the Failure field of AuthorizationAnswer, ValidationAnswer to report errors. I don't think it's worth the extra infrastructure to distinguish between internal and non-internal errors.
  • Rename json_is_authorized to json_str_is_authorized & update it to return a json string encoding of a AuthorizationAnswer. Similar for json_validate.

Issue #, if available

Checklist for requesting a review

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

  • A change "invisible" to users (e.g., documentation, changes to "internal" crates like cedar-policy-core, cedar-validator, etc.)

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

  • Does not update the CHANGELOG because my change does not significantly impact released code.

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.

@khieta khieta requested review from andrewmwells-amazon and removed request for cdisselkoen March 20, 2024 18:34
@khieta khieta marked this pull request as ready for review March 20, 2024 18:36
Comment on lines -560 to -561
let policy_set = match policies {
PolicySpecification::Concatenated(policies) => match PolicySet::from_str(&policies) {
Copy link
Contributor Author

@khieta khieta Mar 20, 2024

Choose a reason for hiding this comment

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

Fyi (to help processing the diff): This parsing code, and the parse_policy_set_from_individual_policies function below were copied verbatim to util.rs.

@andrewmwells-amazon
Copy link
Contributor

If you rebase, the downstream build should hopefully pass now

khieta and others added 5 commits March 21, 2024 10:55
Signed-off-by: Kesha Hietala <khieta@amazon.com>
Signed-off-by: Kesha Hietala <khieta@amazon.com>
Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
Signed-off-by: Kesha Hietala <khieta@amazon.com>
Signed-off-by: Andrew Wells <anmwells@amazon.com>
Signed-off-by: Kesha Hietala <khieta@amazon.com>
Signed-off-by: Kesha Hietala <khieta@amazon.com>
#[serde(default)]
#[serde(rename = "validationSettings")]
validation_settings: ValidationSettings,
schema: cedar_policy_validator::SchemaFragment,
/// Schema in JSON format
schema: JsonValueWithNoDuplicateKeys,
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the benefit of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consistency with AuthorizationCall

#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi, from_wasm_abi))]
struct ValidateCall {
Copy link
Contributor

Choose a reason for hiding this comment

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

The Validate to Validation change looks nice, but I wonder if it's worth making a breaking change to the API. Depends on how much we care about keeping this interface stable.

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 isn't breaking since the ValidateCall type was only ever exposed indirectly via its serialized JSON format.

Signed-off-by: Kesha Hietala <khieta@amazon.com>
@khieta khieta merged commit cecb2c3 into main Mar 25, 2024
12 of 14 checks passed
@khieta khieta deleted the khieta/cleanup branch March 25, 2024 15:04
@khieta khieta added the breaking-change This is (likely) a breaking change label Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change This is (likely) a breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants