mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-23 01:06:43 +00:00
fix(backups): Handle orphaned snapshots
This commit is contained in:
parent
421c92d12e
commit
93b98cd4fd
|
@ -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:
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
import datetime
|
||||
import strawberry
|
||||
|
||||
|
||||
@strawberry.type
|
||||
class SnapshotInfo:
|
||||
id: str
|
||||
service_name: str
|
||||
created_at: datetime.datetime
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue