2022-06-24 13:05:18 +00:00
|
|
|
"""Common system information and settings"""
|
|
|
|
# pylint: disable=too-few-public-methods
|
2022-06-24 12:26:51 +00:00
|
|
|
import typing
|
|
|
|
import strawberry
|
|
|
|
|
2022-06-24 18:18:21 +00:00
|
|
|
from selfprivacy_api.graphql.queries.common import Alert, Severity
|
2022-06-24 12:26:51 +00:00
|
|
|
from selfprivacy_api.graphql.queries.providers import DnsProvider, ServerProvider
|
2022-06-24 18:14:20 +00:00
|
|
|
from selfprivacy_api.utils import ReadUserData
|
2022-08-10 23:36:36 +00:00
|
|
|
import selfprivacy_api.actions.system as system_actions
|
|
|
|
import selfprivacy_api.actions.ssh as ssh_actions
|
2022-06-24 18:14:20 +00:00
|
|
|
|
2022-06-24 12:26:51 +00:00
|
|
|
|
|
|
|
@strawberry.type
|
|
|
|
class DnsRecord:
|
2022-06-24 13:05:18 +00:00
|
|
|
"""DNS record"""
|
2022-06-24 18:14:20 +00:00
|
|
|
|
2022-06-24 12:26:51 +00:00
|
|
|
recordType: str
|
|
|
|
name: str
|
|
|
|
content: str
|
|
|
|
ttl: int
|
|
|
|
priority: typing.Optional[int]
|
|
|
|
|
2022-06-24 18:14:20 +00:00
|
|
|
|
2022-06-24 12:26:51 +00:00
|
|
|
@strawberry.type
|
|
|
|
class SystemDomainInfo:
|
2022-06-24 13:05:18 +00:00
|
|
|
"""Information about the system domain"""
|
2022-06-24 18:14:20 +00:00
|
|
|
|
2022-06-24 12:26:51 +00:00
|
|
|
domain: str
|
|
|
|
hostname: str
|
|
|
|
provider: DnsProvider
|
|
|
|
required_dns_records: typing.List[DnsRecord]
|
|
|
|
|
2022-06-24 18:14:20 +00:00
|
|
|
|
|
|
|
def get_system_domain_info() -> SystemDomainInfo:
|
|
|
|
"""Get basic system domain info"""
|
|
|
|
with ReadUserData() as user_data:
|
|
|
|
return SystemDomainInfo(
|
|
|
|
domain=user_data["domain"],
|
|
|
|
hostname=user_data["hostname"],
|
|
|
|
provider=DnsProvider.CLOUDFLARE,
|
|
|
|
# TODO: get ip somehow
|
|
|
|
required_dns_records=[],
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-06-24 12:26:51 +00:00
|
|
|
@strawberry.type
|
|
|
|
class AutoUpgradeOptions:
|
2022-06-24 13:05:18 +00:00
|
|
|
"""Automatic upgrade options"""
|
2022-06-24 18:14:20 +00:00
|
|
|
|
2022-06-24 12:26:51 +00:00
|
|
|
enable: bool
|
|
|
|
allow_reboot: bool
|
|
|
|
|
2022-06-24 18:14:20 +00:00
|
|
|
|
|
|
|
def get_auto_upgrade_options() -> AutoUpgradeOptions:
|
|
|
|
"""Get automatic upgrade options"""
|
2022-08-10 23:36:36 +00:00
|
|
|
settings = system_actions.get_auto_upgrade_settings()
|
|
|
|
return AutoUpgradeOptions(
|
|
|
|
enable=settings.enable,
|
|
|
|
allow_reboot=settings.allowReboot,
|
|
|
|
)
|
2022-06-24 18:14:20 +00:00
|
|
|
|
|
|
|
|
2022-06-24 12:26:51 +00:00
|
|
|
@strawberry.type
|
|
|
|
class SshSettings:
|
2022-06-24 13:05:18 +00:00
|
|
|
"""SSH settings and root SSH keys"""
|
2022-06-24 18:14:20 +00:00
|
|
|
|
2022-06-24 12:26:51 +00:00
|
|
|
enable: bool
|
|
|
|
password_authentication: bool
|
|
|
|
root_ssh_keys: typing.List[str]
|
|
|
|
|
2022-06-24 18:14:20 +00:00
|
|
|
|
|
|
|
def get_ssh_settings() -> SshSettings:
|
|
|
|
"""Get SSH settings"""
|
2022-08-10 23:36:36 +00:00
|
|
|
settings = ssh_actions.get_ssh_settings()
|
|
|
|
return SshSettings(
|
|
|
|
enable=settings.enable,
|
|
|
|
password_authentication=settings.passwordAuthentication,
|
|
|
|
root_ssh_keys=settings.rootSshKeys,
|
|
|
|
)
|
2022-06-24 18:14:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_system_timezone() -> str:
|
|
|
|
"""Get system timezone"""
|
|
|
|
with ReadUserData() as user_data:
|
2022-08-10 23:36:36 +00:00
|
|
|
return system_actions.get_timezone()
|
2022-06-24 18:14:20 +00:00
|
|
|
|
|
|
|
|
2022-06-24 12:26:51 +00:00
|
|
|
@strawberry.type
|
|
|
|
class SystemSettings:
|
2022-06-24 13:05:18 +00:00
|
|
|
"""Common system settings"""
|
2022-06-24 18:14:20 +00:00
|
|
|
|
|
|
|
auto_upgrade: AutoUpgradeOptions = strawberry.field(
|
|
|
|
resolver=get_auto_upgrade_options
|
|
|
|
)
|
|
|
|
ssh: SshSettings = strawberry.field(resolver=get_ssh_settings)
|
|
|
|
timezone: str = strawberry.field(resolver=get_system_timezone)
|
|
|
|
|
|
|
|
|
|
|
|
def get_system_version() -> str:
|
|
|
|
"""Get system version"""
|
2022-08-10 23:36:36 +00:00
|
|
|
return system_actions.get_system_version()
|
2022-06-24 18:14:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_python_version() -> str:
|
|
|
|
"""Get Python version"""
|
2022-08-10 23:36:36 +00:00
|
|
|
return system_actions.get_python_version()
|
2022-06-24 18:14:20 +00:00
|
|
|
|
2022-06-24 12:26:51 +00:00
|
|
|
|
|
|
|
@strawberry.type
|
|
|
|
class SystemInfo:
|
2022-06-24 13:05:18 +00:00
|
|
|
"""System components versions"""
|
2022-06-24 18:14:20 +00:00
|
|
|
|
|
|
|
system_version: str = strawberry.field(resolver=get_system_version)
|
|
|
|
python_version: str = strawberry.field(resolver=get_python_version)
|
|
|
|
|
2022-06-24 12:26:51 +00:00
|
|
|
|
|
|
|
@strawberry.type
|
|
|
|
class SystemProviderInfo:
|
2022-06-24 13:05:18 +00:00
|
|
|
"""Information about the VPS/Dedicated server provider"""
|
2022-06-24 18:14:20 +00:00
|
|
|
|
2022-06-24 12:26:51 +00:00
|
|
|
provider: ServerProvider
|
|
|
|
id: str
|
|
|
|
|
2022-06-24 18:14:20 +00:00
|
|
|
|
|
|
|
def get_system_provider_info() -> SystemProviderInfo:
|
|
|
|
"""Get system provider info"""
|
|
|
|
return SystemProviderInfo(provider=ServerProvider.HETZNER, id="UNKNOWN")
|
|
|
|
|
|
|
|
|
2022-06-24 12:26:51 +00:00
|
|
|
@strawberry.type
|
|
|
|
class System:
|
|
|
|
"""
|
|
|
|
Base system type which represents common system status
|
|
|
|
"""
|
2022-06-24 18:14:20 +00:00
|
|
|
|
2022-07-07 13:53:19 +00:00
|
|
|
status: Alert = strawberry.field(
|
|
|
|
resolver=lambda: Alert(
|
|
|
|
severity=Severity.INFO,
|
|
|
|
title="Test message",
|
|
|
|
message="Test message",
|
|
|
|
timestamp=None,
|
|
|
|
)
|
|
|
|
)
|
2022-07-08 15:28:08 +00:00
|
|
|
domain_info: SystemDomainInfo = strawberry.field(resolver=get_system_domain_info)
|
2022-06-24 18:18:21 +00:00
|
|
|
settings: SystemSettings = SystemSettings()
|
|
|
|
info: SystemInfo = SystemInfo()
|
2022-06-24 18:14:20 +00:00
|
|
|
provider: SystemProviderInfo = strawberry.field(resolver=get_system_provider_info)
|
|
|
|
busy: bool = False
|