Skip to content

Commit a9d8c0f

Browse files
committed
Always insert actions from schema during partial entities construction
Signed-off-by: Shaobo He <[email protected]>
1 parent 1b3275b commit a9d8c0f

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

cedar-policy-core/src/tpe/entities.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ impl PartialEntities {
528528
validate_ancestors(&entities)?;
529529
let mut entities = Self { entities };
530530
entities.compute_tc()?;
531+
entities.insert_actions(schema);
531532
Ok(entities)
532533
}
533534

@@ -590,6 +591,20 @@ impl PartialEntities {
590591
}
591592
}
592593

594+
// Insert action entities from the schema
595+
// Overwriting existing action entities is fine because they should come
596+
// from schema or be consistent with schema anyways
597+
fn insert_actions(&mut self, schema: &ValidatorSchema) {
598+
for (uid, action) in &schema.actions {
599+
self.entities.insert(
600+
uid.clone(),
601+
// PANIC SAFETY: action entities do not contain unknowns
602+
#[allow(clippy::unwrap_used)]
603+
action.as_ref().clone().try_into().unwrap(),
604+
);
605+
}
606+
}
607+
593608
/// Construct [`PartialEntities`] from a JSON list
594609
pub fn from_json_value(
595610
value: serde_json::Value,
@@ -609,17 +624,7 @@ impl PartialEntities {
609624
partial_entities.compute_tc()?;
610625

611626
// Insert actions from the schema
612-
for (uid, action) in &schema.actions {
613-
partial_entities.entities.insert(
614-
uid.clone(),
615-
PartialEntity {
616-
uid: uid.clone(),
617-
attrs: Some(BTreeMap::default()),
618-
ancestors: Some(action.ancestors().cloned().collect()),
619-
tags: Some(BTreeMap::default()),
620-
},
621-
);
622-
}
627+
partial_entities.insert_actions(schema);
623628
Ok(partial_entities)
624629
}
625630

0 commit comments

Comments
 (0)