mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-22 20:11:30 +00:00
add providers migration
This commit is contained in:
parent
27255cb533
commit
b0c26b876a
43
selfprivacy_api/migrations/providers.py
Normal file
43
selfprivacy_api/migrations/providers.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
from selfprivacy_api.migrations.migration import Migration
|
||||||
|
from selfprivacy_api.utils import ReadUserData, WriteUserData
|
||||||
|
|
||||||
|
|
||||||
|
class CreateProviderFields(Migration):
|
||||||
|
"""Unhardcode providers"""
|
||||||
|
|
||||||
|
def get_migration_name(self):
|
||||||
|
return "create_provider_fields"
|
||||||
|
|
||||||
|
def get_migration_description(self):
|
||||||
|
return "Add DNS, backup and server provider fields to enable user to choose between different clouds and to make the deployment adapt to these preferences."
|
||||||
|
|
||||||
|
def is_migration_needed(self):
|
||||||
|
try:
|
||||||
|
with ReadUserData() as userdata:
|
||||||
|
return "dns" not in userdata
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
return False
|
||||||
|
|
||||||
|
def migrate(self):
|
||||||
|
# Write info about providers to userdata.json
|
||||||
|
try:
|
||||||
|
with WriteUserData() as userdata:
|
||||||
|
userdata["dns"] = {
|
||||||
|
"provider": "CLOUDFLARE",
|
||||||
|
"apiToken": userdata["cloudflare"]["apiToken"],
|
||||||
|
}
|
||||||
|
userdata["server"] = {
|
||||||
|
"provider": "HETZNER",
|
||||||
|
}
|
||||||
|
userdata["backup"] = {
|
||||||
|
"provider": "BACKBLAZE",
|
||||||
|
"accountId": userdata["backblaze"]["accountId"],
|
||||||
|
"accountKey": userdata["backblaze"]["accountKey"],
|
||||||
|
"bucket": userdata["backblaze"]["bucket"],
|
||||||
|
}
|
||||||
|
|
||||||
|
print("Done")
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
print("Error migrating provider fields")
|
Loading…
Reference in a new issue