Skip to content

Commit

Permalink
Fixups
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Eline <aeline+github@amazon.com>
  • Loading branch information
aaronjeline committed Jun 14, 2024
1 parent 202aaaa commit 029038f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cedar-policy-core/src/ast/restricted_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ pub enum RestrictedExpressionError {
InvalidRestrictedExpression(#[from] restricted_expr_errors::InvalidRestrictedExpressionError),
}

/// Error subtypes for [`RestrictedExprError`]
/// Error subtypes for [`RestrictedExpressionError`]
pub mod restricted_expr_errors {
use super::Expr;
use miette::Diagnostic;
Expand Down
36 changes: 23 additions & 13 deletions cedar-policy/src/ffi/is_authorized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,27 +612,37 @@ impl AuthorizationCall {
None
}
};
let context = parse_context(self.context, schema.as_ref(), action.as_ref(), &mut errs);

let mut b = Request::builder();

/// For P/A/R:
/// Only attempt to parse principal if it's present.
/// If it's missing, it's an unknown and not an error.
// For P/A/R:
// Only attempt to parse principal if it's present.
// If it's missing, it's an unknown and not an error.
if let Some(principal_json) = self.principal {
b = b.principal(parse_entity_uid(
Some(principal_json),
"principal",
&mut errs,
));
if let Some(principal) = parse_entity_uid(Some(principal_json), "principal", &mut errs)
{
b = b.principal(principal);
}
}

if let Some(action_json) = self.action {
b = b.action(parse_entity_uid(Some(action_json), "action", &mut errs));
}
// If the action exists, use it to parse context, otherwise don't
let context = match self.action {
Some(action_json) => {
let action = parse_entity_uid(Some(action_json), "action", &mut errs);
let context =
parse_context(self.context, schema.as_ref(), action.as_ref(), &mut errs);
if let Some(action) = action {
b = b.action(action);
}
context
}
None => parse_context(self.context, schema.as_ref(), None, &mut errs),
};

if let Some(resource_json) = self.resource {
b = b.resource(parse_entity_uid(Some(resource_json), "resource", &mut errs));
if let Some(resource) = parse_entity_uid(Some(resource_json), "resource", &mut errs) {
b = b.resource(resource);
}
}

b = b.context(context);
Expand Down

0 comments on commit 029038f

Please sign in to comment.