From 1f6c899b6b6c4fd38334de7861a358eb1587af39 Mon Sep 17 00:00:00 2001 From: Kesha Hietala Date: Fri, 9 Aug 2024 15:57:09 -0400 Subject: [PATCH] updates for cedar#1027 (#376) (#415) --- cedar-drt/fuzz/src/dump.rs | 28 ++++++++++++-------------- cedar-policy-generators/src/request.rs | 2 +- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/cedar-drt/fuzz/src/dump.rs b/cedar-drt/fuzz/src/dump.rs index f9f80b078..f0b1cb73d 100644 --- a/cedar-drt/fuzz/src/dump.rs +++ b/cedar-drt/fuzz/src/dump.rs @@ -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, @@ -230,22 +231,19 @@ fn dump_request_var(var: &EntityUIDEntry) -> Option 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::>() + .into_iter() + .map(|(k, pval)| { + ( + k, + RestrictedExpr::try_from(pval) + .unwrap() + .to_natural_json() + .unwrap(), + ) }) - .unwrap_or_default(); + .collect::>(); serde_json::to_value(context) .expect("failed to serialize context") .into() diff --git a/cedar-policy-generators/src/request.rs b/cedar-policy-generators/src/request.rs index 5f1df3334..540679755 100644 --- a/cedar-policy-generators/src/request.rs +++ b/cedar-policy-generators/src/request.rs @@ -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 {