pub struct CompiledPolicy { /* private fields */ }
Expand description
Wrapper around CompiledPolicyData that holds an Rc reference.
Implementations§
Source§impl CompiledPolicy
impl CompiledPolicy
Sourcepub fn eval_with_input(&self, input: Value) -> Result<Value>
pub fn eval_with_input(&self, input: Value) -> Result<Value>
Evaluate the compiled policy with the given input.
For target policies, evaluates the target’s effect rule. For regular policies, evaluates the originally compiled rule.
input
: Input data (resource) to validate against the policy.
Returns the result of evaluating the rule.
Sourcepub fn get_policy_info(&self) -> Result<PolicyInfo>
pub fn get_policy_info(&self) -> Result<PolicyInfo>
Get information about the compiled policy including metadata about modules, target configuration, and resource types.
Returns a crate::policy_info::PolicyInfo
struct containing comprehensive
information about the compiled policy such as module IDs, target name,
applicable resource types, entry point rule, and parameters.
§Examples
use regorus::*;
// Compile the policy
let policy_rego = r#"
package policy.example
import rego.v1
__target__ := "target.tests.sample_test_target"
effect := "allow" if {
input.type == "storage_account"
input.location in ["eastus", "westus"]
}
"#;
let modules = vec![regorus::PolicyModule {
id: "policy.rego".into(),
content: policy_rego.into(),
}];
#[cfg(feature = "azure_policy")]
let compiled = regorus::compile_policy_for_target(Value::new_object(), &modules)?;
#[cfg(not(feature = "azure_policy"))]
let compiled = regorus::compile_policy_with_entrypoint(Value::new_object(), &modules, "allow".into())?;
let info = compiled.get_policy_info()?;
assert_eq!(info.target_name, Some("target.tests.sample_test_target".into()));
assert_eq!(info.effect_rule, Some("effect".into()));
assert!(info.module_ids.len() > 0);
Trait Implementations§
Source§impl Clone for CompiledPolicy
impl Clone for CompiledPolicy
Source§fn clone(&self) -> CompiledPolicy
fn clone(&self) -> CompiledPolicy
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for CompiledPolicy
impl !RefUnwindSafe for CompiledPolicy
impl Send for CompiledPolicy
impl Sync for CompiledPolicy
impl Unpin for CompiledPolicy
impl !UnwindSafe for CompiledPolicy
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
Mutably borrows from an owned value. Read more