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 has_non_scope_constraint(&self) -> bool
pub fn has_non_scope_constraint(&self) -> bool
Returns true if this template has a when or unless clause.
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(""). Returns None when the
annotation is not present or when key is not a valid annotation identifier.
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 to_cedar(&self) -> String
pub fn to_cedar(&self) -> String
Get the human-readable Cedar syntax representation of this template. This function is primarily intended for rendering JSON policies in the human-readable syntax, but it will also return the original policy text when given a policy parsed from the human-readable syntax.
It also does not format the policy according to any particular rules.
Policy formatting can be done through the Cedar policy CLI or
the cedar-policy-formatter crate.
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 the valid RequestEnvs for this template, according to the schema.
That is, all the RequestEnvs in the schema for which this template is
not trivially false.
Trait Implementations§
Source§impl From<&Template> for TemplateBody
Available on crate feature protobufs only.
impl From<&Template> for TemplateBody
protobufs only.Source§impl From<&TemplateBody> for Template
Available on crate feature protobufs only.
impl From<&TemplateBody> for Template
protobufs only.Source§fn from(v: &TemplateBody) -> Self
fn from(v: &TemplateBody) -> Self
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§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