mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-17 16:09:14 +00:00
feature(backups): actually dealing with situation when the provider is not configured
This commit is contained in:
parent
cd32aa83b7
commit
9f096ed2c0
|
@ -168,38 +168,47 @@ class Backups:
|
|||
if redis_provider is not None:
|
||||
return redis_provider
|
||||
|
||||
json_provider = Backups.load_provider_json()
|
||||
try:
|
||||
json_provider = Backups.load_provider_json()
|
||||
except FileNotFoundError:
|
||||
json_provider = None
|
||||
|
||||
if json_provider is not None:
|
||||
Storage.store_provider(json_provider)
|
||||
return json_provider
|
||||
|
||||
memory_provider = Backups.construct_provider("MEMORY", login="", key="")
|
||||
Storage.store_provider(memory_provider)
|
||||
return memory_provider
|
||||
none_provider = Backups.construct_provider(
|
||||
"NONE", login="", key="", location=""
|
||||
)
|
||||
Storage.store_provider(none_provider)
|
||||
return none_provider
|
||||
|
||||
@staticmethod
|
||||
def load_provider_json() -> AbstractBackupProvider:
|
||||
def load_provider_json() -> Optional[AbstractBackupProvider]:
|
||||
with ReadUserData() as user_data:
|
||||
account = ""
|
||||
key = ""
|
||||
provider_dict = {
|
||||
"provider": "",
|
||||
"accountId": "",
|
||||
"accountKey": "",
|
||||
"bucket": "",
|
||||
}
|
||||
|
||||
if "backup" not in user_data.keys():
|
||||
if "backblaze" in user_data.keys():
|
||||
account = user_data["backblaze"]["accountId"]
|
||||
key = user_data["backblaze"]["accountKey"]
|
||||
location = user_data["backblaze"]["bucket"]
|
||||
provider_string = "BACKBLAZE"
|
||||
return Backups.construct_provider(
|
||||
kind=provider_string, login=account, key=key, location=location
|
||||
)
|
||||
provider_dict.update(user_data["backblaze"])
|
||||
provider_dict["provider"] = "BACKBLAZE"
|
||||
return None
|
||||
else:
|
||||
provider_dict.update(user_data["backup"])
|
||||
|
||||
if provider_dict == DEFAULT_JSON_PROVIDER:
|
||||
return None
|
||||
|
||||
account = user_data["backup"]["accountId"]
|
||||
key = user_data["backup"]["accountKey"]
|
||||
provider_string = user_data["backup"]["provider"]
|
||||
location = user_data["backup"]["bucket"]
|
||||
return Backups.construct_provider(
|
||||
kind=provider_string, login=account, key=key, location=location
|
||||
kind=provider_dict["provider"],
|
||||
login=provider_dict["accountId"],
|
||||
key=provider_dict["accountKey"],
|
||||
location=provider_dict["bucket"],
|
||||
)
|
||||
|
||||
def reset_provider_json() -> AbstractBackupProvider:
|
||||
|
|
|
@ -9,7 +9,11 @@ class AbstractBackuper(ABC):
|
|||
pass
|
||||
|
||||
@abstractmethod
|
||||
def is_initted(self, repo_name: str) -> bool:
|
||||
def is_initted(self) -> bool:
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def set_creds(self, account: str, key: str, repo: str):
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
|
|
|
@ -5,9 +5,12 @@ from selfprivacy_api.backup.backuppers import AbstractBackuper
|
|||
|
||||
|
||||
class NoneBackupper(AbstractBackuper):
|
||||
def is_initted(self, repo_name: str) -> bool:
|
||||
def is_initted(self, repo_name: str = "") -> bool:
|
||||
return False
|
||||
|
||||
def set_creds(self, account: str, key: str, repo: str):
|
||||
pass
|
||||
|
||||
def start_backup(self, folders: List[str], repo_name: str):
|
||||
raise NotImplementedError
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ from selfprivacy_api.backup.backuppers.none_backupper import NoneBackupper
|
|||
class AbstractBackupProvider(ABC):
|
||||
@property
|
||||
def backuper(self) -> AbstractBackuper:
|
||||
return NoneBackupper
|
||||
return NoneBackupper()
|
||||
|
||||
name = "NONE"
|
||||
|
||||
|
|
|
@ -230,7 +230,7 @@ def test_remove(authorized_client, generic_userdata):
|
|||
assert_ok(data)
|
||||
|
||||
configuration = data["configuration"]
|
||||
assert configuration["provider"] == "BACKBLAZE"
|
||||
assert configuration["provider"] == "NONE"
|
||||
assert configuration["locationId"] == ""
|
||||
assert configuration["locationName"] == ""
|
||||
# still generated every time it is missing
|
||||
|
|
|
@ -15,6 +15,7 @@ from selfprivacy_api.backup import Backups
|
|||
import selfprivacy_api.backup.providers as providers
|
||||
from selfprivacy_api.backup.providers import AbstractBackupProvider
|
||||
from selfprivacy_api.backup.providers.backblaze import Backblaze
|
||||
|
||||
from selfprivacy_api.backup.tasks import start_backup, restore_snapshot
|
||||
from selfprivacy_api.backup.storage import Storage
|
||||
from selfprivacy_api.backup.jobs import get_backup_job
|
||||
|
@ -126,7 +127,7 @@ def test_json_reset(generic_userdata):
|
|||
Backups.reset()
|
||||
provider = Backups.provider()
|
||||
assert provider is not None
|
||||
assert isinstance(provider, Backblaze)
|
||||
assert isinstance(provider, AbstractBackupProvider)
|
||||
assert provider.login == ""
|
||||
assert provider.key == ""
|
||||
assert provider.location == ""
|
||||
|
|
Loading…
Reference in a new issue