fix(backups): try to actually get backup configuration

This commit is contained in:
Inex Code 2023-06-14 00:43:01 +03:00
parent f950dd1e93
commit 0ef6569d97
5 changed files with 20 additions and 10 deletions

View file

@ -4,3 +4,5 @@ from selfprivacy_api.backup.restic_backuper import ResticBackuper
class Backblaze(AbstractBackupProvider):
backuper = ResticBackuper("--b2-account", "--b2-key", ":b2:")
name = "BACKBLAZE"

View file

@ -5,6 +5,8 @@ from selfprivacy_api.backup.restic_backuper import ResticBackuper
class LocalFileBackup(AbstractBackupProvider):
backuper = ResticBackuper("", "", "memory")
name = "FILE"
# login and key args are for compatibility with generic provider methods. They are ignored.
def __init__(self, filename: str, login: str = "", key: str = ""):
super().__init__()

View file

@ -4,3 +4,5 @@ from selfprivacy_api.backup.restic_backuper import ResticBackuper
class InMemoryBackup(AbstractBackupProvider):
backuper = ResticBackuper("", "", ":memory:")
name = "MEMORY"

View file

@ -18,22 +18,25 @@ class BackupConfiguration:
# False when repo is not initialized and not ready to be used
is_initialized: bool
# If none, autobackups are disabled
autobackup_period: typing.Optional[int] = None
autobackup_period: typing.Optional[int]
# Bucket name for Backblaze, path for some other providers
location_name: typing.Optional[str] = None
location_id: typing.Optional[str] = None
location_name: typing.Optional[str]
location_id: typing.Optional[str]
@strawberry.type
class Backup:
@strawberry.field
def configuration() -> BackupConfiguration:
config = BackupConfiguration()
config.encryption_key = LocalBackupSecret.get()
config.is_initialized = Backups.is_initted()
config.autobackup_period = Backups.autobackup_period_minutes()
config.location_name = Backups.provider().location
config.location_id = Backups.provider().repo_id
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,
)
@strawberry.field
def all_snapshots(self) -> typing.List[SnapshotInfo]:

View file

@ -19,6 +19,7 @@ class ServerProvider(Enum):
@strawberry.enum
class BackupProvider(Enum):
BACKBLAZE = "BACKBLAZE"
NONE = "NONE"
# for testing purposes, make sure not selectable in prod.
MEMORY = "MEMORY"
FILE = "FILE"