strawberry init

This commit is contained in:
inexcode 2022-06-24 15:26:51 +03:00
parent c30e062210
commit 75e3143c82
9 changed files with 162 additions and 1 deletions

View file

@ -6,5 +6,7 @@
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
"python.testing.pytestEnabled": true,
"python.languageServer": "Pylance",
"python.analysis.typeCheckingMode": "basic"
}

View file

View file

@ -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

View file

@ -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]

View file

@ -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"

View file

@ -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

View file

@ -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 {

12
strawberry-graphql.patch Normal file
View file

@ -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"