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:
|
if redis_provider is not None:
|
||||||
return redis_provider
|
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:
|
if json_provider is not None:
|
||||||
Storage.store_provider(json_provider)
|
Storage.store_provider(json_provider)
|
||||||
return json_provider
|
return json_provider
|
||||||
|
|
||||||
memory_provider = Backups.construct_provider("MEMORY", login="", key="")
|
none_provider = Backups.construct_provider(
|
||||||
Storage.store_provider(memory_provider)
|
"NONE", login="", key="", location=""
|
||||||
return memory_provider
|
)
|
||||||
|
Storage.store_provider(none_provider)
|
||||||
|
return none_provider
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load_provider_json() -> AbstractBackupProvider:
|
def load_provider_json() -> Optional[AbstractBackupProvider]:
|
||||||
with ReadUserData() as user_data:
|
with ReadUserData() as user_data:
|
||||||
account = ""
|
provider_dict = {
|
||||||
key = ""
|
"provider": "",
|
||||||
|
"accountId": "",
|
||||||
|
"accountKey": "",
|
||||||
|
"bucket": "",
|
||||||
|
}
|
||||||
|
|
||||||
if "backup" not in user_data.keys():
|
if "backup" not in user_data.keys():
|
||||||
if "backblaze" in user_data.keys():
|
if "backblaze" in user_data.keys():
|
||||||
account = user_data["backblaze"]["accountId"]
|
provider_dict.update(user_data["backblaze"])
|
||||||
key = user_data["backblaze"]["accountKey"]
|
provider_dict["provider"] = "BACKBLAZE"
|
||||||
location = user_data["backblaze"]["bucket"]
|
return None
|
||||||
provider_string = "BACKBLAZE"
|
else:
|
||||||
return Backups.construct_provider(
|
provider_dict.update(user_data["backup"])
|
||||||
kind=provider_string, login=account, key=key, location=location
|
|
||||||
)
|
if provider_dict == DEFAULT_JSON_PROVIDER:
|
||||||
return None
|
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(
|
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:
|
def reset_provider_json() -> AbstractBackupProvider:
|
||||||
|
|
|
@ -9,7 +9,11 @@ class AbstractBackuper(ABC):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@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
|
raise NotImplementedError
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|
|
@ -5,9 +5,12 @@ from selfprivacy_api.backup.backuppers import AbstractBackuper
|
||||||
|
|
||||||
|
|
||||||
class NoneBackupper(AbstractBackuper):
|
class NoneBackupper(AbstractBackuper):
|
||||||
def is_initted(self, repo_name: str) -> bool:
|
def is_initted(self, repo_name: str = "") -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def set_creds(self, account: str, key: str, repo: str):
|
||||||
|
pass
|
||||||
|
|
||||||
def start_backup(self, folders: List[str], repo_name: str):
|
def start_backup(self, folders: List[str], repo_name: str):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ from selfprivacy_api.backup.backuppers.none_backupper import NoneBackupper
|
||||||
class AbstractBackupProvider(ABC):
|
class AbstractBackupProvider(ABC):
|
||||||
@property
|
@property
|
||||||
def backuper(self) -> AbstractBackuper:
|
def backuper(self) -> AbstractBackuper:
|
||||||
return NoneBackupper
|
return NoneBackupper()
|
||||||
|
|
||||||
name = "NONE"
|
name = "NONE"
|
||||||
|
|
||||||
|
|
|
@ -230,7 +230,7 @@ def test_remove(authorized_client, generic_userdata):
|
||||||
assert_ok(data)
|
assert_ok(data)
|
||||||
|
|
||||||
configuration = data["configuration"]
|
configuration = data["configuration"]
|
||||||
assert configuration["provider"] == "BACKBLAZE"
|
assert configuration["provider"] == "NONE"
|
||||||
assert configuration["locationId"] == ""
|
assert configuration["locationId"] == ""
|
||||||
assert configuration["locationName"] == ""
|
assert configuration["locationName"] == ""
|
||||||
# still generated every time it is missing
|
# still generated every time it is missing
|
||||||
|
|
|
@ -15,6 +15,7 @@ from selfprivacy_api.backup import Backups
|
||||||
import selfprivacy_api.backup.providers as providers
|
import selfprivacy_api.backup.providers as providers
|
||||||
from selfprivacy_api.backup.providers import AbstractBackupProvider
|
from selfprivacy_api.backup.providers import AbstractBackupProvider
|
||||||
from selfprivacy_api.backup.providers.backblaze import Backblaze
|
from selfprivacy_api.backup.providers.backblaze import Backblaze
|
||||||
|
|
||||||
from selfprivacy_api.backup.tasks import start_backup, restore_snapshot
|
from selfprivacy_api.backup.tasks import start_backup, restore_snapshot
|
||||||
from selfprivacy_api.backup.storage import Storage
|
from selfprivacy_api.backup.storage import Storage
|
||||||
from selfprivacy_api.backup.jobs import get_backup_job
|
from selfprivacy_api.backup.jobs import get_backup_job
|
||||||
|
@ -126,7 +127,7 @@ def test_json_reset(generic_userdata):
|
||||||
Backups.reset()
|
Backups.reset()
|
||||||
provider = Backups.provider()
|
provider = Backups.provider()
|
||||||
assert provider is not None
|
assert provider is not None
|
||||||
assert isinstance(provider, Backblaze)
|
assert isinstance(provider, AbstractBackupProvider)
|
||||||
assert provider.login == ""
|
assert provider.login == ""
|
||||||
assert provider.key == ""
|
assert provider.key == ""
|
||||||
assert provider.location == ""
|
assert provider.location == ""
|
||||||
|
|
Loading…
Reference in a new issue