pub struct PolicySet { /* private fields */ }Expand description
Represents a set of Policys
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 Policys 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 Policys 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 Templates 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
valsmay not match the slots in the template - The
new_idmay conflict w/ a policy that already exists in the set template_iddoes 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 From<&PolicySet> for LiteralPolicySet
Available on crate feature protobufs only.
impl From<&PolicySet> for LiteralPolicySet
protobufs only.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
Source§impl TryFrom<&LiteralPolicySet> for PolicySet
Available on crate feature protobufs only.
impl TryFrom<&LiteralPolicySet> for PolicySet
protobufs only.Source§type Error = PolicySetError
type Error = PolicySetError
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§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