Struct cedar_policy::Schema
source · pub struct Schema(/* private fields */);
Expand description
Object containing schema information used by the validator.
Implementations§
source§impl Schema
impl Schema
sourcepub fn from_schema_fragments(
fragments: impl IntoIterator<Item = SchemaFragment>,
) -> Result<Self, SchemaError>
pub fn from_schema_fragments( fragments: impl IntoIterator<Item = SchemaFragment>, ) -> Result<Self, SchemaError>
Create a Schema
from multiple SchemaFragment
. The individual
fragments may references entity types that are not declared in that
fragment, but all referenced entity types must be declared in some
fragment.
sourcepub fn from_json_value(json: Value) -> Result<Self, SchemaError>
pub fn from_json_value(json: Value) -> Result<Self, SchemaError>
Create a Schema
from a JSON value (which should be an object of the
shape required for Cedar schemas).
sourcepub fn from_file(file: impl Read) -> Result<Self, SchemaError>
👎Deprecated since 3.3.0: Use from_json_file()
instead
pub fn from_file(file: impl Read) -> Result<Self, SchemaError>
from_json_file()
insteadCreate a Schema
directly from a file.
sourcepub fn from_json_file(file: impl Read) -> Result<Self, SchemaError>
pub fn from_json_file(file: impl Read) -> Result<Self, SchemaError>
Create a Schema
directly from a file.
sourcepub fn from_file_natural(
file: impl Read,
) -> Result<(Self, impl Iterator<Item = SchemaWarning>), HumanSchemaError>
👎Deprecated since 3.3.0: Use from_cedarschema_file()
instead
pub fn from_file_natural( file: impl Read, ) -> Result<(Self, impl Iterator<Item = SchemaWarning>), HumanSchemaError>
from_cedarschema_file()
insteadParse the schema from a reader
sourcepub fn from_cedarschema_file(
file: impl Read,
) -> Result<(Self, impl Iterator<Item = SchemaWarning>), HumanSchemaError>
pub fn from_cedarschema_file( file: impl Read, ) -> Result<(Self, impl Iterator<Item = SchemaWarning>), HumanSchemaError>
Parse the schema from a reader
sourcepub fn from_str_natural(
src: &str,
) -> Result<(Self, impl Iterator<Item = SchemaWarning>), HumanSchemaError>
👎Deprecated since 3.3.0: Use from_cedarschema_str()
instead
pub fn from_str_natural( src: &str, ) -> Result<(Self, impl Iterator<Item = SchemaWarning>), HumanSchemaError>
from_cedarschema_str()
insteadParse the schema from a string
sourcepub fn from_cedarschema_str(
src: &str,
) -> Result<(Self, impl Iterator<Item = SchemaWarning>), HumanSchemaError>
pub fn from_cedarschema_str( src: &str, ) -> Result<(Self, impl Iterator<Item = SchemaWarning>), HumanSchemaError>
Parse the schema from a string
sourcepub fn action_entities(&self) -> Result<Entities, EntitiesError>
pub fn action_entities(&self) -> Result<Entities, EntitiesError>
Extract from the schema an Entities
containing the action entities
declared in the schema.
sourcepub fn principals(&self) -> impl Iterator<Item = &EntityTypeName>
pub fn principals(&self) -> impl Iterator<Item = &EntityTypeName>
Returns an iterator over every entity type that can be a principal for any action in this schema
Note: this iterator may contain duplicates.
§Examples
Here’s an example of using a std::collections::HashSet
to get a de-duplicated set of principals
use std::collections::HashSet;
use cedar_policy::Schema;
let schema : Schema = Schema::from_cedarschema_str(r#"
entity User;
entity Folder;
action Access appliesTo {
principal : User,
resource : Folder,
};
action Delete appliesTo {
principal : User,
resource : Folder,
};
"#).unwrap().0;
let principals = schema.principals().collect::<HashSet<_>>();
assert_eq!(principals, HashSet::from([&"User".parse().unwrap()]));
sourcepub fn resources(&self) -> impl Iterator<Item = &EntityTypeName>
pub fn resources(&self) -> impl Iterator<Item = &EntityTypeName>
Returns an iterator over every entity type that can be a resource for any action in this schema
Note: this iterator may contain duplicates.
§Examples
Here’s an example of using a std::collections::HashSet
to get a de-duplicated set of resources
use std::collections::HashSet;
use cedar_policy::Schema;
let schema : Schema = Schema::from_cedarschema_str(r#"
entity User;
entity Folder;
action Access appliesTo {
principal : User,
resource : Folder,
};
action Delete appliesTo {
principal : User,
resource : Folder,
};
"#).unwrap().0;
let resources = schema.resources().collect::<HashSet<_>>();
assert_eq!(resources, HashSet::from([&"Folder".parse().unwrap()]));
sourcepub fn principals_for_action(
&self,
action: &EntityUid,
) -> Option<impl Iterator<Item = &EntityTypeName>>
pub fn principals_for_action( &self, action: &EntityUid, ) -> Option<impl Iterator<Item = &EntityTypeName>>
sourcepub fn resources_for_action(
&self,
action: &EntityUid,
) -> Option<impl Iterator<Item = &EntityTypeName>>
pub fn resources_for_action( &self, action: &EntityUid, ) -> Option<impl Iterator<Item = &EntityTypeName>>
sourcepub fn ancestors<'a>(
&'a self,
ty: &'a EntityTypeName,
) -> Option<impl Iterator<Item = &EntityTypeName> + 'a>
pub fn ancestors<'a>( &'a self, ty: &'a EntityTypeName, ) -> Option<impl Iterator<Item = &EntityTypeName> + 'a>
sourcepub fn action_groups(&self) -> impl Iterator<Item = &EntityUid>
pub fn action_groups(&self) -> impl Iterator<Item = &EntityUid>
Returns an iterator over all the action groups defined in this schema
sourcepub fn entity_types(&self) -> impl Iterator<Item = &EntityTypeName>
pub fn entity_types(&self) -> impl Iterator<Item = &EntityTypeName>
Returns an iterator over all entity types defined in this schema
Trait Implementations§
source§impl FromStr for Schema
impl FromStr for Schema
source§fn from_str(schema_src: &str) -> Result<Self, Self::Err>
fn from_str(schema_src: &str) -> Result<Self, Self::Err>
Construct a schema from a string containing a schema formatted in the Cedar schema format. This can fail if it is not possible to parse a schema from the strings, or if errors in values in the schema are uncovered after parsing. For instance, when an entity attribute name is found to not be a valid attribute name according to the Cedar grammar.
§type Err = SchemaError
type Err = SchemaError
source§impl TryInto<Schema> for SchemaFragment
impl TryInto<Schema> for SchemaFragment
source§fn try_into(self) -> Result<Schema, Self::Error>
fn try_into(self) -> Result<Schema, Self::Error>
Convert SchemaFragment
into a Schema
. To build the Schema
we
need to have all entity types defined, so an error will be returned if
any undeclared entity types are referenced in the schema fragment.
§type Error = SchemaError
type Error = SchemaError
Auto Trait Implementations§
impl Freeze for Schema
impl RefUnwindSafe for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnwindSafe for Schema
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more