Struct cedar_policy_core::entities::EntityJsonParser
source · pub struct EntityJsonParser<'e, 's, S: Schema = NoEntitiesSchema> { /* private fields */ }
Expand description
Struct used to parse entities from JSON.
Implementations§
source§impl<'e, 's, S: Schema> EntityJsonParser<'e, 's, S>
impl<'e, 's, S: Schema> EntityJsonParser<'e, 's, S>
sourcepub fn new(
schema: Option<&'s S>,
extensions: Extensions<'e>,
tc_computation: TCComputation
) -> Self
pub fn new( schema: Option<&'s S>, extensions: Extensions<'e>, tc_computation: TCComputation ) -> Self
Create a new EntityJsonParser
.
schema
represents a source of Action
entities, which will be added
to the entities parsed from JSON.
(If any Action
entities are present in the JSON, and a schema
is
also provided, each Action
entity in the JSON must exactly match its
definition in the schema or an error is returned.)
If a schema
is present, this will also inform the parsing: for
instance, it will allow __entity
and __extn
escapes to be implicit.
Finally, if a schema
is present, the EntityJsonParser
will ensure
that the produced entities fully conform to the schema
– for
instance, it will error if attributes have the wrong types (e.g., string
instead of integer), or if required attributes are missing or
superfluous attributes are provided.
If you pass TCComputation::AssumeAlreadyComputed
, then the caller is
responsible for ensuring that TC holds before calling this method.
sourcepub fn from_json_str(&self, json: &str) -> Result<Entities, EntitiesError>
pub fn from_json_str(&self, json: &str) -> Result<Entities, EntitiesError>
sourcepub fn from_json_value(&self, json: Value) -> Result<Entities, EntitiesError>
pub fn from_json_value(&self, json: Value) -> Result<Entities, EntitiesError>
Parse an entities JSON file (in serde_json::Value
form) into an Entities
object.
If the EntityJsonParser
has a schema
, this also adds Action
entities declared in the schema
.
sourcepub fn from_json_file(&self, json: impl Read) -> Result<Entities, EntitiesError>
pub fn from_json_file(&self, json: impl Read) -> Result<Entities, EntitiesError>
Parse an entities JSON file (in std::io::Read
form) into an Entities
object.
If the EntityJsonParser
has a schema
, this also adds Action
entities declared in the schema
.
sourcepub fn iter_from_json_str(
&self,
json: &str
) -> Result<impl Iterator<Item = Entity> + '_, EntitiesError>
pub fn iter_from_json_str( &self, json: &str ) -> Result<impl Iterator<Item = Entity> + '_, EntitiesError>
sourcepub fn iter_from_json_value(
&self,
json: Value
) -> Result<impl Iterator<Item = Entity> + '_, EntitiesError>
pub fn iter_from_json_value( &self, json: Value ) -> Result<impl Iterator<Item = Entity> + '_, EntitiesError>
Parse an entities JSON file (in serde_json::Value
form) into an iterator over Entity
s.
If the EntityJsonParser
has a schema
, this also adds Action
entities declared in the schema
.
sourcepub fn iter_from_json_file(
&self,
json: impl Read
) -> Result<impl Iterator<Item = Entity> + '_, EntitiesError>
pub fn iter_from_json_file( &self, json: impl Read ) -> Result<impl Iterator<Item = Entity> + '_, EntitiesError>
Parse an entities JSON file (in std::io::Read
form) into an iterator over Entity
s.
If the EntityJsonParser
has a schema
, this also adds Action
entities declared in the schema
.