reifydb_transaction/interceptor/
authentication.rs1use reifydb_core::interface::catalog::authentication::Authentication;
5use reifydb_type::Result;
6
7use crate::interceptor::chain::InterceptorChain;
8
9pub struct AuthenticationPostCreateContext<'a> {
10 pub post: &'a Authentication,
11}
12
13impl<'a> AuthenticationPostCreateContext<'a> {
14 pub fn new(post: &'a Authentication) -> Self {
15 Self {
16 post,
17 }
18 }
19}
20
21pub trait AuthenticationPostCreateInterceptor: Send + Sync {
22 fn intercept<'a>(&self, ctx: &mut AuthenticationPostCreateContext<'a>) -> Result<()>;
23}
24
25impl InterceptorChain<dyn AuthenticationPostCreateInterceptor + Send + Sync> {
26 pub fn execute(&self, mut ctx: AuthenticationPostCreateContext) -> Result<()> {
27 for interceptor in &self.interceptors {
28 interceptor.intercept(&mut ctx)?;
29 }
30 Ok(())
31 }
32}
33
34pub struct ClosureAuthenticationPostCreateInterceptor<F>
35where
36 F: for<'a> Fn(&mut AuthenticationPostCreateContext<'a>) -> Result<()> + Send + Sync,
37{
38 closure: F,
39}
40
41impl<F> ClosureAuthenticationPostCreateInterceptor<F>
42where
43 F: for<'a> Fn(&mut AuthenticationPostCreateContext<'a>) -> Result<()> + Send + Sync,
44{
45 pub fn new(closure: F) -> Self {
46 Self {
47 closure,
48 }
49 }
50}
51
52impl<F> Clone for ClosureAuthenticationPostCreateInterceptor<F>
53where
54 F: for<'a> Fn(&mut AuthenticationPostCreateContext<'a>) -> Result<()> + Send + Sync + Clone,
55{
56 fn clone(&self) -> Self {
57 Self {
58 closure: self.closure.clone(),
59 }
60 }
61}
62
63impl<F> AuthenticationPostCreateInterceptor for ClosureAuthenticationPostCreateInterceptor<F>
64where
65 F: for<'a> Fn(&mut AuthenticationPostCreateContext<'a>) -> Result<()> + Send + Sync,
66{
67 fn intercept<'a>(&self, ctx: &mut AuthenticationPostCreateContext<'a>) -> Result<()> {
68 (self.closure)(ctx)
69 }
70}
71
72pub fn authentication_post_create<F>(f: F) -> ClosureAuthenticationPostCreateInterceptor<F>
73where
74 F: for<'a> Fn(&mut AuthenticationPostCreateContext<'a>) -> Result<()> + Send + Sync + Clone + 'static,
75{
76 ClosureAuthenticationPostCreateInterceptor::new(f)
77}
78
79pub struct AuthenticationPreDeleteContext<'a> {
80 pub pre: &'a Authentication,
81}
82
83impl<'a> AuthenticationPreDeleteContext<'a> {
84 pub fn new(pre: &'a Authentication) -> Self {
85 Self {
86 pre,
87 }
88 }
89}
90
91pub trait AuthenticationPreDeleteInterceptor: Send + Sync {
92 fn intercept<'a>(&self, ctx: &mut AuthenticationPreDeleteContext<'a>) -> Result<()>;
93}
94
95impl InterceptorChain<dyn AuthenticationPreDeleteInterceptor + Send + Sync> {
96 pub fn execute(&self, mut ctx: AuthenticationPreDeleteContext) -> Result<()> {
97 for interceptor in &self.interceptors {
98 interceptor.intercept(&mut ctx)?;
99 }
100 Ok(())
101 }
102}
103
104pub struct ClosureAuthenticationPreDeleteInterceptor<F>
105where
106 F: for<'a> Fn(&mut AuthenticationPreDeleteContext<'a>) -> Result<()> + Send + Sync,
107{
108 closure: F,
109}
110
111impl<F> ClosureAuthenticationPreDeleteInterceptor<F>
112where
113 F: for<'a> Fn(&mut AuthenticationPreDeleteContext<'a>) -> Result<()> + Send + Sync,
114{
115 pub fn new(closure: F) -> Self {
116 Self {
117 closure,
118 }
119 }
120}
121
122impl<F> Clone for ClosureAuthenticationPreDeleteInterceptor<F>
123where
124 F: for<'a> Fn(&mut AuthenticationPreDeleteContext<'a>) -> Result<()> + Send + Sync + Clone,
125{
126 fn clone(&self) -> Self {
127 Self {
128 closure: self.closure.clone(),
129 }
130 }
131}
132
133impl<F> AuthenticationPreDeleteInterceptor for ClosureAuthenticationPreDeleteInterceptor<F>
134where
135 F: for<'a> Fn(&mut AuthenticationPreDeleteContext<'a>) -> Result<()> + Send + Sync,
136{
137 fn intercept<'a>(&self, ctx: &mut AuthenticationPreDeleteContext<'a>) -> Result<()> {
138 (self.closure)(ctx)
139 }
140}
141
142pub fn authentication_pre_delete<F>(f: F) -> ClosureAuthenticationPreDeleteInterceptor<F>
143where
144 F: for<'a> Fn(&mut AuthenticationPreDeleteContext<'a>) -> Result<()> + Send + Sync + Clone + 'static,
145{
146 ClosureAuthenticationPreDeleteInterceptor::new(f)
147}