2022-08-25 17:03:56 +00:00
|
|
|
"""Class representing Bitwarden service"""
|
|
|
|
import base64
|
|
|
|
import subprocess
|
2024-03-01 00:21:31 +00:00
|
|
|
from typing import Optional, List
|
2022-08-25 17:03:56 +00:00
|
|
|
|
|
|
|
from selfprivacy_api.jobs import Job, Jobs
|
|
|
|
from selfprivacy_api.services.generic_service_mover import FolderMoveNames, move_service
|
|
|
|
from selfprivacy_api.services.generic_status_getter import get_service_status
|
2024-03-01 00:21:31 +00:00
|
|
|
from selfprivacy_api.services.service import Service, ServiceStatus
|
|
|
|
from selfprivacy_api.utils import get_domain
|
2022-08-25 17:03:56 +00:00
|
|
|
from selfprivacy_api.utils.block_devices import BlockDevice
|
|
|
|
from selfprivacy_api.services.gitea.icon import GITEA_ICON
|
|
|
|
|
|
|
|
|
|
|
|
class Gitea(Service):
|
|
|
|
"""Class representing Gitea service"""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_id() -> str:
|
|
|
|
"""Return service id."""
|
|
|
|
return "gitea"
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_display_name() -> str:
|
|
|
|
"""Return service display name."""
|
|
|
|
return "Gitea"
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_description() -> str:
|
|
|
|
"""Return service description."""
|
|
|
|
return "Gitea is a Git forge."
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_svg_icon() -> str:
|
|
|
|
"""Read SVG icon from file and return it as base64 encoded string."""
|
|
|
|
return base64.b64encode(GITEA_ICON.encode("utf-8")).decode("utf-8")
|
|
|
|
|
|
|
|
@staticmethod
|
2024-03-01 00:21:31 +00:00
|
|
|
def get_url() -> Optional[str]:
|
2022-08-25 17:03:56 +00:00
|
|
|
"""Return service url."""
|
|
|
|
domain = get_domain()
|
|
|
|
return f"https://git.{domain}"
|
|
|
|
|
2024-03-01 00:21:31 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_subdomain() -> Optional[str]:
|
|
|
|
return "git"
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def is_movable() -> bool:
|
|
|
|
return True
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_required() -> bool:
|
|
|
|
return False
|
|
|
|
|
2023-06-29 11:27:08 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_backup_description() -> str:
|
|
|
|
return "Git repositories, database and user data."
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_status() -> ServiceStatus:
|
|
|
|
"""
|
|
|
|
Return Gitea status from systemd.
|
|
|
|
Use command return code to determine status.
|
|
|
|
Return code 0 means service is running.
|
|
|
|
Return code 1 or 2 means service is in error stat.
|
|
|
|
Return code 3 means service is stopped.
|
|
|
|
Return code 4 means service is off.
|
|
|
|
"""
|
|
|
|
return get_service_status("gitea.service")
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def stop():
|
|
|
|
subprocess.run(["systemctl", "stop", "gitea.service"])
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def start():
|
|
|
|
subprocess.run(["systemctl", "start", "gitea.service"])
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def restart():
|
|
|
|
subprocess.run(["systemctl", "restart", "gitea.service"])
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_configuration():
|
|
|
|
return {}
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def set_configuration(config_items):
|
|
|
|
return super().set_configuration(config_items)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_logs():
|
|
|
|
return ""
|
|
|
|
|
2023-04-17 12:48:11 +00:00
|
|
|
@staticmethod
|
2024-03-01 00:21:31 +00:00
|
|
|
def get_folders() -> List[str]:
|
2023-04-17 12:48:11 +00:00
|
|
|
return ["/var/lib/gitea"]
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
def move_to_volume(self, volume: BlockDevice) -> Job:
|
2022-10-27 14:01:11 +00:00
|
|
|
job = Jobs.add(
|
2022-08-25 17:03:56 +00:00
|
|
|
type_id="services.gitea.move",
|
|
|
|
name="Move Gitea",
|
|
|
|
description=f"Moving Gitea data to {volume.name}",
|
|
|
|
)
|
|
|
|
|
|
|
|
move_service(
|
|
|
|
self,
|
|
|
|
volume,
|
|
|
|
job,
|
2023-04-19 12:43:47 +00:00
|
|
|
FolderMoveNames.default_foldermoves(self),
|
2022-09-19 00:50:43 +00:00
|
|
|
"gitea",
|
2022-08-25 17:03:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return job
|