From 19c009e7a1b9593c9da66d2898747ff47873124c Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Tue, 19 Nov 2024 10:13:06 -0600 Subject: [PATCH] Start documenting mappers --- v-api/src/mapper/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/v-api/src/mapper/mod.rs b/v-api/src/mapper/mod.rs index 66bb307..59e9556 100644 --- a/v-api/src/mapper/mod.rs +++ b/v-api/src/mapper/mod.rs @@ -35,11 +35,14 @@ pub mod email_domain; pub mod github_username; #[async_trait] +/// Mapping rules that determine permissions and groups for users pub trait MapperRule: Send + Sync where T: VAppPermission, { + /// Determines the permissions for a given user. async fn permissions_for(&self, user: &UserInfo) -> Result, StoreError>; + /// Determines the access groups for a given user. async fn groups_for( &self, user: &UserInfo, @@ -54,11 +57,15 @@ pub enum MappingEngineError { Other(Box), } +/// Interface for generating mapping rules from mapper configurations pub trait MappingEngine: Send + Sync + 'static { + /// Creates a new mapping rule from a Mapper configuration fn create_mapping(&self, value: Mapper) -> Result>, MappingEngineError>; + /// Validates whether the provided data represents a known mapping rule fn validate_mapping_data(&self, value: &Value) -> bool; } +/// Default implementation of the MappingEngine trait pub struct DefaultMappingEngine { caller: Caller, group: GroupContext, @@ -73,6 +80,7 @@ where } } +/// The default mapping rule configurations that are supported by the default mapping engine #[derive(Debug, Deserialize, Serialize, JsonSchema)] #[serde(tag = "rule", rename_all = "snake_case")] pub enum MappingRulesData {