pub struct Template { /* private fields */ }
Expand description
Policy template datatype
Implementations§
Source§impl Template
impl Template
Sourcepub fn parse(
id: Option<PolicyId>,
src: impl AsRef<str>,
) -> Result<Self, ParseErrors>
pub fn parse( id: Option<PolicyId>, src: impl AsRef<str>, ) -> Result<Self, ParseErrors>
Attempt to parse a Template
from source.
Returns an error if the input is a static policy (i.e., has no slots).
If id
is Some, then the resulting template will have that id
.
If the id
is None, the parser will use the default “policy0”.
The behavior around None may change in the future.
Sourcepub fn annotation(&self, key: impl AsRef<str>) -> Option<&str>
pub fn annotation(&self, key: impl AsRef<str>) -> Option<&str>
Get an annotation value of this Template
.
If the annotation is present without an explicit value (e.g., @annotation
),
then this function returns Some("")
. It returns None
only when the
annotation is not present.
Sourcepub fn annotations(&self) -> impl Iterator<Item = (&str, &str)>
pub fn annotations(&self) -> impl Iterator<Item = (&str, &str)>
Iterate through annotation data of this Template
as key-value pairs
Annotations which do not have an explicit value (e.g., @annotation
),
are included in the iterator with the value ""
.
Sourcepub fn slots(&self) -> impl Iterator<Item = &SlotId>
pub fn slots(&self) -> impl Iterator<Item = &SlotId>
Iterate over the open slots in this Template
Sourcepub fn principal_constraint(&self) -> TemplatePrincipalConstraint
pub fn principal_constraint(&self) -> TemplatePrincipalConstraint
Get the scope constraint on this policy’s principal
Sourcepub fn action_constraint(&self) -> ActionConstraint
pub fn action_constraint(&self) -> ActionConstraint
Get the scope constraint on this policy’s action
Sourcepub fn resource_constraint(&self) -> TemplateResourceConstraint
pub fn resource_constraint(&self) -> TemplateResourceConstraint
Get the scope constraint on this policy’s resource
Sourcepub fn from_json(
id: Option<PolicyId>,
json: Value,
) -> Result<Self, PolicyFromJsonError>
pub fn from_json( id: Option<PolicyId>, json: Value, ) -> Result<Self, PolicyFromJsonError>
Create a Template
from its JSON representation.
Returns an error if the input is a static policy (i.e., has no slots).
If id
is Some, the policy will be given that Policy Id.
If id
is None, then “JSON policy” will be used.
The behavior around None may change in the future.
Sourcepub fn to_json(&self) -> Result<Value, PolicyToJsonError>
pub fn to_json(&self) -> Result<Value, PolicyToJsonError>
Get the JSON representation of this Template
.
Sourcepub fn get_valid_request_envs(
&self,
s: &Schema,
) -> impl Iterator<Item = RequestEnv>
pub fn get_valid_request_envs( &self, s: &Schema, ) -> impl Iterator<Item = RequestEnv>
Get valid RequestEnv
s.
A RequestEnv
is valid when the template type checks w.r.t requests
that satisfy it.
Trait Implementations§
impl Eq for Template
Auto Trait Implementations§
impl Freeze for Template
impl RefUnwindSafe for Template
impl Send for Template
impl Sync for Template
impl Unpin for Template
impl UnwindSafe for Template
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<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