pub struct RuleRegistry { /* private fields */ }Expand description
Hot-swappable rule registry.
Thread-safe: all public operations take &self and synchronize
internally via RwLock.
Implementations§
Source§impl RuleRegistry
impl RuleRegistry
Sourcepub fn new(
max_history_per_rule: usize,
swap_backend: Arc<dyn RuleSwapBackend>,
) -> Self
pub fn new( max_history_per_rule: usize, swap_backend: Arc<dyn RuleSwapBackend>, ) -> Self
Create a new registry with the given backend.
max_history_per_rule determines how many prior versions we keep
available for rollback. When the limit is exceeded, the oldest
version is evicted (FIFO).
Sourcepub fn with_verifier(self, verifier: Arc<dyn SignatureVerifier>) -> Self
pub fn with_verifier(self, verifier: Arc<dyn SignatureVerifier>) -> Self
Attach a signature verifier. Rules without signatures are rejected once a verifier is set.
Sourcepub fn rule_count(&self) -> usize
pub fn rule_count(&self) -> usize
Number of rules currently registered.
Sourcepub fn max_history(&self) -> usize
pub fn max_history(&self) -> usize
Configured history depth per rule.
Sourcepub async fn register_rule(
&self,
rule: CompiledRule,
device_compute_cap: &str,
) -> Result<RuleHandle, RuleError>
pub async fn register_rule( &self, rule: CompiledRule, device_compute_cap: &str, ) -> Result<RuleHandle, RuleError>
Register a rule for the first time (or register a new version of an existing rule without making it active).
On success, the new version has status RuleStatus::Registered
if the rule already had an active version; otherwise it is
immediately activated and returned with RuleStatus::Active.
Sourcepub async fn reload_rule(
&self,
rule: CompiledRule,
device_compute_cap: &str,
) -> Result<ReloadReport, RuleError>
pub async fn reload_rule( &self, rule: CompiledRule, device_compute_cap: &str, ) -> Result<ReloadReport, RuleError>
Atomically hot-swap a new version of an existing rule.
Preconditions:
- rule is already registered
- proposed version strictly greater than current active version
- validation passes (signature, compute cap, deps)
Postconditions:
- new version has status
RuleStatus::Active - old active version has status [
RuleStatus::Superseded(new)] ReloadReportreturned with timing information
Sourcepub async fn rollback_rule(
&self,
rule_id: &str,
to_version: u64,
) -> Result<ReloadReport, RuleError>
pub async fn rollback_rule( &self, rule_id: &str, to_version: u64, ) -> Result<ReloadReport, RuleError>
Roll back to a specific earlier version kept in history.
Unlike reload_rule, rollback marks the previously active version
as RuleStatus::Rolledback (not Superseded) so auditors can
tell the transition apart.
Sourcepub fn list_rules(&self) -> Vec<RuleHandle>
pub fn list_rules(&self) -> Vec<RuleHandle>
List the active handle for every registered rule.
Sourcepub fn get_rule(&self, rule_id: &str, version: u64) -> Option<CompiledRule>
pub fn get_rule(&self, rule_id: &str, version: u64) -> Option<CompiledRule>
Return a specific (rule_id, version) artifact if still in history.
Sourcepub fn get_active(&self, rule_id: &str) -> Option<CompiledRule>
pub fn get_active(&self, rule_id: &str) -> Option<CompiledRule>
Return the currently active rule artifact, if any.
Sourcepub fn history(&self, rule_id: &str) -> Vec<RuleHandle>
pub fn history(&self, rule_id: &str) -> Vec<RuleHandle>
Full history for a rule (oldest first).