mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-25 21:41:27 +00:00
feature(backups): resetting json config too
This commit is contained in:
parent
47aee3c1f1
commit
79c3b9598c
|
@ -4,7 +4,7 @@ from os import statvfs
|
|||
|
||||
from selfprivacy_api.models.backup.snapshot import Snapshot
|
||||
|
||||
from selfprivacy_api.utils import ReadUserData
|
||||
from selfprivacy_api.utils import ReadUserData, WriteUserData
|
||||
|
||||
from selfprivacy_api.services import get_service_by_id
|
||||
from selfprivacy_api.services.service import Service
|
||||
|
@ -22,6 +22,13 @@ from selfprivacy_api.backup.jobs import (
|
|||
)
|
||||
from selfprivacy_api.jobs import Jobs, JobStatus
|
||||
|
||||
DEFAULT_JSON_PROVIDER = {
|
||||
"provider": "BACKBLAZE",
|
||||
"accountId": "",
|
||||
"accountKey": "",
|
||||
"bucket": "",
|
||||
}
|
||||
|
||||
|
||||
class Backups:
|
||||
"""A singleton controller for backups"""
|
||||
|
@ -147,8 +154,13 @@ class Backups:
|
|||
return provider_class(login=login, key=key, location=location, repo_id=repo_id)
|
||||
|
||||
@staticmethod
|
||||
def reset():
|
||||
def reset(reset_json=True):
|
||||
Storage.reset()
|
||||
if reset_json:
|
||||
try:
|
||||
Backups.reset_provider_json()
|
||||
except FileNotFoundError: # if there is no userdata file, we do not need to reset it
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def lookup_provider() -> AbstractBackupProvider:
|
||||
|
@ -190,6 +202,13 @@ class Backups:
|
|||
kind=provider_string, login=account, key=key, location=location
|
||||
)
|
||||
|
||||
def reset_provider_json() -> AbstractBackupProvider:
|
||||
with WriteUserData() as user_data:
|
||||
if "backblaze" in user_data.keys():
|
||||
del user_data["backblaze"]
|
||||
|
||||
user_data["backup"] = DEFAULT_JSON_PROVIDER
|
||||
|
||||
@staticmethod
|
||||
def load_provider_redis() -> AbstractBackupProvider:
|
||||
provider_model = Storage.load_provider()
|
||||
|
|
|
@ -232,7 +232,7 @@ def test_remove(authorized_client, generic_userdata):
|
|||
configuration = data["configuration"]
|
||||
assert configuration["provider"] == "BACKBLAZE"
|
||||
assert configuration["locationId"] == ""
|
||||
assert configuration["locationName"] == "selfprivacy"
|
||||
assert configuration["locationName"] == ""
|
||||
# still generated every time it is missing
|
||||
assert len(configuration["encryptionKey"]) > 1
|
||||
assert configuration["isInitialized"] is False
|
||||
|
|
|
@ -37,7 +37,7 @@ def backups(tmpdir):
|
|||
|
||||
@pytest.fixture()
|
||||
def backups_backblaze(generic_userdata):
|
||||
Backups.reset()
|
||||
Backups.reset(reset_json=False)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
|
@ -101,7 +101,7 @@ def file_backup(tmpdir) -> AbstractBackupProvider:
|
|||
|
||||
|
||||
def test_config_load(generic_userdata):
|
||||
Backups.reset()
|
||||
Backups.reset(reset_json=False)
|
||||
provider = Backups.provider()
|
||||
|
||||
assert provider is not None
|
||||
|
@ -445,7 +445,6 @@ def test_init_tracking_caching2(backups, raw_dummy_service):
|
|||
|
||||
# Storage
|
||||
def test_provider_storage(backups_backblaze):
|
||||
Backups.reset()
|
||||
provider = Backups.provider()
|
||||
|
||||
assert provider is not None
|
||||
|
|
Loading…
Reference in a new issue