refactor: stop using legacy JSON for runtime config
Build runtime pobsync configuration exclusively from structured SQL fields, leaving legacy JSON only for import and audit context. Add SQL-first management commands for global and host configuration and cover them with tests.
This commit is contained in:
@@ -18,68 +18,62 @@ class ConfigRepositoryError(RuntimeError):
|
||||
|
||||
|
||||
def _global_yaml_data(global_config: GlobalConfig) -> dict[str, Any]:
|
||||
data = dict(global_config.data or {})
|
||||
data["backup_root"] = global_config.backup_root
|
||||
data["pobsync_home"] = global_config.pobsync_home
|
||||
data["ssh"] = {
|
||||
"user": global_config.ssh_user,
|
||||
"port": global_config.ssh_port,
|
||||
"options": list(global_config.ssh_options or []),
|
||||
}
|
||||
data["rsync"] = {
|
||||
"binary": global_config.rsync_binary,
|
||||
"args": list(global_config.rsync_args or []),
|
||||
"timeout_seconds": global_config.rsync_timeout_seconds,
|
||||
"bwlimit_kbps": global_config.rsync_bwlimit_kbps,
|
||||
"extra_args": list(global_config.rsync_extra_args or []),
|
||||
}
|
||||
data["defaults"] = {
|
||||
"source_root": global_config.default_source_root,
|
||||
"destination_subdir": global_config.default_destination_subdir,
|
||||
}
|
||||
data["excludes_default"] = list(global_config.excludes_default or [])
|
||||
data["retention_defaults"] = {
|
||||
"daily": global_config.retention_daily,
|
||||
"weekly": global_config.retention_weekly,
|
||||
"monthly": global_config.retention_monthly,
|
||||
"yearly": global_config.retention_yearly,
|
||||
data = {
|
||||
"backup_root": global_config.backup_root,
|
||||
"pobsync_home": global_config.pobsync_home,
|
||||
"ssh": {
|
||||
"user": global_config.ssh_user,
|
||||
"port": global_config.ssh_port,
|
||||
"options": list(global_config.ssh_options or []),
|
||||
},
|
||||
"rsync": {
|
||||
"binary": global_config.rsync_binary,
|
||||
"args": list(global_config.rsync_args or []),
|
||||
"timeout_seconds": global_config.rsync_timeout_seconds,
|
||||
"bwlimit_kbps": global_config.rsync_bwlimit_kbps,
|
||||
"extra_args": list(global_config.rsync_extra_args or []),
|
||||
},
|
||||
"defaults": {
|
||||
"source_root": global_config.default_source_root,
|
||||
"destination_subdir": global_config.default_destination_subdir,
|
||||
},
|
||||
"excludes_default": list(global_config.excludes_default or []),
|
||||
"retention_defaults": {
|
||||
"daily": global_config.retention_daily,
|
||||
"weekly": global_config.retention_weekly,
|
||||
"monthly": global_config.retention_monthly,
|
||||
"yearly": global_config.retention_yearly,
|
||||
},
|
||||
}
|
||||
return validate_dict(data, GLOBAL_SCHEMA, path="global")
|
||||
|
||||
|
||||
def _host_yaml_data(host_config: HostConfig) -> dict[str, Any]:
|
||||
data = dict(host_config.config or {})
|
||||
data["host"] = host_config.host
|
||||
data["address"] = host_config.address
|
||||
data: dict[str, Any] = {
|
||||
"host": host_config.host,
|
||||
"address": host_config.address,
|
||||
"includes": list(host_config.includes or []),
|
||||
"retention": {
|
||||
"daily": host_config.retention_daily,
|
||||
"weekly": host_config.retention_weekly,
|
||||
"monthly": host_config.retention_monthly,
|
||||
"yearly": host_config.retention_yearly,
|
||||
},
|
||||
}
|
||||
if host_config.ssh_user or host_config.ssh_port:
|
||||
data["ssh"] = {}
|
||||
if host_config.ssh_user:
|
||||
data["ssh"]["user"] = host_config.ssh_user
|
||||
if host_config.ssh_port is not None:
|
||||
data["ssh"]["port"] = host_config.ssh_port
|
||||
else:
|
||||
data.pop("ssh", None)
|
||||
if host_config.source_root:
|
||||
data["source_root"] = host_config.source_root
|
||||
else:
|
||||
data.pop("source_root", None)
|
||||
data["includes"] = list(host_config.includes or [])
|
||||
if host_config.excludes_replace is not None:
|
||||
data["excludes_replace"] = list(host_config.excludes_replace or [])
|
||||
data.pop("excludes_add", None)
|
||||
else:
|
||||
data["excludes_add"] = list(host_config.excludes_add or [])
|
||||
data.pop("excludes_replace", None)
|
||||
if host_config.rsync_extra_args:
|
||||
data["rsync"] = {"extra_args": list(host_config.rsync_extra_args or [])}
|
||||
else:
|
||||
data.pop("rsync", None)
|
||||
data["retention"] = {
|
||||
"daily": host_config.retention_daily,
|
||||
"weekly": host_config.retention_weekly,
|
||||
"monthly": host_config.retention_monthly,
|
||||
"yearly": host_config.retention_yearly,
|
||||
}
|
||||
return validate_dict(data, HOST_SCHEMA, path="host")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user