pub struct PolicySet { /* private fields */ }
Expand description
Represents a set of Policy
s
Implementations§
source§impl PolicySet
impl PolicySet
sourcepub fn from_json_str(src: impl AsRef<str>) -> Result<Self, PolicySetError>
pub fn from_json_str(src: impl AsRef<str>) -> Result<Self, PolicySetError>
Deserialize the PolicySet
from a JSON string
sourcepub fn from_json_value(src: Value) -> Result<Self, PolicySetError>
pub fn from_json_value(src: Value) -> Result<Self, PolicySetError>
Deserialize the PolicySet
from a JSON value
sourcepub fn from_json_file(r: impl Read) -> Result<Self, PolicySetError>
pub fn from_json_file(r: impl Read) -> Result<Self, PolicySetError>
Deserialize the PolicySet
from a JSON reader
sourcepub fn from_policies(
policies: impl IntoIterator<Item = Policy>,
) -> Result<Self, PolicySetError>
pub fn from_policies( policies: impl IntoIterator<Item = Policy>, ) -> Result<Self, PolicySetError>
Create a PolicySet
from the given policies
sourcepub fn add(&mut self, policy: Policy) -> Result<(), PolicySetError>
pub fn add(&mut self, policy: Policy) -> Result<(), PolicySetError>
Add an static policy to the PolicySet
. To add a template instance, use
link
instead. This function will return an error (and not modify
the PolicySet
) if a template-linked policy is passed in.
sourcepub fn remove_static(
&mut self,
policy_id: PolicyId,
) -> Result<Policy, PolicySetError>
pub fn remove_static( &mut self, policy_id: PolicyId, ) -> Result<Policy, PolicySetError>
Remove a static Policy
from the PolicySet
.
This will error if the policy is not a static policy.
sourcepub fn add_template(&mut self, template: Template) -> Result<(), PolicySetError>
pub fn add_template(&mut self, template: Template) -> Result<(), PolicySetError>
Add a Template
to the PolicySet
sourcepub fn remove_template(
&mut self,
template_id: PolicyId,
) -> Result<Template, PolicySetError>
pub fn remove_template( &mut self, template_id: PolicyId, ) -> Result<Template, PolicySetError>
Remove a Template
from the PolicySet
.
This will error if any policy is linked to the template.
This will error if policy_id
is not a template.
sourcepub fn get_linked_policies(
&self,
template_id: PolicyId,
) -> Result<impl Iterator<Item = &PolicyId>, PolicySetError>
pub fn get_linked_policies( &self, template_id: PolicyId, ) -> Result<impl Iterator<Item = &PolicyId>, PolicySetError>
Get policies linked to a Template
in the PolicySet
.
If any policy is linked to the template, this will error
sourcepub fn policies(&self) -> impl Iterator<Item = &Policy>
pub fn policies(&self) -> impl Iterator<Item = &Policy>
Iterate over all the Policy
s in the PolicySet
.
This will include both static and template-linked policies.
sourcepub fn templates(&self) -> impl Iterator<Item = &Template>
pub fn templates(&self) -> impl Iterator<Item = &Template>
Iterate over the Template
’s in the PolicySet
.
sourcepub fn annotation(&self, id: &PolicyId, key: impl AsRef<str>) -> Option<&str>
pub fn annotation(&self, id: &PolicyId, key: impl AsRef<str>) -> Option<&str>
Extract annotation data from a Policy
by its PolicyId
and annotation key.
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 template_annotation(
&self,
id: &PolicyId,
key: impl AsRef<str>,
) -> Option<&str>
pub fn template_annotation( &self, id: &PolicyId, key: impl AsRef<str>, ) -> Option<&str>
Extract annotation data from a Template
by its PolicyId
and annotation key.
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 num_of_policies(&self) -> usize
pub fn num_of_policies(&self) -> usize
Returns the number of Policy
s in the PolicySet
.
This will include both static and template-linked policies.
sourcepub fn num_of_templates(&self) -> usize
pub fn num_of_templates(&self) -> usize
Returns the number of Template
s in the PolicySet
.
sourcepub fn link(
&mut self,
template_id: PolicyId,
new_id: PolicyId,
vals: HashMap<SlotId, EntityUid>,
) -> Result<(), PolicySetError>
pub fn link( &mut self, template_id: PolicyId, new_id: PolicyId, vals: HashMap<SlotId, EntityUid>, ) -> Result<(), PolicySetError>
Attempt to link a template and add the new template-linked policy to the policy set.
If link fails, the PolicySet
is not modified.
Failure can happen for three reasons
- The map passed in
vals
may not match the slots in the template - The
new_id
may conflict w/ a policy that already exists in the set template_id
does not correspond to a template. Either the id is not in the policy set, or it is in the policy set but is either a linked or static policy rather than a template
sourcepub fn unknown_entities(&self) -> HashSet<EntityUid>
Available on crate feature partial-eval
only.
pub fn unknown_entities(&self) -> HashSet<EntityUid>
partial-eval
only.Get all the unknown entities from the policy set
Trait Implementations§
source§impl FromStr for PolicySet
impl FromStr for PolicySet
source§fn from_str(policies: &str) -> Result<Self, Self::Err>
fn from_str(policies: &str) -> Result<Self, Self::Err>
Create a policy set from multiple statements.
Policy ids will default to “policy*” with numbers from 0. If you load more policies, do not use the default id, or there will be conflicts.
See Policy
for more.
source§type Err = ParseErrors
type Err = ParseErrors
impl Eq for PolicySet
Auto Trait Implementations§
impl Freeze for PolicySet
impl RefUnwindSafe for PolicySet
impl Send for PolicySet
impl Sync for PolicySet
impl Unpin for PolicySet
impl UnwindSafe for PolicySet
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