From f834c85401073a19b18bcafbda837d82f6e5f383 Mon Sep 17 00:00:00 2001 From: dettlaff Date: Sun, 16 Jun 2024 12:35:59 +0400 Subject: [PATCH] feat: rewrite get_url() --- selfprivacy_api/services/bitwarden/__init__.py | 8 -------- selfprivacy_api/services/gitea/__init__.py | 8 -------- selfprivacy_api/services/jitsimeet/__init__.py | 7 ------- selfprivacy_api/services/nextcloud/__init__.py | 7 ------- selfprivacy_api/services/pleroma/__init__.py | 8 -------- selfprivacy_api/services/roundcube/__init__.py | 8 -------- selfprivacy_api/services/service.py | 7 ++++--- 7 files changed, 4 insertions(+), 49 deletions(-) diff --git a/selfprivacy_api/services/bitwarden/__init__.py b/selfprivacy_api/services/bitwarden/__init__.py index 6c44aeb..5d27569 100644 --- a/selfprivacy_api/services/bitwarden/__init__.py +++ b/selfprivacy_api/services/bitwarden/__init__.py @@ -4,8 +4,6 @@ import base64 import subprocess from typing import Optional, List -from selfprivacy_api.utils import get_domain - from selfprivacy_api.utils.systemd import get_service_status from selfprivacy_api.services.service import Service, ServiceStatus from selfprivacy_api.services.bitwarden.icon import BITWARDEN_ICON @@ -38,12 +36,6 @@ class Bitwarden(Service): def get_user() -> str: return "vaultwarden" - @staticmethod - def get_url() -> Optional[str]: - """Return service url.""" - domain = get_domain() - return f"https://password.{domain}" - @staticmethod def is_movable() -> bool: return True diff --git a/selfprivacy_api/services/gitea/__init__.py b/selfprivacy_api/services/gitea/__init__.py index 7029b48..3247040 100644 --- a/selfprivacy_api/services/gitea/__init__.py +++ b/selfprivacy_api/services/gitea/__init__.py @@ -4,8 +4,6 @@ import base64 import subprocess from typing import Optional, List -from selfprivacy_api.utils import get_domain - from selfprivacy_api.utils.systemd import get_service_status from selfprivacy_api.services.service import Service, ServiceStatus from selfprivacy_api.services.gitea.icon import GITEA_ICON @@ -34,12 +32,6 @@ class Gitea(Service): """Read SVG icon from file and return it as base64 encoded string.""" return base64.b64encode(GITEA_ICON.encode("utf-8")).decode("utf-8") - @staticmethod - def get_url() -> Optional[str]: - """Return service url.""" - domain = get_domain() - return f"https://git.{domain}" - @staticmethod def is_movable() -> bool: return True diff --git a/selfprivacy_api/services/jitsimeet/__init__.py b/selfprivacy_api/services/jitsimeet/__init__.py index 05ef2f7..074c546 100644 --- a/selfprivacy_api/services/jitsimeet/__init__.py +++ b/selfprivacy_api/services/jitsimeet/__init__.py @@ -9,7 +9,6 @@ from selfprivacy_api.utils.systemd import ( get_service_status_from_several_units, ) from selfprivacy_api.services.service import Service, ServiceStatus -from selfprivacy_api.utils import get_domain from selfprivacy_api.utils.block_devices import BlockDevice from selfprivacy_api.services.jitsimeet.icon import JITSI_ICON @@ -37,12 +36,6 @@ class JitsiMeet(Service): """Read SVG icon from file and return it as base64 encoded string.""" return base64.b64encode(JITSI_ICON.encode("utf-8")).decode("utf-8") - @staticmethod - def get_url() -> Optional[str]: - """Return service url.""" - domain = get_domain() - return f"https://meet.{domain}" - @staticmethod def is_movable() -> bool: return False diff --git a/selfprivacy_api/services/nextcloud/__init__.py b/selfprivacy_api/services/nextcloud/__init__.py index 6aee771..eee9fa7 100644 --- a/selfprivacy_api/services/nextcloud/__init__.py +++ b/selfprivacy_api/services/nextcloud/__init__.py @@ -4,7 +4,6 @@ import base64 import subprocess from typing import Optional, List -from selfprivacy_api.utils import get_domain from selfprivacy_api.jobs import Job, Jobs from selfprivacy_api.utils.systemd import get_service_status @@ -36,12 +35,6 @@ class Nextcloud(Service): """Read SVG icon from file and return it as base64 encoded string.""" return base64.b64encode(NEXTCLOUD_ICON.encode("utf-8")).decode("utf-8") - @staticmethod - def get_url() -> Optional[str]: - """Return service url.""" - domain = get_domain() - return f"https://cloud.{domain}" - @staticmethod def is_movable() -> bool: return True diff --git a/selfprivacy_api/services/pleroma/__init__.py b/selfprivacy_api/services/pleroma/__init__.py index eebd925..16ee70c 100644 --- a/selfprivacy_api/services/pleroma/__init__.py +++ b/selfprivacy_api/services/pleroma/__init__.py @@ -4,8 +4,6 @@ import base64 import subprocess from typing import Optional, List -from selfprivacy_api.utils import get_domain - from selfprivacy_api.services.owned_path import OwnedPath from selfprivacy_api.utils.systemd import get_service_status from selfprivacy_api.services.service import Service, ServiceStatus @@ -32,12 +30,6 @@ class Pleroma(Service): def get_svg_icon() -> str: return base64.b64encode(PLEROMA_ICON.encode("utf-8")).decode("utf-8") - @staticmethod - def get_url() -> Optional[str]: - """Return service url.""" - domain = get_domain() - return f"https://social.{domain}" - @staticmethod def is_movable() -> bool: return True diff --git a/selfprivacy_api/services/roundcube/__init__.py b/selfprivacy_api/services/roundcube/__init__.py index 61a23ea..41bef32 100644 --- a/selfprivacy_api/services/roundcube/__init__.py +++ b/selfprivacy_api/services/roundcube/__init__.py @@ -9,7 +9,6 @@ from selfprivacy_api.utils.systemd import ( get_service_status_from_several_units, ) from selfprivacy_api.services.service import Service, ServiceStatus -from selfprivacy_api.utils import get_domain from selfprivacy_api.utils.block_devices import BlockDevice from selfprivacy_api.services.roundcube.icon import ROUNDCUBE_ICON @@ -37,13 +36,6 @@ class Roundcube(Service): """Read SVG icon from file and return it as base64 encoded string.""" return base64.b64encode(ROUNDCUBE_ICON.encode("utf-8")).decode("utf-8") - @staticmethod - def get_url() -> Optional[str]: - """Return service url.""" - domain = get_domain() - subdomain = get_subdomain() - return f"https://{subdomain}.{domain}" - @staticmethod def is_movable() -> bool: return False diff --git a/selfprivacy_api/services/service.py b/selfprivacy_api/services/service.py index 262d690..ed55a0e 100644 --- a/selfprivacy_api/services/service.py +++ b/selfprivacy_api/services/service.py @@ -4,6 +4,7 @@ from abc import ABC, abstractmethod from typing import List, Optional from selfprivacy_api import utils +from selfprivacy_api.utils import get_domain from selfprivacy_api.utils import ReadUserData, WriteUserData from selfprivacy_api.utils.waitloop import wait_until_true from selfprivacy_api.utils.block_devices import BlockDevice, BlockDevices @@ -66,13 +67,13 @@ class Service(ABC): """ pass - @staticmethod - @abstractmethod def get_url() -> Optional[str]: """ The url of the service if it is accessible from the internet browser. """ - pass + domain = get_domain() + subdomain = self.get_subdomain() + return f"https://{subdomain}.{domain}" def get_subdomain() -> Optional[str]: """