diff --git a/selfprivacy_api/backup/local_secret.py b/selfprivacy_api/backup/local_secret.py index 389f3a3..ea2afec 100644 --- a/selfprivacy_api/backup/local_secret.py +++ b/selfprivacy_api/backup/local_secret.py @@ -38,7 +38,7 @@ class LocalBackupSecret: @staticmethod def exists() -> bool: - return redis.exists(REDIS_KEY) + return redis.exists(REDIS_KEY) == 1 @staticmethod def _generate() -> str: diff --git a/selfprivacy_api/graphql/common_types/backup_snapshot.py b/selfprivacy_api/graphql/common_types/backup_snapshot.py deleted file mode 100644 index 3256e0c..0000000 --- a/selfprivacy_api/graphql/common_types/backup_snapshot.py +++ /dev/null @@ -1,9 +0,0 @@ -import datetime -import strawberry - - -@strawberry.type -class SnapshotInfo: - id: str - service_name: str - created_at: datetime.datetime diff --git a/selfprivacy_api/graphql/common_types/service.py b/selfprivacy_api/graphql/common_types/service.py index 9e04254..b3403e9 100644 --- a/selfprivacy_api/graphql/common_types/service.py +++ b/selfprivacy_api/graphql/common_types/service.py @@ -3,7 +3,6 @@ import typing import strawberry import datetime from selfprivacy_api.graphql.common_types.dns import DnsRecord -from selfprivacy_api.graphql.common_types.backup_snapshot import SnapshotInfo from selfprivacy_api.services import get_service_by_id, get_services_by_location from selfprivacy_api.services import Service as ServiceInterface @@ -104,14 +103,14 @@ class Service: return get_storage_usage(self) @strawberry.field - def backup_snapshots(self) -> typing.Optional[typing.List[SnapshotInfo]]: + def backup_snapshots(self) -> typing.Optional[typing.List["SnapshotInfo"]]: return None @strawberry.type class SnapshotInfo: id: str - service: "Service" + service: Service created_at: datetime.datetime diff --git a/selfprivacy_api/graphql/queries/backup.py b/selfprivacy_api/graphql/queries/backup.py index 2cc8d83..9858543 100644 --- a/selfprivacy_api/graphql/queries/backup.py +++ b/selfprivacy_api/graphql/queries/backup.py @@ -7,13 +7,20 @@ import strawberry from selfprivacy_api.backup import Backups from selfprivacy_api.backup.local_secret import LocalBackupSecret from selfprivacy_api.graphql.queries.providers import BackupProvider -from selfprivacy_api.graphql.common_types.service import SnapshotInfo +from selfprivacy_api.graphql.common_types.service import ( + Service, + ServiceStatusEnum, + SnapshotInfo, + service_to_graphql_service, +) +from selfprivacy_api.services import get_service_by_id @strawberry.type class BackupConfiguration: provider: BackupProvider - # When server is lost, the app should have the key to decrypt backups on a new server + # When server is lost, the app should have the key to decrypt backups + # on a new server encryption_key: str # False when repo is not initialized and not ready to be used is_initialized: bool @@ -39,11 +46,31 @@ class Backup: @strawberry.field def all_snapshots(self) -> typing.List[SnapshotInfo]: + if not Backups.is_initted(): + return [] result = [] snapshots = Backups.get_all_snapshots() for snap in snapshots: + service = get_service_by_id(snap.service_name) + if service is None: + service = Service( + id=snap.service_name, + display_name=f"{snap.service_name} (Orphaned)", + description="", + svg_icon="", + is_movable=False, + is_required=False, + is_enabled=False, + status=ServiceStatusEnum.OFF, + url=None, + dns_records=None, + ) + else: + service = service_to_graphql_service(service) graphql_snap = SnapshotInfo( - id=snap.id, service=snap.service_name, created_at=snap.created_at + id=snap.id, + service=service, + created_at=snap.created_at, ) result.append(graphql_snap) return result