migrate backblaze settings to new json format

And adjust methods and tests
This commit is contained in:
Houkime 2022-10-31 13:32:17 +00:00
parent 07af2e59be
commit 41e5f89b7b
52 changed files with 28 additions and 274 deletions

View file

@ -257,24 +257,25 @@ async def restore_restic_backup(backup: BackupRestoreInput):
raise HTTPException(status_code=404, detail="Backup not found") raise HTTPException(status_code=404, detail="Backup not found")
class BackblazeConfigInput(BaseModel): class BackupConfigInput(BaseModel):
accountId: str accountId: str
accountKey: str accountKey: str
bucket: str bucket: str
@router.put("/restic/backblaze/config") @router.put("/restic/backblaze/config")
async def set_backblaze_config(backblaze_config: BackblazeConfigInput): async def set_backblaze_config(backup_config: BackupConfigInput):
with WriteUserData() as data: with WriteUserData() as data:
if "backblaze" not in data: if "backup" not in data:
data["backblaze"] = {} data["backup"] = {}
data["backblaze"]["accountId"] = backblaze_config.accountId data["backup"]["provider"] = "BACKBLAZE"
data["backblaze"]["accountKey"] = backblaze_config.accountKey data["backup"]["accountId"] = backup_config.accountId
data["backblaze"]["bucket"] = backblaze_config.bucket data["backup"]["accountKey"] = backup_config.accountKey
data["backup"]["bucket"] = backup_config.bucket
restic_tasks.update_keys_from_userdata() restic_tasks.update_keys_from_userdata()
return "New Backblaze settings saved" return "New backup settings saved"
@router.post("/ssh/enable") @router.post("/ssh/enable")

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -161,7 +161,7 @@ def mock_restic_tasks(mocker):
@pytest.fixture @pytest.fixture
def undefined_settings(mocker, datadir): def undefined_settings(mocker, datadir):
mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "undefined.json") mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "undefined.json")
assert "backblaze" not in read_json(datadir / "undefined.json") assert "backup" not in read_json(datadir / "undefined.json")
return datadir return datadir
@ -170,20 +170,22 @@ def some_settings(mocker, datadir):
mocker.patch( mocker.patch(
"selfprivacy_api.utils.USERDATA_FILE", new=datadir / "some_values.json" "selfprivacy_api.utils.USERDATA_FILE", new=datadir / "some_values.json"
) )
assert "backblaze" in read_json(datadir / "some_values.json") assert "backup" in read_json(datadir / "some_values.json")
assert read_json(datadir / "some_values.json")["backblaze"]["accountId"] == "ID" assert read_json(datadir / "some_values.json")["backup"]["provider"] == "BACKBLAZE"
assert read_json(datadir / "some_values.json")["backblaze"]["accountKey"] == "KEY" assert read_json(datadir / "some_values.json")["backup"]["accountId"] == "ID"
assert read_json(datadir / "some_values.json")["backblaze"]["bucket"] == "BUCKET" assert read_json(datadir / "some_values.json")["backup"]["accountKey"] == "KEY"
assert read_json(datadir / "some_values.json")["backup"]["bucket"] == "BUCKET"
return datadir return datadir
@pytest.fixture @pytest.fixture
def no_values(mocker, datadir): def no_values(mocker, datadir):
mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "no_values.json") mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "no_values.json")
assert "backblaze" in read_json(datadir / "no_values.json") assert "backup" in read_json(datadir / "no_values.json")
assert "accountId" not in read_json(datadir / "no_values.json")["backblaze"] assert "provider" not in read_json(datadir / "no_values.json")["backup"]
assert "accountKey" not in read_json(datadir / "no_values.json")["backblaze"] assert "accountId" not in read_json(datadir / "no_values.json")["backup"]
assert "bucket" not in read_json(datadir / "no_values.json")["backblaze"] assert "accountKey" not in read_json(datadir / "no_values.json")["backup"]
assert "bucket" not in read_json(datadir / "no_values.json")["backup"]
return datadir return datadir
@ -462,7 +464,8 @@ def test_set_backblaze_config(
) )
assert response.status_code == 200 assert response.status_code == 200
assert mock_restic_tasks.update_keys_from_userdata.call_count == 1 assert mock_restic_tasks.update_keys_from_userdata.call_count == 1
assert read_json(some_settings / "some_values.json")["backblaze"] == { assert read_json(some_settings / "some_values.json")["backup"] == {
"provider": "BACKBLAZE",
"accountId": "123", "accountId": "123",
"accountKey": "456", "accountKey": "456",
"bucket": "789", "bucket": "789",
@ -478,7 +481,8 @@ def test_set_backblaze_config_on_undefined(
) )
assert response.status_code == 200 assert response.status_code == 200
assert mock_restic_tasks.update_keys_from_userdata.call_count == 1 assert mock_restic_tasks.update_keys_from_userdata.call_count == 1
assert read_json(undefined_settings / "undefined.json")["backblaze"] == { assert read_json(undefined_settings / "undefined.json")["backup"] == {
"provider": "BACKBLAZE",
"accountId": "123", "accountId": "123",
"accountKey": "456", "accountKey": "456",
"bucket": "789", "bucket": "789",
@ -494,7 +498,8 @@ def test_set_backblaze_config_on_no_values(
) )
assert response.status_code == 200 assert response.status_code == 200
assert mock_restic_tasks.update_keys_from_userdata.call_count == 1 assert mock_restic_tasks.update_keys_from_userdata.call_count == 1
assert read_json(no_values / "no_values.json")["backblaze"] == { assert read_json(no_values / "no_values.json")["backup"] == {
"provider": "BACKBLAZE",
"accountId": "123", "accountId": "123",
"accountKey": "456", "accountKey": "456",
"bucket": "789", "bucket": "789",

View file

@ -1,6 +1,4 @@
{ {
"backblaze": {
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false
@ -70,9 +68,5 @@
"provider": "HETZNER" "provider": "HETZNER"
}, },
"backup": { "backup": {
"provider": "BACKBLAZE",
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
} }
} }

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "BUCKET"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false
@ -76,6 +71,6 @@
"provider": "BACKBLAZE", "provider": "BACKBLAZE",
"accountId": "ID", "accountId": "ID",
"accountKey": "KEY", "accountKey": "KEY",
"bucket": "selfprivacy" "bucket": "BUCKET"
} }
} }

View file

@ -66,11 +66,5 @@
}, },
"server": { "server": {
"provider": "HETZNER" "provider": "HETZNER"
},
"backup": {
"provider": "BACKBLAZE",
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
} }
} }

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false

View file

@ -1,9 +1,4 @@
{ {
"backblaze": {
"accountId": "ID",
"accountKey": "KEY",
"bucket": "selfprivacy"
},
"api": { "api": {
"token": "TEST_TOKEN", "token": "TEST_TOKEN",
"enableSwagger": false "enableSwagger": false