use uuid::Uuid; use crate::domain::{ oidc::{ ports::OidcNotifier, requests::{GetRedirectResponse, GetUserInfoResponse}, }, warren::{ models::{ auth_session::requests::FetchAuthSessionResponse, file::{AbsoluteFilePath, AbsoluteFilePathList, LsResponse}, option::{DeleteOptionResponse, GetOptionResponse, OptionType, SetOptionResponse}, share::{ CreateShareResponse, DeleteShareResponse, GetShareResponse, ListSharesResponse, ShareCatResponse, ShareLsResponse, VerifySharePasswordResponse, }, user::{ ListAllUsersAndWarrensResponse, LoginUserOidcResponse, LoginUserResponse, User, }, user_warren::UserWarren, warren::{ Warren, WarrenCpResponse, WarrenLsResponse, WarrenMkdirResponse, WarrenMvResponse, WarrenRmResponse, WarrenSaveResponse, WarrenTouchResponse, }, }, ports::{AuthNotifier, FileSystemNotifier, OptionNotifier, WarrenNotifier}, }, }; #[derive(Debug, Clone, Copy)] pub struct NotifierDebugLogger; impl NotifierDebugLogger { pub fn new() -> Self { Self {} } } impl WarrenNotifier for NotifierDebugLogger { async fn warren_created(&self, warren: &Warren) { tracing::debug!("[Notifier] Created warren: {}", warren.name()); } async fn warren_edited(&self, warren: &Warren) { tracing::debug!("[Notifier] Edited warren: {}", warren.name()); } async fn warren_deleted(&self, warren: &Warren) { tracing::debug!("[Notifier] Deleted warren: {}", warren.name()); } async fn warrens_fetched(&self, warrens: &Vec) { tracing::debug!("[Notifier] Fetched {} warren(s)", warrens.len()); } async fn warrens_listed(&self, warrens: &Vec) { tracing::debug!("[Notifier] Listed {} warren(s)", warrens.len()); } async fn warren_fetched(&self, warren: &Warren) { tracing::debug!("[Notifier] Fetched warren {}", warren.name()); } async fn warren_cat(&self, warren: &Warren, paths: &AbsoluteFilePathList) { tracing::debug!( "[Notifier] Fetched {} file(s) in warren {}", paths.paths().len(), warren.name(), ); } async fn warren_ls(&self, response: &WarrenLsResponse) { tracing::debug!( "[Notifier] Listed {} file(s) in warren {}", response.base().files().len(), response.warren().name() ); } async fn warren_mkdir(&self, response: &WarrenMkdirResponse) { tracing::debug!( "[Notifier] Created directory {} in warren {}", response.path(), response.warren().name() ); } async fn warren_save(&self, warren: &Warren, path: &AbsoluteFilePath) { tracing::debug!("[Notifier] Saved file {} to warren {}", path, warren.name()); } async fn warren_rm(&self, response: &WarrenRmResponse) { let span = tracing::debug_span!("warren_rm", "{}", response.warren().name()).entered(); let results = response.results(); for result in results { match result.as_ref() { Ok(path) => tracing::debug!("Deleted file: {path}"), Err(e) => match e { crate::domain::warren::models::file::RmError::NotFound(path) => { tracing::debug!("File not found: {path}") } crate::domain::warren::models::file::RmError::NotEmpty(path) => { tracing::debug!("Directory not empty: {path}") } crate::domain::warren::models::file::RmError::Unknown(_) => (), }, } } span.exit(); } async fn warren_mv(&self, response: &WarrenMvResponse) { let span = tracing::debug_span!("warren_mv", "{}", response.warren().name()).entered(); let results = response.results(); for result in results { match result.as_ref() { Ok((old_path, new_path)) => { tracing::debug!("Moved file {old_path} to {new_path}") } Err(e) => match e { crate::domain::warren::models::file::MvError::NotFound(path) => { tracing::debug!("File not found: {path}") } crate::domain::warren::models::file::MvError::AlreadyExists(path) => { tracing::debug!("File already exists: {path}") } crate::domain::warren::models::file::MvError::Unknown(_) => (), }, } } span.exit(); } async fn warren_touch(&self, warren: &Warren, path: &AbsoluteFilePath) { tracing::debug!( "[Notifier] Touched file {} in warren {}", path, warren.name() ); } async fn warren_cp(&self, response: &WarrenCpResponse) { tracing::debug!( "[Notifier] Copied file {} to {} in warren {}", response.base().path(), response.base().target_path(), response.warren().name() ); } async fn warren_share_created(&self, response: &CreateShareResponse) { tracing::debug!( "[Notifier] Created share for file {} in warren {}", response.share().path(), response.share().warren_id(), ); } async fn warren_shares_listed(&self, response: &ListSharesResponse) { tracing::debug!( "[Notifier] Listed {} share(s) for file {} in warren {}", response.shares().len(), response.path(), response.warren().id(), ); } async fn warren_share_deleted(&self, response: &DeleteShareResponse) { tracing::debug!( "[Notifier] Deleted share {} for file {} in warren {}", response.share().id(), response.share().path(), response.share().warren_id(), ); } async fn got_warren_share(&self, response: &GetShareResponse) { tracing::debug!( "[Notifier] Got share {} from warren {}", response.share().id(), response.share().warren_id() ); } async fn warren_share_ls(&self, response: &ShareLsResponse) { tracing::debug!( "[Notifier] Listed {} file(s) in share {} at path {}", response.base().files().len(), response.share().id(), response.path() ); } async fn warren_share_cat(&self, response: &ShareCatResponse) { tracing::debug!( "[Notifier] Fetched {} file(s) from share {}", response.paths().paths().len(), response.share().id(), ); } async fn warren_share_password_verified(&self, response: &VerifySharePasswordResponse) { tracing::debug!( "[Notifier] Verified password for share {}", response.share().id() ); } } impl FileSystemNotifier for NotifierDebugLogger { async fn ls(&self, response: &LsResponse) { tracing::debug!("[Notifier] Listed {} file(s)", response.files().len()); } async fn cat(&self, paths: &AbsoluteFilePathList) { tracing::debug!("[Notifier] Fetched {} file(s)", paths.paths().len()); } async fn mkdir(&self, path: &AbsoluteFilePath) { tracing::debug!("[Notifier] Created directory {}", path); } async fn rm(&self, path: &AbsoluteFilePath) { tracing::debug!("[Notifier] Deleted file {}", path); } async fn mv(&self, old_path: &AbsoluteFilePath, new_path: &AbsoluteFilePath) { tracing::debug!("[Notifier] Renamed file {} to {}", old_path, new_path); } async fn save(&self, path: &AbsoluteFilePath) { tracing::debug!("[Notifier] Saved file {}", path); } async fn touch(&self, path: &AbsoluteFilePath) { tracing::debug!("[Notifier] Touched file {}", path); } async fn cp(&self, path: &AbsoluteFilePath, target_path: &AbsoluteFilePath) { tracing::debug!("[Notifier] Copied file {} to {}", path, target_path); } async fn stat(&self, path: &AbsoluteFilePath) { tracing::debug!("[Notifier] Got stats for file {}", path); } } impl AuthNotifier for NotifierDebugLogger { async fn auth_warren_created(&self, creator: &User, warren: &Warren) { tracing::debug!( "[Notifier] Admin {} created warren: {}", creator.id(), warren.name() ); } async fn auth_warren_edited(&self, editor: &User, warren: &Warren) { tracing::debug!( "[Notifier] Admin {} edited warren: {}", editor.id(), warren.name() ); } async fn auth_warren_deleted(&self, deleter: &User, warren: &Warren) { tracing::debug!( "[Notifier] Admin {} deleted warren: {}", deleter.id(), warren.name() ); } async fn user_registered(&self, user: &User) { tracing::debug!("[Notifier] Registered user {}", user.name()); } async fn user_created(&self, creator: &User, user: &User) { tracing::debug!( "[Notifier] Admin user {} created user {}", creator.name(), user.name() ); } async fn user_edited(&self, editor: &User, user: &User) { tracing::debug!( "[Notifier] Admin user {} edited user {}", editor.name(), user.id() ); } async fn user_deleted(&self, deleter: &User, user: &User) { tracing::debug!( "[Notifier] Admin user {} deleted user {}", deleter.name(), user.name() ); } async fn users_listed(&self, user: &User, users: &Vec) { tracing::debug!( "[Notifier] Admin user {} listed {} user(s)", user.name(), users.len() ); } async fn all_users_and_warrens_listed( &self, user: &User, response: &ListAllUsersAndWarrensResponse, ) { tracing::debug!( "[Notifier] Admin user {} listed {} user(s), {} warren(s) and {} user warren(s)", user.name(), response.users().len(), response.warrens().len(), response.user_warrens().len(), ); } async fn user_logged_in(&self, response: &LoginUserResponse) { tracing::debug!("[Notifier] Logged in user {}", response.user().name()); } async fn user_logged_in_oidc(&self, response: &LoginUserOidcResponse) { tracing::debug!( "[Notifier] Logged in user {} with OIDC", response.user().name() ); } async fn auth_session_created(&self, user_id: &Uuid) { tracing::debug!("[Notifier] Created auth session for user {}", user_id); } async fn auth_session_fetched(&self, response: &FetchAuthSessionResponse) { tracing::debug!( "[Notifier] Fetched auth session for user {}", response.user().id() ); } async fn auth_user_warren_created(&self, creator: &User, user_warren: &UserWarren) { tracing::debug!( "[Notifier] Admin user {} added user {} to warren {}", creator.id(), user_warren.user_id(), user_warren.warren_id(), ); } async fn auth_user_warren_edited(&self, editor: &User, user_warren: &UserWarren) { tracing::debug!( "[Notifier] Admin user {} edited the access of user {} to warren {}", editor.id(), user_warren.user_id(), user_warren.warren_id(), ); } async fn auth_user_warren_deleted(&self, deleter: &User, user_warren: &UserWarren) { tracing::debug!( "[Notifier] Admin user {} added removed {} from warren {}", deleter.id(), user_warren.user_id(), user_warren.warren_id(), ); } async fn auth_user_warrens_fetched(&self, user_id: &Uuid, warren_ids: &Vec) { tracing::debug!( "[Notifier] Fetched {} user warrens for authenticated user {}", warren_ids.len(), user_id ); } async fn auth_user_warrens_listed(&self, user: &User, warrens: &Vec) { tracing::debug!( "[Notifier] Fetched {} warren(s) for authenticated user {}", warrens.len(), user.id() ); } async fn auth_warren_fetched(&self, user: &User, warren: &Warren) { tracing::debug!( "[Notifier] Fetched warren {} for authenticated user {}", warren.name(), user.id(), ); } async fn auth_warren_cat(&self, user: &User, warren_id: &Uuid, paths: &AbsoluteFilePathList) { tracing::debug!( "[Notifier] User {} fetched {} file(s) in warren {warren_id}", user.id(), paths.paths().len(), ); } async fn auth_warren_ls(&self, user: &User, response: &WarrenLsResponse) { tracing::debug!( "[Notifier] Listed {} file(s) in warren {} for authenticated user {}", response.base().files().len(), response.warren().name(), user.id() ); } async fn auth_warren_mkdir(&self, user: &User, response: &WarrenMkdirResponse) { tracing::debug!( "[Notifier] Created directory {} in warren {} for authenticated user {}", response.path(), response.warren().name(), user.id(), ); } async fn auth_warren_save(&self, user: &User, response: &WarrenSaveResponse) { tracing::debug!( "[Notifier] Uploaded file {} to warren {} for authenticated user {}", response.path(), response.warren().name(), user.id(), ); } async fn auth_warren_rm(&self, user: &User, response: &WarrenRmResponse) { let results = response.results(); let successes = results.iter().filter(|r| r.is_ok()).count(); tracing::debug!( "[Notifier] Deleted {successes} file(s) from warren {} for authenticated user {}", response.warren().name(), user.id(), ); } async fn auth_warren_mv(&self, user: &User, response: &WarrenMvResponse) { let results = response.results(); let successes = results.iter().filter(|r| r.is_ok()).count(); tracing::debug!( "[Notifier] Moved {successes} file(s) in warren {} for authenticated user {}", response.warren().name(), user.id(), ); } async fn auth_warren_touch(&self, user: &User, response: &WarrenTouchResponse) { tracing::debug!( "[Notifier] Touched file {} in warren {} for authenticated user {}", response.path(), response.warren().name(), user.id() ) } async fn auth_warren_cp(&self, user: &User, response: &WarrenCpResponse) { tracing::debug!( "[Notifier] Copied file {} to {} in warren {} for authenticated user {}", response.base().path(), response.base().target_path(), response.warren().name(), user.id() ) } async fn auth_warren_share_created(&self, user: &User, response: &CreateShareResponse) { tracing::debug!( "[Notifier] Created share for file {} in warren {} for authenticated user {}", response.share().path(), response.share().warren_id(), user.id(), ); } async fn auth_warren_shares_listed(&self, user: &User, response: &ListSharesResponse) { tracing::debug!( "[Notifier] Listed {} share(s) for file {} in warren {} for authenticated user {}", response.shares().len(), response.path(), response.warren().id(), user.id(), ); } async fn auth_warren_share_deleted(&self, user: &User, response: &DeleteShareResponse) { tracing::debug!( "[Notifier] Deleted share {} for file {} in warren {} for authenticated user {}", response.share().id(), response.share().path(), response.share().warren_id(), user.id(), ); } } impl OidcNotifier for NotifierDebugLogger { async fn get_redirect(&self, response: &GetRedirectResponse) { tracing::debug!("[Notifier] Got OIDC redirect: {}", response.url()); } async fn get_user_info(&self, response: &GetUserInfoResponse) { tracing::debug!( "[Notifier] Got OIDC user info: {} ({})", response .info() .preferred_username() .unwrap_or(response.info().name()), response.info().sub(), ); } } impl OptionNotifier for NotifierDebugLogger { async fn got_option(&self, response: &GetOptionResponse) { tracing::debug!( "[Notifier] Got option {}: {}", response.key().to_string(), response.value().to_string(), ); } async fn set_option(&self, response: &SetOptionResponse) { tracing::debug!( "[Notifier] Set option {} to {}", response.key().to_string(), response.value().to_string(), ); } async fn deleted_option(&self, response: &DeleteOptionResponse) { tracing::debug!("[Notifier] Deleted option {}", response.key().to_string()); } }