2024-07-17 15:44:56 +00:00
|
|
|
from selfprivacy_api.migrations.migration import Migration
|
|
|
|
|
|
|
|
from selfprivacy_api.services.flake_service_manager import FlakeServiceManager
|
|
|
|
from selfprivacy_api.utils import ReadUserData, WriteUserData
|
|
|
|
|
|
|
|
|
2024-07-24 03:12:18 +00:00
|
|
|
class AddMonitoring(Migration):
|
|
|
|
"""Adds monitoring service if it is not present."""
|
2024-07-17 15:44:56 +00:00
|
|
|
|
|
|
|
def get_migration_name(self) -> str:
|
2024-07-24 03:12:18 +00:00
|
|
|
return "add_monitoring"
|
2024-07-17 15:44:56 +00:00
|
|
|
|
|
|
|
def get_migration_description(self) -> str:
|
2024-07-24 03:12:18 +00:00
|
|
|
return "Adds the Monitoring if it is not present."
|
2024-07-17 15:44:56 +00:00
|
|
|
|
|
|
|
def is_migration_needed(self) -> bool:
|
|
|
|
with FlakeServiceManager() as manager:
|
2024-07-24 03:12:18 +00:00
|
|
|
if "monitoring" not in manager.services:
|
2024-07-17 15:44:56 +00:00
|
|
|
return True
|
|
|
|
with ReadUserData() as data:
|
2024-07-24 03:12:18 +00:00
|
|
|
if "monitoring" not in data["modules"]:
|
2024-07-17 15:44:56 +00:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def migrate(self) -> None:
|
|
|
|
with FlakeServiceManager() as manager:
|
2024-07-24 03:12:18 +00:00
|
|
|
if "monitoring" not in manager.services:
|
2024-07-18 16:40:18 +00:00
|
|
|
manager.services[
|
2024-07-24 03:12:18 +00:00
|
|
|
"monitoring"
|
|
|
|
] = "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/monitoring"
|
2024-07-17 15:44:56 +00:00
|
|
|
with WriteUserData() as data:
|
2024-07-24 03:12:18 +00:00
|
|
|
if "monitoring" not in data["modules"]:
|
|
|
|
data["modules"]["monitoring"] = {
|
2024-07-24 03:18:11 +00:00
|
|
|
"enable": True
|
2024-07-17 15:44:56 +00:00
|
|
|
}
|