Skip to content

Commit

Permalink
updates for cedar#1027 (#376) (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
khieta authored Aug 9, 2024
1 parent b983bbc commit 1f6c899
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
28 changes: 13 additions & 15 deletions cedar-drt/fuzz/src/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ pub fn dump(
resource: dump_request_var(q.resource()),
context: dump_context(
q.context()
.expect("`dump` does not support requests missing context"),
.expect("`dump` does not support requests missing context")
.clone(),
),
enable_request_validation: true,
decision: a.decision,
Expand Down Expand Up @@ -230,22 +231,19 @@ fn dump_request_var(var: &EntityUIDEntry) -> Option<JsonValueWithNoDuplicateKeys
}

/// Dump the context to a "natural" json value
fn dump_context(context: &Context) -> JsonValueWithNoDuplicateKeys {
fn dump_context(context: Context) -> JsonValueWithNoDuplicateKeys {
let context = context
.iter()
.map(|it| {
it.map(|(k, pval)| {
(
k.clone(),
RestrictedExpr::try_from(pval)
.unwrap()
.to_natural_json()
.unwrap(),
)
})
.collect::<HashMap<_, _>>()
.into_iter()
.map(|(k, pval)| {
(
k,
RestrictedExpr::try_from(pval)
.unwrap()
.to_natural_json()
.unwrap(),
)
})
.unwrap_or_default();
.collect::<HashMap<_, _>>();
serde_json::to_value(context)
.expect("failed to serialize context")
.into()
Expand Down
2 changes: 1 addition & 1 deletion cedar-policy-generators/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl std::fmt::Display for Request {
"(principal : {}, action: {}, resource: {})",
self.principal, self.action, self.resource
)?;
let mut context = self.context.iter().unwrap().peekable();
let mut context = self.context.clone().into_iter().peekable();
if context.peek().is_some() {
writeln!(f, "\nWith context: {{")?;
for (attr, val) in context {
Expand Down

0 comments on commit 1f6c899

Please sign in to comment.