From 65acd3173ab8f076951b5aff72164454d728d592 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 19 Apr 2023 12:43:47 +0000 Subject: [PATCH] refactor(services): use fully generic foldermoves --- .../services/bitwarden/__init__.py | 10 +--------- .../services/generic_service_mover.py | 9 +++++++++ selfprivacy_api/services/gitea/__init__.py | 10 +--------- .../services/mailserver/__init__.py | 19 +++++-------------- .../services/nextcloud/__init__.py | 9 +-------- selfprivacy_api/services/pleroma/__init__.py | 15 +-------------- 6 files changed, 18 insertions(+), 54 deletions(-) diff --git a/selfprivacy_api/services/bitwarden/__init__.py b/selfprivacy_api/services/bitwarden/__init__.py index 56eb0fd..6842af6 100644 --- a/selfprivacy_api/services/bitwarden/__init__.py +++ b/selfprivacy_api/services/bitwarden/__init__.py @@ -154,15 +154,7 @@ class Bitwarden(Service): self, volume, job, - [ - FolderMoveNames( - name=Bitwarden.get_foldername(folder), - bind_location=folder, - group="vaultwarden", - owner="vaultwarden", - ) - for folder in Bitwarden.get_folders() - ], + FolderMoveNames.default_foldermoves(self), "bitwarden", ) diff --git a/selfprivacy_api/services/generic_service_mover.py b/selfprivacy_api/services/generic_service_mover.py index 1e5efe6..e2b26f4 100644 --- a/selfprivacy_api/services/generic_service_mover.py +++ b/selfprivacy_api/services/generic_service_mover.py @@ -34,6 +34,15 @@ class FolderMoveNames(BaseModel): def get_foldername(path: str) -> str: return path.split("/")[-1] + @staticmethod + def default_foldermoves(service: Service): + return ( + [ + FolderMoveNames.from_owned_path(folder) + for folder in service.get_owned_folders() + ], + ) + @huey.task() def move_service( diff --git a/selfprivacy_api/services/gitea/__init__.py b/selfprivacy_api/services/gitea/__init__.py index 707cdec..f9ff3d2 100644 --- a/selfprivacy_api/services/gitea/__init__.py +++ b/selfprivacy_api/services/gitea/__init__.py @@ -148,15 +148,7 @@ class Gitea(Service): self, volume, job, - [ - FolderMoveNames( - name=Gitea.get_foldername(folder), - bind_location=folder, - group="gitea", - owner="gitea", - ) - for folder in Gitea.get_folders() - ], + FolderMoveNames.default_foldermoves(self), "gitea", ) diff --git a/selfprivacy_api/services/mailserver/__init__.py b/selfprivacy_api/services/mailserver/__init__.py index eb69ae9..b0a6e30 100644 --- a/selfprivacy_api/services/mailserver/__init__.py +++ b/selfprivacy_api/services/mailserver/__init__.py @@ -37,6 +37,10 @@ class MailServer(Service): def get_svg_icon() -> str: return base64.b64encode(MAILSERVER_ICON.encode("utf-8")).decode("utf-8") + @staticmethod + def get_user() -> str: + return "virtualMail" + @staticmethod def get_url() -> typing.Optional[str]: """Return service url.""" @@ -158,20 +162,7 @@ class MailServer(Service): self, volume, job, - [ - FolderMoveNames( - name="vmail", - bind_location="/var/vmail", - group="virtualMail", - owner="virtualMail", - ), - FolderMoveNames( - name="sieve", - bind_location="/var/sieve", - group="virtualMail", - owner="virtualMail", - ), - ], + FolderMoveNames.default_foldermoves(self), "mailserver", ) diff --git a/selfprivacy_api/services/nextcloud/__init__.py b/selfprivacy_api/services/nextcloud/__init__.py index 0036c77..ae81403 100644 --- a/selfprivacy_api/services/nextcloud/__init__.py +++ b/selfprivacy_api/services/nextcloud/__init__.py @@ -152,14 +152,7 @@ class Nextcloud(Service): self, volume, job, - [ - FolderMoveNames( - name="nextcloud", - bind_location="/var/lib/nextcloud", - owner="nextcloud", - group="nextcloud", - ), - ], + FolderMoveNames.default_foldermoves(self), "nextcloud", ) return job diff --git a/selfprivacy_api/services/pleroma/__init__.py b/selfprivacy_api/services/pleroma/__init__.py index f7e185b..0d5b338 100644 --- a/selfprivacy_api/services/pleroma/__init__.py +++ b/selfprivacy_api/services/pleroma/__init__.py @@ -150,20 +150,7 @@ class Pleroma(Service): self, volume, job, - [ - FolderMoveNames( - name="pleroma", - bind_location="/var/lib/pleroma", - owner="pleroma", - group="pleroma", - ), - FolderMoveNames( - name="postgresql", - bind_location="/var/lib/postgresql", - owner="postgres", - group="postgres", - ), - ], + FolderMoveNames.default_foldermoves(self), "pleroma", ) return job