pub struct ValidatorSchema { /* private fields */ }Expand description
Internal representation of the schema for use by the validator.
In this representation, all common types are fully expanded, and all entity type names are fully disambiguated (fully qualified).
Implementations§
Source§impl ValidatorSchema
impl ValidatorSchema
Sourcepub fn to_json_schema(&self) -> Result<Fragment<RawName>, String>
pub fn to_json_schema(&self) -> Result<Fragment<RawName>, String>
Converts a ValidatorSchema into a json_schema::Fragment.
Roundtripping through this function gives a semantically equivalent
schema but will lose formatting, annotations, and common type
definitions. It will also inline the transitive closure of the entity
hierarchy for each entity type and action.
Sourcepub fn to_cedar_schema(&self) -> Result<String, String>
pub fn to_cedar_schema(&self) -> Result<String, String>
Converts a ValidatorSchema into a Cedar schema string.
This first converts to JSON schema format and then to Cedar syntax.
Source§impl ValidatorSchema
impl ValidatorSchema
Sourcepub fn new(
entity_types: impl IntoIterator<Item = ValidatorEntityType>,
action_ids: impl IntoIterator<Item = ValidatorActionId>,
) -> Self
pub fn new( entity_types: impl IntoIterator<Item = ValidatorEntityType>, action_ids: impl IntoIterator<Item = ValidatorActionId>, ) -> Self
Construct a new ValidatorSchema from a set of ValidatorEntityTypes and ValidatorActionIds.
The caller must ensure that there are no duplicate entity type names or action names in the input. Duplicates are silently collapsed (last entry wins).
Sourcepub fn common_types(&self) -> impl Iterator<Item = &LocatedCommonType>
Available on crate feature extended-schema only.
pub fn common_types(&self) -> impl Iterator<Item = &LocatedCommonType>
extended-schema only.Returns an iter of common types in the schema
Sourcepub fn namespaces(&self) -> impl Iterator<Item = &LocatedNamespace>
Available on crate feature extended-schema only.
pub fn namespaces(&self) -> impl Iterator<Item = &LocatedNamespace>
extended-schema only.Returns an iter of validator namespaces in the schema
Sourcepub fn principals(&self) -> impl Iterator<Item = &EntityType>
pub fn principals(&self) -> impl Iterator<Item = &EntityType>
Returns an iterator over every entity type that can be a principal for any action in this schema
Sourcepub fn resources(&self) -> impl Iterator<Item = &EntityType>
pub fn resources(&self) -> impl Iterator<Item = &EntityType>
Returns an iterator over every entity type that can be a resource for any action in this schema
Sourcepub fn principals_for_action(
&self,
action: &EntityUID,
) -> Option<impl Iterator<Item = &EntityType>>
pub fn principals_for_action( &self, action: &EntityUID, ) -> Option<impl Iterator<Item = &EntityType>>
Sourcepub fn resources_for_action(
&self,
action: &EntityUID,
) -> Option<impl Iterator<Item = &EntityType>>
pub fn resources_for_action( &self, action: &EntityUID, ) -> Option<impl Iterator<Item = &EntityType>>
Sourcepub fn actions_for_principal_and_resource<'a: 'b, 'b>(
&'a self,
principal_type: &'b EntityType,
resource_type: &'b EntityType,
) -> impl Iterator<Item = &'a EntityUID> + 'b
pub fn actions_for_principal_and_resource<'a: 'b, 'b>( &'a self, principal_type: &'b EntityType, resource_type: &'b EntityType, ) -> impl Iterator<Item = &'a EntityUID> + 'b
Returns an iterator over the actions that apply to this principal and
resource type, as specified by the appliesTo block for the action in
this schema.
Sourcepub fn unlinked_request_envs(
&self,
mode: ValidationMode,
) -> impl Iterator<Item = RequestEnv<'_>> + '_
pub fn unlinked_request_envs( &self, mode: ValidationMode, ) -> impl Iterator<Item = RequestEnv<'_>> + '_
Returns an iterator over every valid RequestEnv in the schema
Sourcepub fn ancestors<'a>(
&'a self,
ty: &'a EntityType,
) -> Option<impl Iterator<Item = &'a EntityType> + 'a>
pub fn ancestors<'a>( &'a self, ty: &'a EntityType, ) -> Option<impl Iterator<Item = &'a EntityType> + '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 actions(&self) -> impl Iterator<Item = &EntityUID>
pub fn actions(&self) -> impl Iterator<Item = &EntityUID>
Returns an iterator over all actions defined in this schema
Sourcepub fn empty() -> ValidatorSchema
pub fn empty() -> ValidatorSchema
Create a ValidatorSchema without any definitions (of entity types,
common types, or actions).
Sourcepub fn from_json_value(json: Value, extensions: &Extensions<'_>) -> Result<Self>
pub fn from_json_value(json: Value, extensions: &Extensions<'_>) -> Result<Self>
Construct a ValidatorSchema from a JSON value in the appropriate
shape.
Sourcepub fn from_json_str(json: &str, extensions: &Extensions<'_>) -> Result<Self>
pub fn from_json_str(json: &str, extensions: &Extensions<'_>) -> Result<Self>
Construct a ValidatorSchema from a string containing JSON in the
appropriate shape.
Sourcepub fn from_json_file(
file: impl Read,
extensions: &Extensions<'_>,
) -> Result<Self>
pub fn from_json_file( file: impl Read, extensions: &Extensions<'_>, ) -> Result<Self>
Construct a ValidatorSchema directly from a file containing JSON
in the appropriate shape.
Sourcepub fn from_cedarschema_file<'a>(
r: impl Read,
extensions: &'a Extensions<'a>,
) -> Result<(Self, impl Iterator<Item = SchemaWarning> + 'a), CedarSchemaError>
pub fn from_cedarschema_file<'a>( r: impl Read, extensions: &'a Extensions<'a>, ) -> Result<(Self, impl Iterator<Item = SchemaWarning> + 'a), CedarSchemaError>
Construct a ValidatorSchema directly from a file containing the
Cedar schema syntax.
Sourcepub fn from_cedarschema_str<'a>(
src: &str,
extensions: &Extensions<'a>,
) -> Result<(Self, impl Iterator<Item = SchemaWarning> + 'a), CedarSchemaError>
pub fn from_cedarschema_str<'a>( src: &str, extensions: &Extensions<'a>, ) -> Result<(Self, impl Iterator<Item = SchemaWarning> + 'a), CedarSchemaError>
Construct a ValidatorSchema from a string containing the Cedar
schema syntax.
Sourcepub fn from_schema_fragments(
fragments: impl IntoIterator<Item = ValidatorSchemaFragment<ConditionalName, ConditionalName>>,
extensions: &Extensions<'_>,
) -> Result<ValidatorSchema>
pub fn from_schema_fragments( fragments: impl IntoIterator<Item = ValidatorSchemaFragment<ConditionalName, ConditionalName>>, extensions: &Extensions<'_>, ) -> Result<ValidatorSchema>
Construct a ValidatorSchema from some number of ValidatorSchemaFragments.
Sourcepub fn get_action_id(&self, action_id: &EntityUID) -> Option<&ValidatorActionId>
pub fn get_action_id(&self, action_id: &EntityUID) -> Option<&ValidatorActionId>
Lookup the ValidatorActionId object in the schema with the given name.
Sourcepub fn get_entity_type<'a>(
&'a self,
entity_type_id: &EntityType,
) -> Option<&'a ValidatorEntityType>
pub fn get_entity_type<'a>( &'a self, entity_type_id: &EntityType, ) -> Option<&'a ValidatorEntityType>
Lookup the ValidatorEntityType object in the schema with the given name.
Sourcepub fn action_ids(&self) -> impl Iterator<Item = &ValidatorActionId>
pub fn action_ids(&self) -> impl Iterator<Item = &ValidatorActionId>
An iterator over the ValidatorActionIds in the schema.
Sourcepub fn entity_type_names(&self) -> impl Iterator<Item = &EntityType>
pub fn entity_type_names(&self) -> impl Iterator<Item = &EntityType>
An iterator over the entity type names in the schema.
Sourcepub fn entity_types(&self) -> impl Iterator<Item = &ValidatorEntityType>
pub fn entity_types(&self) -> impl Iterator<Item = &ValidatorEntityType>
An iterator over the ValidatorEntityTypes in the schema.
Sourcepub fn context_type(&self, action: &EntityUID) -> Option<&Type>
pub fn context_type(&self, action: &EntityUID) -> Option<&Type>
Get the Type of context expected for the given action.
This always returns a closed record type.
Returns None if the action is not in the schema.
Sourcepub fn action_entities(&self) -> Result<Entities, EntitiesError>
pub fn action_entities(&self) -> Result<Entities, EntitiesError>
Construct an Entity object for each action in the schema
Sourcepub fn try_validate(self) -> Result<Self, SchemaError>
pub fn try_validate(self) -> Result<Self, SchemaError>
Validate that a schema is well-formed according to the rules of the schema language. This is useful when the schema has been constructed directly from Rust code, without going through the JSON or Cedar schema syntax, and thus may not have been checked for well-formedness by the JSON or Cedar schema parsers.
More specifically, this checks the following:
- all entity types referenced are declared,
- all extension types in the schema are known extensions,
entity_typesdoes not declare actions andaction_idsdeclares only actions,- enum entities do not appear as descendants,
- RFC 70 shadowing rules are satisfied. Additionally, this recomputes the transitive closure computation for entity types and actions.
This does NOT check the following, which must be ensured before construction:
- duplicate entity type or action declarations (duplicates are silently collapsed
by
ValidatorSchema::newsince it collects into aHashMap; the protobuf conversion path detects duplicates before callingnew), - that context types are records
- common type resolution
Source§impl ValidatorSchema
impl ValidatorSchema
Sourcepub fn from_deprecated_json_value(
json: Value,
extensions: &Extensions<'_>,
) -> Result<Self, SchemaError>
pub fn from_deprecated_json_value( json: Value, extensions: &Extensions<'_>, ) -> Result<Self, SchemaError>
Construct a ValidatorSchema from a JSON value in the appropriate
shape.
Sourcepub fn from_deprecated_json_str(
json: &str,
extensions: &Extensions<'_>,
) -> Result<Self, SchemaError>
pub fn from_deprecated_json_str( json: &str, extensions: &Extensions<'_>, ) -> Result<Self, SchemaError>
Construct a ValidatorSchema from a string containing JSON in the
appropriate shape.
Sourcepub fn from_deprecated_json_file(
file: impl Read,
extensions: &Extensions<'_>,
) -> Result<Self, SchemaError>
pub fn from_deprecated_json_file( file: impl Read, extensions: &Extensions<'_>, ) -> Result<Self, SchemaError>
Construct a ValidatorSchema directly from a file containing JSON
in the appropriate shape.
Trait Implementations§
Source§impl Clone for ValidatorSchema
impl Clone for ValidatorSchema
Source§fn clone(&self) -> ValidatorSchema
fn clone(&self) -> ValidatorSchema
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ValidatorSchema
impl Debug for ValidatorSchema
impl Eq for ValidatorSchema
Source§impl FromStr for ValidatorSchema
Construct ValidatorSchema from a string containing a schema formatted
in the Cedar schema format.
impl FromStr for ValidatorSchema
Construct ValidatorSchema from a string containing a schema formatted
in the Cedar schema format.
Source§impl PartialEq for ValidatorSchema
impl PartialEq for ValidatorSchema
Source§impl RequestSchema for ValidatorSchema
impl RequestSchema for ValidatorSchema
Source§fn validate_context<'a>(
&self,
context: &Context,
action: &EntityUID,
extensions: &Extensions<'a>,
) -> Result<(), RequestValidationError>
fn validate_context<'a>( &self, context: &Context, action: &EntityUID, extensions: &Extensions<'a>, ) -> Result<(), RequestValidationError>
Validate a context against a schema for a specific action
Source§fn validate_scope_variables(
&self,
principal: Option<&EntityUID>,
action: Option<&EntityUID>,
resource: Option<&EntityUID>,
) -> Result<(), RequestValidationError>
fn validate_scope_variables( &self, principal: Option<&EntityUID>, action: Option<&EntityUID>, resource: Option<&EntityUID>, ) -> Result<(), RequestValidationError>
Validate entities against a schema for a specific action
Source§type Error = RequestValidationError
type Error = RequestValidationError
Source§fn validate_request(
&self,
request: &Request,
extensions: &Extensions<'_>,
) -> Result<(), Self::Error>
fn validate_request( &self, request: &Request, extensions: &Extensions<'_>, ) -> Result<(), Self::Error>
request, returning Err if it fails validationAuto Trait Implementations§
impl !Freeze for ValidatorSchema
impl RefUnwindSafe for ValidatorSchema
impl Send for ValidatorSchema
impl Sync for ValidatorSchema
impl Unpin for ValidatorSchema
impl UnsafeUnpin for ValidatorSchema
impl UnwindSafe for ValidatorSchema
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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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