fix(backups): try to actually get backup configuration

pull/35/head
Inex Code 2023-06-14 00:43:01 +03:00
parent f77556b60e
commit c603394449
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): class Backblaze(AbstractBackupProvider):
backuper = ResticBackuper("--b2-account", "--b2-key", ":b2:") 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): class LocalFileBackup(AbstractBackupProvider):
backuper = ResticBackuper("", "", "memory") backuper = ResticBackuper("", "", "memory")
name = "FILE"
# login and key args are for compatibility with generic provider methods. They are ignored. # login and key args are for compatibility with generic provider methods. They are ignored.
def __init__(self, filename: str, login: str = "", key: str = ""): def __init__(self, filename: str, login: str = "", key: str = ""):
super().__init__() super().__init__()

View File

@ -4,3 +4,5 @@ from selfprivacy_api.backup.restic_backuper import ResticBackuper
class InMemoryBackup(AbstractBackupProvider): class InMemoryBackup(AbstractBackupProvider):
backuper = ResticBackuper("", "", ":memory:") 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 # False when repo is not initialized and not ready to be used
is_initialized: bool is_initialized: bool
# If none, autobackups are disabled # 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 # Bucket name for Backblaze, path for some other providers
location_name: typing.Optional[str] = None location_name: typing.Optional[str]
location_id: typing.Optional[str] = None location_id: typing.Optional[str]
@strawberry.type @strawberry.type
class Backup: class Backup:
@strawberry.field @strawberry.field
def configuration() -> BackupConfiguration: def configuration(self) -> BackupConfiguration:
config = BackupConfiguration() encryption_key = LocalBackupSecret.get()
config.encryption_key = LocalBackupSecret.get() return BackupConfiguration(
config.is_initialized = Backups.is_initted() provider=BackupProvider[Backups.provider().name],
config.autobackup_period = Backups.autobackup_period_minutes() encryption_key=encryption_key.decode() if encryption_key else "",
config.location_name = Backups.provider().location is_initialized=Backups.is_initted(),
config.location_id = Backups.provider().repo_id autobackup_period=Backups.autobackup_period_minutes(),
location_name=Backups.provider().location,
location_id=Backups.provider().repo_id,
)
@strawberry.field @strawberry.field
def all_snapshots(self) -> typing.List[SnapshotInfo]: def all_snapshots(self) -> typing.List[SnapshotInfo]:

View File

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