mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-22 12:11:26 +00:00
feat: add prometheus migration
This commit is contained in:
parent
f357607f68
commit
80a46a58ac
36
selfprivacy_api/migrations/add_promiteus.py
Normal file
36
selfprivacy_api/migrations/add_promiteus.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
from selfprivacy_api.migrations.migration import Migration
|
||||
|
||||
from selfprivacy_api.services.flake_service_manager import FlakeServiceManager
|
||||
from selfprivacy_api.utils import ReadUserData, WriteUserData
|
||||
|
||||
|
||||
class AddPrometheus(Migration):
|
||||
"""Adds the Prometheus if it is not present."""
|
||||
|
||||
def get_migration_name(self) -> str:
|
||||
return "add_prometheus"
|
||||
|
||||
def get_migration_description(self) -> str:
|
||||
return "Adds the Prometheus if it is not present."
|
||||
|
||||
def is_migration_needed(self) -> bool:
|
||||
with FlakeServiceManager() as manager:
|
||||
if "prometheus" not in manager.services:
|
||||
return True
|
||||
with ReadUserData() as data:
|
||||
if "prometheus" not in data["modules"]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def migrate(self) -> None:
|
||||
with FlakeServiceManager() as manager:
|
||||
if "prometheus" not in manager.services:
|
||||
manager.services["prometheus"] = (
|
||||
"git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/prometheus"
|
||||
)
|
||||
with WriteUserData() as data:
|
||||
if "prometheus" not in data["modules"]:
|
||||
data["modules"]["prometheus"] = {
|
||||
"enable": False,
|
||||
"subdomain": "prometheus",
|
||||
}
|
Loading…
Reference in a new issue