2023-01-23 11:15:05 +00:00
|
|
|
"""Backup"""
|
|
|
|
# pylint: disable=too-few-public-methods
|
|
|
|
import typing
|
|
|
|
import strawberry
|
2023-05-29 16:12:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
@strawberry.type
|
|
|
|
class BackupConfiguration:
|
|
|
|
provider: BackupProvider
|
|
|
|
# When server is lost, the app should have the key to decrypt backups on a new server
|
|
|
|
encryption_key: str
|
2023-06-13 20:54:02 +00:00
|
|
|
# False when repo is not initialized and not ready to be used
|
|
|
|
is_initialized: bool
|
2023-05-29 16:12:22 +00:00
|
|
|
# If none, autobackups are disabled
|
2023-06-13 21:43:01 +00:00
|
|
|
autobackup_period: typing.Optional[int]
|
2023-05-29 16:12:22 +00:00
|
|
|
# Bucket name for Backblaze, path for some other providers
|
2023-06-13 21:43:01 +00:00
|
|
|
location_name: typing.Optional[str]
|
|
|
|
location_id: typing.Optional[str]
|
2023-01-23 11:15:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
@strawberry.type
|
|
|
|
class Backup:
|
2023-05-29 16:12:22 +00:00
|
|
|
@strawberry.field
|
2023-06-13 21:43:01 +00:00
|
|
|
def configuration(self) -> BackupConfiguration:
|
|
|
|
encryption_key = LocalBackupSecret.get()
|
|
|
|
return BackupConfiguration(
|
|
|
|
provider=BackupProvider[Backups.provider().name],
|
|
|
|
encryption_key=encryption_key.decode() if encryption_key else "",
|
|
|
|
is_initialized=Backups.is_initted(),
|
|
|
|
autobackup_period=Backups.autobackup_period_minutes(),
|
|
|
|
location_name=Backups.provider().location,
|
|
|
|
location_id=Backups.provider().repo_id,
|
|
|
|
)
|
2023-01-23 11:15:05 +00:00
|
|
|
|
|
|
|
@strawberry.field
|
2023-05-29 16:12:22 +00:00
|
|
|
def all_snapshots(self) -> typing.List[SnapshotInfo]:
|
2023-06-05 11:36:58 +00:00
|
|
|
result = []
|
|
|
|
snapshots = Backups.get_all_snapshots()
|
|
|
|
for snap in snapshots:
|
|
|
|
graphql_snap = SnapshotInfo(
|
|
|
|
id=snap.id, service=snap.service_name, created_at=snap.created_at
|
|
|
|
)
|
|
|
|
result.append(graphql_snap)
|
|
|
|
return result
|