Struct cedar_policy_core::ast::Template
source · pub struct Template { /* private fields */ }
Expand description
Top level structure for a policy template. Contains both the AST for template, and the list of open slots in the template.
Note that this “template” may have no slots, in which case this Template
represents a static policy
Implementations§
source§impl Template
impl Template
sourcepub fn new(
id: PolicyID,
annotations: BTreeMap<Id, SmolStr>,
effect: Effect,
principal_constraint: PrincipalConstraint,
action_constraint: ActionConstraint,
resource_constraint: ResourceConstraint,
non_head_constraint: Expr,
) -> Self
pub fn new( id: PolicyID, annotations: BTreeMap<Id, SmolStr>, effect: Effect, principal_constraint: PrincipalConstraint, action_constraint: ActionConstraint, resource_constraint: ResourceConstraint, non_head_constraint: Expr, ) -> Self
Construct a Template
from its components
sourcepub fn principal_constraint(&self) -> &PrincipalConstraint
pub fn principal_constraint(&self) -> &PrincipalConstraint
Get the principal constraint on the body
sourcepub fn action_constraint(&self) -> &ActionConstraint
pub fn action_constraint(&self) -> &ActionConstraint
Get the action constraint on the body
sourcepub fn resource_constraint(&self) -> &ResourceConstraint
pub fn resource_constraint(&self) -> &ResourceConstraint
Get the resource constraint on the body
sourcepub fn non_head_constraints(&self) -> &Expr
pub fn non_head_constraints(&self) -> &Expr
Get the non-head constraint on the body
sourcepub fn annotation(&self, key: &Id) -> Option<&SmolStr>
pub fn annotation(&self, key: &Id) -> Option<&SmolStr>
Get data from an annotation.
sourcepub fn annotations(&self) -> impl Iterator<Item = (&Id, &SmolStr)>
pub fn annotations(&self) -> impl Iterator<Item = (&Id, &SmolStr)>
Get all annotation data.
sourcepub fn condition(&self) -> Expr
pub fn condition(&self) -> Expr
Get the condition expression of this template.
This will be a conjunction of the template’s head constraints (on principal, resource, and action); the template’s “when” conditions; and the negation of each of the template’s “unless” conditions.
sourcepub fn is_static(&self) -> bool
pub fn is_static(&self) -> bool
Check if this template is a static policy
Static policies can be linked without any slots, and all links will be identical.
sourcepub fn check_binding(
template: &Template,
values: &HashMap<SlotId, EntityUID>,
) -> Result<(), LinkingError>
pub fn check_binding( template: &Template, values: &HashMap<SlotId, EntityUID>, ) -> Result<(), LinkingError>
Ensure that every slot in the template is bound by values, and that no extra values are bound in values This upholds invariant (values total map)
sourcepub fn link(
template: Arc<Template>,
new_id: PolicyID,
values: HashMap<SlotId, EntityUID>,
) -> Result<Policy, LinkingError>
pub fn link( template: Arc<Template>, new_id: PolicyID, values: HashMap<SlotId, EntityUID>, ) -> Result<Policy, LinkingError>
Attempt to create a template-linked policy from this template.
This will fail if values for all open slots are not given.
new_instance_id
is the PolicyId
for the created template-linked policy.
sourcepub fn link_static_policy(p: StaticPolicy) -> (Arc<Template>, Policy)
pub fn link_static_policy(p: StaticPolicy) -> (Arc<Template>, Policy)
Take a static policy and create a template and a template-linked policy for it. They will share the same ID
Trait Implementations§
source§impl<'de> Deserialize<'de> for Template
impl<'de> Deserialize<'de> for Template
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl From<Template> for TemplateBody
impl From<Template> for TemplateBody
source§impl From<TemplateBody> for Template
impl From<TemplateBody> for Template
source§fn from(body: TemplateBody) -> Self
fn from(body: TemplateBody) -> Self
source§impl TryFrom<Template> for StaticPolicy
impl TryFrom<Template> for StaticPolicy
impl Eq for Template
impl StructuralPartialEq 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<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