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