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
|
|
|
|
2024-07-02 19:35:28 +00:00
|
|
|
from selfprivacy_api.utils import get_domain, ReadUserData, WriteUserData
|
2024-02-18 23:58:00 +00:00
|
|
|
|
2024-03-05 08:55:52 +00:00
|
|
|
from selfprivacy_api.utils.systemd import get_service_status
|
2024-03-01 00:21:31 +00:00
|
|
|
from selfprivacy_api.services.service import Service, ServiceStatus
|
2024-06-30 19:02:07 +00:00
|
|
|
from selfprivacy_api.services.forgejo.icon import FORGEJO_ICON
|
2024-07-02 19:35:28 +00:00
|
|
|
from selfprivacy_api.services.config_item import (
|
2024-07-03 13:35:40 +00:00
|
|
|
StringServiceConfigItem,
|
|
|
|
BoolServiceConfigItem,
|
|
|
|
EnumServiceConfigItem,
|
|
|
|
ServiceConfigItem,
|
2024-07-02 19:35:28 +00:00
|
|
|
)
|
2022-08-25 17:03:56 +00:00
|
|
|
|
|
|
|
|
2024-06-30 19:02:07 +00:00
|
|
|
class Forgejo(Service):
|
|
|
|
"""Class representing Forgejo service.
|
|
|
|
|
|
|
|
Previously was Gitea, so some IDs are still called gitea for compatibility.
|
|
|
|
"""
|
2022-08-25 17:03:56 +00:00
|
|
|
|
2024-07-03 13:35:40 +00:00
|
|
|
config_items: dict[str, ServiceConfigItem] = {
|
|
|
|
"subdomain": StringServiceConfigItem(
|
2024-07-02 19:35:28 +00:00
|
|
|
id="subdomain",
|
|
|
|
default_value="git",
|
|
|
|
description="Subdomain",
|
|
|
|
regex=r"[A-Za-z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9]",
|
|
|
|
widget="subdomain",
|
|
|
|
),
|
2024-07-03 13:35:40 +00:00
|
|
|
"appName": StringServiceConfigItem(
|
2024-07-02 19:35:28 +00:00
|
|
|
id="appName",
|
|
|
|
default_value="SelfPrivacy git Service",
|
|
|
|
description="The name displayed in the web interface",
|
|
|
|
),
|
2024-07-03 13:35:40 +00:00
|
|
|
"enableLfs": BoolServiceConfigItem(
|
2024-07-02 19:35:28 +00:00
|
|
|
id="enableLfs",
|
|
|
|
default_value=True,
|
|
|
|
description="Enable Git LFS",
|
|
|
|
),
|
2024-07-03 13:35:40 +00:00
|
|
|
"forcePrivate": BoolServiceConfigItem(
|
2024-07-02 19:35:28 +00:00
|
|
|
id="forcePrivate",
|
|
|
|
default_value=False,
|
|
|
|
description="Force all new repositories to be private",
|
|
|
|
),
|
2024-07-03 13:35:40 +00:00
|
|
|
"disableRegistration": BoolServiceConfigItem(
|
2024-07-02 19:35:28 +00:00
|
|
|
id="disableRegistration",
|
|
|
|
default_value=False,
|
|
|
|
description="Disable registration of new users",
|
|
|
|
),
|
2024-07-03 13:35:40 +00:00
|
|
|
"requireSigninView": BoolServiceConfigItem(
|
2024-07-02 19:35:28 +00:00
|
|
|
id="requireSigninView",
|
|
|
|
default_value=False,
|
|
|
|
description="Require signin to view any page",
|
|
|
|
),
|
2024-07-03 13:35:40 +00:00
|
|
|
"defaultTheme": EnumServiceConfigItem(
|
2024-07-03 10:26:26 +00:00
|
|
|
id="defaultTheme",
|
|
|
|
default_value="forgejo-auto",
|
|
|
|
description="Default theme",
|
|
|
|
options=[
|
|
|
|
"forgejo-auto",
|
|
|
|
"forgejo-light",
|
|
|
|
"forgejo-dark",
|
|
|
|
"auto",
|
|
|
|
"gitea",
|
|
|
|
"arc-green",
|
|
|
|
],
|
|
|
|
),
|
2024-07-02 19:35:28 +00:00
|
|
|
}
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_id() -> str:
|
2024-06-30 19:02:07 +00:00
|
|
|
"""Return service id. For compatibility keep in gitea."""
|
2022-08-25 17:03:56 +00:00
|
|
|
return "gitea"
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_display_name() -> str:
|
|
|
|
"""Return service display name."""
|
2024-06-30 19:02:07 +00:00
|
|
|
return "Forgejo"
|
2022-08-25 17:03:56 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_description() -> str:
|
|
|
|
"""Return service description."""
|
2024-06-30 19:02:07 +00:00
|
|
|
return "Forgejo is a Git forge."
|
2022-08-25 17:03:56 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_svg_icon() -> str:
|
|
|
|
"""Read SVG icon from file and return it as base64 encoded string."""
|
2024-06-30 19:02:07 +00:00
|
|
|
return base64.b64encode(FORGEJO_ICON.encode("utf-8")).decode("utf-8")
|
2022-08-25 17:03:56 +00:00
|
|
|
|
|
|
|
@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.
|
|
|
|
"""
|
2024-06-30 19:02:07 +00:00
|
|
|
return get_service_status("forgejo.service")
|
2022-08-25 17:03:56 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def stop():
|
2024-06-30 19:02:07 +00:00
|
|
|
subprocess.run(["systemctl", "stop", "forgejo.service"])
|
2022-08-25 17:03:56 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def start():
|
2024-06-30 19:02:07 +00:00
|
|
|
subprocess.run(["systemctl", "start", "forgejo.service"])
|
2022-08-25 17:03:56 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def restart():
|
2024-06-30 19:02:07 +00:00
|
|
|
subprocess.run(["systemctl", "restart", "forgejo.service"])
|
2022-08-25 17:03:56 +00:00
|
|
|
|
2024-07-02 19:35:28 +00:00
|
|
|
@classmethod
|
|
|
|
def get_configuration(cls):
|
|
|
|
with ReadUserData() as user_data:
|
|
|
|
return {
|
|
|
|
key: cls.config_items[key].as_dict(
|
|
|
|
user_data.get("modules", {}).get(cls.get_id(), {})
|
|
|
|
)
|
|
|
|
for key in cls.config_items
|
|
|
|
}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_configuration(cls, config_items):
|
|
|
|
with WriteUserData() as user_data:
|
|
|
|
if "modules" not in user_data:
|
|
|
|
user_data["modules"] = {}
|
|
|
|
if cls.get_id() not in user_data["modules"]:
|
|
|
|
user_data["modules"][cls.get_id()] = {}
|
|
|
|
for key, value in config_items.items():
|
|
|
|
cls.config_items[key].set_value(
|
|
|
|
value,
|
|
|
|
user_data["modules"][cls.get_id()],
|
|
|
|
)
|
2022-08-25 17:03:56 +00:00
|
|
|
|
|
|
|
@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]:
|
2024-06-30 19:02:07 +00:00
|
|
|
"""The data folder is still called gitea for compatibility."""
|
2023-04-17 12:48:11 +00:00
|
|
|
return ["/var/lib/gitea"]
|