PROD5 for Micinas

This commit is contained in:
hubaceks
2026-05-01 22:39:54 +02:00
parent f891a75063
commit d5760660f3
3 changed files with 47 additions and 1 deletions

View File

@@ -24,7 +24,8 @@ def validate_service(data: dict, source: Path) -> None:
raise ValueError(f"{source.name}: missing required key '{key}'")
svc_type = data["type"]
if svc_type not in {"static", "proxy"}:
if svc_type not in {"static", "proxy", "redirect"}:
raise ValueError(f"{source.name}: unsupported type '{svc_type}'")
if svc_type == "static" and "root" not in data:
@@ -33,6 +34,9 @@ def validate_service(data: dict, source: Path) -> None:
if svc_type == "proxy" and "backend" not in data:
raise ValueError(f"{source.name}: proxy service requires 'backend'")
if svc_type == "redirect" and "target" not in data:
raise ValueError(f"{source.name}: redirect service requires 'target'")
def render_service(env: Environment, data: dict) -> str:
svc_type = data["type"]
@@ -43,6 +47,13 @@ def render_service(env: Environment, data: dict) -> str:
"real_ip": False,
"health_uri": None,
"health_interval": None,
"internal": False,
"internal_ranges": [
"10.0.0.0/8",
"172.16.0.0/12",
"192.168.0.0/16",
],
"redirect_code": 301,
}
merged = {**defaults, **data}
@@ -51,6 +62,10 @@ def render_service(env: Environment, data: dict) -> str:
template = env.get_template("static.caddy.j2")
return template.render(**merged).strip() + "\n"
if svc_type == "redirect":
template = env.get_template("redirect.caddy.j2")
return template.render(**merged).strip() + "\n"
reverse_proxy_block = any(
[
merged.get("real_ip"),