1414mod tests;
1515
1616mod mem;
17+ mod postgres;
1718
1819use crate :: context:: ParticipantContext ;
1920use regex:: Regex ;
2021use thiserror:: Error ;
2122
2223pub use mem:: MemoryAuthorizationEvaluator ;
24+ pub use postgres:: PostgresAuthorizationEvaluator ;
2325
2426/// Represents an operation with specific attributes that describe its scope, action, and resource.
2527///
@@ -73,19 +75,21 @@ impl Rule {
7375}
7476
7577/// Evaluates whether an operation is authorized for a participant based on the configured rules.
78+ #[ async_trait:: async_trait]
7679pub trait AuthorizationEvaluator : Sync + Send {
77- fn evaluate (
80+ async fn evaluate (
7881 & self ,
7982 participant_context : & ParticipantContext ,
8083 operation : Operation ,
8184 ) -> Result < bool , AuthorizationError > ;
8285}
8386
8487/// Stores rules for a participant.
88+ #[ async_trait:: async_trait]
8589pub trait RuleStore : Send + Sync {
86- fn get_rules ( & self , participant_context : & ParticipantContext ) -> Result < Vec < Rule > , AuthorizationError > ;
87- fn save_rule ( & self , participant_context : & ParticipantContext , rule : Rule ) -> Result < ( ) , AuthorizationError > ;
88- fn remove_rule ( & self , participant_context : & ParticipantContext , rule : Rule ) -> Result < ( ) , AuthorizationError > ;
90+ async fn get_rules ( & self , participant_context : & ParticipantContext ) -> Result < Vec < Rule > , AuthorizationError > ;
91+ async fn save_rule ( & self , participant_context : & ParticipantContext , rule : Rule ) -> Result < ( ) , AuthorizationError > ;
92+ async fn remove_rule ( & self , participant_context : & ParticipantContext , rule : Rule ) -> Result < ( ) , AuthorizationError > ;
8993}
9094
9195pub struct TrueAuthorizationEvaluator { }
@@ -96,8 +100,9 @@ impl TrueAuthorizationEvaluator {
96100 }
97101}
98102
103+ #[ async_trait:: async_trait]
99104impl AuthorizationEvaluator for TrueAuthorizationEvaluator {
100- fn evaluate ( & self , _: & ParticipantContext , _: Operation ) -> Result < bool , AuthorizationError > {
105+ async fn evaluate ( & self , _: & ParticipantContext , _: Operation ) -> Result < bool , AuthorizationError > {
101106 Ok ( true )
102107 }
103108}
0 commit comments