agentguard_core/authorize/
entities.rs

1//! Build `cedar_policy::Entities` from JSON values.
2
3use crate::error::Result;
4use cedar_policy::{Entities, Entity};
5
6/// Build `Entities` from a list of entity JSON objects.
7pub fn build_entities(items: Vec<serde_json::Value>) -> Result<Entities> {
8    let mut ents: Vec<Entity> = Vec::with_capacity(items.len());
9    for v in items {
10        let s = serde_json::to_string(&v)?;
11        let e = Entity::from_json_str(&s, None)
12            .map_err(|e| crate::error::Error::Entities(e.to_string()))?;
13        ents.push(e);
14    }
15    Entities::from_entities(ents, None).map_err(|e| crate::error::Error::Entities(e.to_string()))
16}