selfprivacy-rest-api/selfprivacy_api/backup/providers/__init__.py

32 lines
1.1 KiB
Python
Raw Normal View History

2023-06-23 09:40:10 +00:00
from typing import Type
from selfprivacy_api.graphql.queries.providers import (
BackupProvider as BackupProviderEnum,
)
2023-02-01 11:58:55 +00:00
from selfprivacy_api.backup.providers.provider import AbstractBackupProvider
from selfprivacy_api.backup.providers.backblaze import Backblaze
2023-02-03 18:29:45 +00:00
from selfprivacy_api.backup.providers.memory import InMemoryBackup
from selfprivacy_api.backup.providers.local_file import LocalFileBackup
2023-06-23 09:40:10 +00:00
from selfprivacy_api.backup.providers.none import NoBackups
2023-02-01 11:58:55 +00:00
2023-06-23 09:40:10 +00:00
PROVIDER_MAPPING: dict[BackupProviderEnum, Type[AbstractBackupProvider]] = {
BackupProviderEnum.BACKBLAZE: Backblaze,
BackupProviderEnum.MEMORY: InMemoryBackup,
BackupProviderEnum.FILE: LocalFileBackup,
BackupProviderEnum.NONE: NoBackups,
2023-02-01 11:58:55 +00:00
}
2023-02-03 18:29:45 +00:00
2023-06-23 09:40:10 +00:00
def get_provider(
provider_type: BackupProviderEnum,
) -> Type[AbstractBackupProvider]:
if provider_type not in PROVIDER_MAPPING.keys():
raise LookupError("could not look up provider", provider_type)
2023-02-01 11:58:55 +00:00
return PROVIDER_MAPPING[provider_type]
def get_kind(provider: AbstractBackupProvider) -> str:
2023-06-23 09:40:10 +00:00
"""Get the kind of the provider in the form of a string"""
return provider.name.value