1use crate::ProvideRuleError;
2use redis_cell_rs::{AllowedDetails, BlockedDetails, Key, Policy};
3
4#[derive(Debug, Clone)]
5#[non_exhaustive]
6pub struct Rule<'a> {
7 pub key: Key<'a>,
8 pub policy: Policy,
9 pub resource: Option<&'static str>,
10}
11
12impl<'a> Rule<'a> {
13 pub fn new<K>(key: K, policy: Policy) -> Self
14 where
15 K: Into<Key<'a>>,
16 {
17 Self {
18 key: key.into(),
19 policy,
20 resource: None,
21 }
22 }
23
24 pub fn resource(mut self, resource_name: &'static str) -> Self {
25 self.resource = Some(resource_name);
26 self
27 }
28}
29
30pub type ProvideRuleResult<'a> = Result<Option<Rule<'a>>, ProvideRuleError<'a>>;
31pub trait ProvideRule<R> {
32 fn provide<'a>(&self, req: &'a R) -> ProvideRuleResult<'a>;
33}
34
35#[derive(Debug, Clone)]
36#[non_exhaustive]
37pub struct RequestBlockedDetails<'a> {
38 pub details: BlockedDetails,
39 pub rule: Rule<'a>,
40}
41
42#[derive(Debug, Clone)]
43#[non_exhaustive]
44pub struct RequestAllowedDetails {
45 pub details: AllowedDetails,
46 pub policy: Policy,
47 pub resource: Option<&'static str>,
48}