Struct RuleRegistry
pub struct RuleRegistry {
rules: RwLock<RawRwLock, HashMap<String, RuleVersionHistory>>,
signature_verifier: Option<Arc<dyn SignatureVerifier>>,
swap_backend: Arc<dyn RuleSwapBackend>,
max_history_per_rule: usize,
}Expand description
Hot-swappable rule registry.
Thread-safe: all public operations take &self and synchronize
internally via RwLock.
Fields§
§rules: RwLock<RawRwLock, HashMap<String, RuleVersionHistory>>§signature_verifier: Option<Arc<dyn SignatureVerifier>>§swap_backend: Arc<dyn RuleSwapBackend>§max_history_per_rule: usizeImplementations§
§impl RuleRegistry
impl RuleRegistry
pub fn new(
max_history_per_rule: usize,
swap_backend: Arc<dyn RuleSwapBackend>,
) -> RuleRegistry
pub fn new( max_history_per_rule: usize, swap_backend: Arc<dyn RuleSwapBackend>, ) -> RuleRegistry
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).
pub fn with_verifier(self, verifier: Arc<dyn SignatureVerifier>) -> RuleRegistry
pub fn with_verifier(self, verifier: Arc<dyn SignatureVerifier>) -> RuleRegistry
Attach a signature verifier. Rules without signatures are rejected once a verifier is set.
pub fn rule_count(&self) -> usize
pub fn rule_count(&self) -> usize
Number of rules currently registered.
pub fn max_history(&self) -> usize
pub fn max_history(&self) -> usize
Configured history depth per rule.
pub 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.
pub 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
pub 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.
pub fn list_rules(&self) -> Vec<RuleHandle>
pub fn list_rules(&self) -> Vec<RuleHandle>
List the active handle for every registered rule.
pub 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.
pub 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.
pub fn history(&self, rule_id: &str) -> Vec<RuleHandle>
pub fn history(&self, rule_id: &str) -> Vec<RuleHandle>
Full history for a rule (oldest first).
Auto Trait Implementations§
impl !Freeze for RuleRegistry
impl !RefUnwindSafe for RuleRegistry
impl Send for RuleRegistry
impl Sync for RuleRegistry
impl Unpin for RuleRegistry
impl !UnwindSafe for RuleRegistry
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
§fn deserialize(
&self,
deserializer: &mut D,
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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