pub struct CompiledPolicy { /* private fields */ }Expand description
Wrapper around CompiledPolicyData that holds an Rc reference.
Implementations§
Source§impl CompiledPolicy
impl CompiledPolicy
Sourcepub fn get_rules(&self) -> &Map<String, Vec<Ref<Rule>>>
pub fn get_rules(&self) -> &Map<String, Vec<Ref<Rule>>>
Get access to the rules in the compiled policy for downstream consumers like the RVM compiler.
Sourcepub fn get_modules(&self) -> &Vec<Ref<Module>> ⓘ
pub fn get_modules(&self) -> &Vec<Ref<Module>> ⓘ
Get access to the modules in the compiled policy.
Sourcepub fn is_rego_v0(&self) -> bool
pub fn is_rego_v0(&self) -> bool
Returns true when the compiled policy should use Rego v0 semantics.
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
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more