diff --git a/.vscode/settings.json b/.vscode/settings.json index ccb092d..8f927dc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,5 +6,7 @@ "tests" ], "python.testing.unittestEnabled": false, - "python.testing.pytestEnabled": true + "python.testing.pytestEnabled": true, + "python.languageServer": "Pylance", + "python.analysis.typeCheckingMode": "basic" } \ No newline at end of file diff --git a/selfprivacy_api/graphql/__init__.py b/selfprivacy_api/graphql/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/selfprivacy_api/graphql/queries/__init__.py b/selfprivacy_api/graphql/queries/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/selfprivacy_api/graphql/queries/api.py b/selfprivacy_api/graphql/queries/api.py new file mode 100644 index 0000000..741a21e --- /dev/null +++ b/selfprivacy_api/graphql/queries/api.py @@ -0,0 +1,25 @@ +"""API access status""" +import datetime +import string +import typing +import strawberry + +@strawberry.type +class ApiDevice: + name: str + creation_date: datetime.datetime + is_caller: bool + +@strawberry.type +class ApiRecoveryKeyStatus: + exists: bool + valid: bool + creation_date: datetime.datetime + expiration_date: typing.Optional[datetime.datetime] + uses_left: typing.Optional[int] + +@strawberry.type +class Api: + version: str + devices: typing.List[ApiDevice] + recovery_key: ApiRecoveryKeyStatus diff --git a/selfprivacy_api/graphql/queries/common.py b/selfprivacy_api/graphql/queries/common.py new file mode 100644 index 0000000..9c9c1cb --- /dev/null +++ b/selfprivacy_api/graphql/queries/common.py @@ -0,0 +1,26 @@ +"""Common types and enums used by different types of queries.""" +from enum import Enum +import datetime +import typing +import strawberry + +@strawberry.enum +class Severity(Enum): + """ + Severity of an alert. + """ + INFO = "INFO" + WARNING = "WARNING" + ERROR = "ERROR" + CRITICAL = "CRITICAL" + SUCCESS = "SUCCESS" + +@strawberry.type +class Alert: + """ + Alert type. + """ + severity: Severity + title: str + message: str + timestamp: typing.Optional[datetime.datetime] diff --git a/selfprivacy_api/graphql/queries/providers.py b/selfprivacy_api/graphql/queries/providers.py new file mode 100644 index 0000000..6d61bac --- /dev/null +++ b/selfprivacy_api/graphql/queries/providers.py @@ -0,0 +1,13 @@ +"""Enums representing different service providers.""" +from enum import Enum +import datetime +import typing +import strawberry + +@strawberry.enum +class DnsProvider(Enum): + CLOUDFLARE = "CLOUDFLARE" + +@strawberry.enum +class ServerProvider(Enum): + HETZNER = "HETZNER" diff --git a/selfprivacy_api/graphql/queries/system.py b/selfprivacy_api/graphql/queries/system.py new file mode 100644 index 0000000..5ab3a36 --- /dev/null +++ b/selfprivacy_api/graphql/queries/system.py @@ -0,0 +1,59 @@ +import typing +import strawberry + +from selfprivacy_api.graphql.queries.common import Alert +from selfprivacy_api.graphql.queries.providers import DnsProvider, ServerProvider + +@strawberry.type +class DnsRecord: + recordType: str + name: str + content: str + ttl: int + priority: typing.Optional[int] + +@strawberry.type +class SystemDomainInfo: + domain: str + hostname: str + provider: DnsProvider + required_dns_records: typing.List[DnsRecord] + +@strawberry.type +class AutoUpgradeOptions: + enable: bool + allow_reboot: bool + +@strawberry.type +class SshSettings: + enable: bool + password_authentication: bool + root_ssh_keys: typing.List[str] + +@strawberry.type +class SystemSettings: + auto_upgrade: AutoUpgradeOptions + ssh: SshSettings + timezone: str + +@strawberry.type +class SystemInfo: + system_version: str + python_version: str + +@strawberry.type +class SystemProviderInfo: + provider: ServerProvider + id: str + +@strawberry.type +class System: + """ + Base system type which represents common system status + """ + status: Alert + domain: SystemDomainInfo + settings: SystemSettings + info: SystemInfo + provider: SystemProviderInfo + busy: bool \ No newline at end of file diff --git a/shell.nix b/shell.nix index 79f3623..947af0b 100644 --- a/shell.nix +++ b/shell.nix @@ -16,6 +16,30 @@ let mnemonic coverage pylint + pydantic + typing-extensions + (buildPythonPackage rec { + pname = "strawberry-graphql"; + version = "0.114.5"; + format = "pyproject"; + patches = [ + ./strawberry-graphql.patch + ]; + propagatedBuildInputs = [ + typing-extensions + graphql-core + python-multipart + python-dateutil + flask + pydantic + pygments + poetry + ]; + src = fetchPypi { + inherit pname version; + sha256 = "b6e007281cf29a66eeba66a512744853d8aa53b4ca2525befb6f350bb7b24df6"; + }; + }) ]); in pkgs.mkShell { diff --git a/strawberry-graphql.patch b/strawberry-graphql.patch new file mode 100644 index 0000000..48a04d4 --- /dev/null +++ b/strawberry-graphql.patch @@ -0,0 +1,12 @@ +diff --git a/pyproject.toml b/pyproject.toml +index 3283fce..89d3e8c 100644 +--- a/pyproject.toml ++++ b/pyproject.toml +@@ -45,7 +45,6 @@ python-multipart = "^0.0.5" + sanic = {version = ">=20.12.2,<22.0.0", optional = true} + aiohttp = {version = "^3.7.4.post0", optional = true} + fastapi = {version = ">=0.65.2", optional = true} +-"backports.cached-property" = "^1.0.1" + + [tool.poetry.dev-dependencies] + pytest = "^7.1"