2022-08-25 17:03:56 +00:00
|
|
|
"""Class representing Bitwarden service"""
|
|
|
|
import base64
|
|
|
|
import subprocess
|
2024-07-23 14:05:29 +00:00
|
|
|
from typing import List
|
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
|
2022-08-25 17:03:56 +00:00
|
|
|
from selfprivacy_api.services.bitwarden.icon import BITWARDEN_ICON
|
2024-07-23 14:29:26 +00:00
|
|
|
from selfprivacy_api.services.config_item import (
|
|
|
|
StringServiceConfigItem,
|
|
|
|
BoolServiceConfigItem,
|
|
|
|
ServiceConfigItem,
|
|
|
|
)
|
|
|
|
from selfprivacy_api.utils.regex_strings import SUBDOMAIN_REGEX
|
2022-08-25 17:03:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Bitwarden(Service):
|
|
|
|
"""Class representing Bitwarden service."""
|
|
|
|
|
2024-07-23 14:29:26 +00:00
|
|
|
config_items: dict[str, ServiceConfigItem] = {
|
|
|
|
"subdomain": StringServiceConfigItem(
|
|
|
|
id="subdomain",
|
|
|
|
default_value="password",
|
|
|
|
description="Subdomain",
|
|
|
|
regex=SUBDOMAIN_REGEX,
|
|
|
|
widget="subdomain",
|
|
|
|
),
|
|
|
|
"signupsAllowed": BoolServiceConfigItem(
|
|
|
|
id="signupsAllowed",
|
|
|
|
default_value=True,
|
|
|
|
description="Allow new user signups",
|
|
|
|
),
|
|
|
|
"sendsAllowed": BoolServiceConfigItem(
|
|
|
|
id="sendsAllowed",
|
|
|
|
default_value=True,
|
|
|
|
description="Allow users to use Bitwarden Send",
|
|
|
|
),
|
|
|
|
"emergencyAccessAllowed": BoolServiceConfigItem(
|
|
|
|
id="emergencyAccessAllowed",
|
|
|
|
default_value=True,
|
|
|
|
description="Allow users to enable Emergency Access",
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_id() -> str:
|
|
|
|
"""Return service id."""
|
|
|
|
return "bitwarden"
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_display_name() -> str:
|
|
|
|
"""Return service display name."""
|
|
|
|
return "Bitwarden"
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_description() -> str:
|
|
|
|
"""Return service description."""
|
|
|
|
return "Bitwarden is a password manager."
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_svg_icon() -> str:
|
|
|
|
"""Read SVG icon from file and return it as base64 encoded string."""
|
|
|
|
return base64.b64encode(BITWARDEN_ICON.encode("utf-8")).decode("utf-8")
|
|
|
|
|
2023-04-19 11:34:14 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_user() -> str:
|
|
|
|
return "vaultwarden"
|
|
|
|
|
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 "Password database, encryption certificate and attachments."
|
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_status() -> ServiceStatus:
|
|
|
|
"""
|
|
|
|
Return Bitwarden 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("vaultwarden.service")
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def stop():
|
|
|
|
subprocess.run(["systemctl", "stop", "vaultwarden.service"])
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def start():
|
|
|
|
subprocess.run(["systemctl", "start", "vaultwarden.service"])
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def restart():
|
|
|
|
subprocess.run(["systemctl", "restart", "vaultwarden.service"])
|
|
|
|
|
2024-07-02 19:35:28 +00:00
|
|
|
@classmethod
|
|
|
|
def get_configuration(cls):
|
2022-08-25 17:03:56 +00:00
|
|
|
return {}
|
|
|
|
|
2024-07-02 19:35:28 +00:00
|
|
|
@classmethod
|
|
|
|
def set_configuration(cls, config_items):
|
2022-08-25 17:03:56 +00:00
|
|
|
return super().set_configuration(config_items)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_logs():
|
|
|
|
return ""
|
|
|
|
|
2023-04-17 12:33:27 +00:00
|
|
|
@staticmethod
|
2024-03-01 00:21:31 +00:00
|
|
|
def get_folders() -> List[str]:
|
2023-04-17 12:33:27 +00:00
|
|
|
return ["/var/lib/bitwarden", "/var/lib/bitwarden_rs"]
|