fix(remnawave): update existing config profile when expected inbound tag is missing
This commit is contained in:
1 parent
f218ca85e1
commit
9be350ed97
1 file changed
+34
-16
@@ -177,20 +177,11 @@ def sync_xray_template(
|
||||
return tpl_uuid
|
||||
|
||||
|
||||
def ensure_profile_and_inbound(
|
||||
def _render_profile_config(
|
||||
api: RemnawaveAPI,
|
||||
node_cfg: dict[str, Any],
|
||||
profile_templates: dict[str, str],
|
||||
changes: list[str],
|
||||
) -> tuple[str, str]:
|
||||
profile_name = node_cfg["profile_name"]
|
||||
inbound_tag = node_cfg["inbound_tag"]
|
||||
|
||||
_, profiles_resp = api.request("GET", "/config-profiles/")
|
||||
profiles = _extract_list(profiles_resp, "configProfiles")
|
||||
profile_uuid = next((p["uuid"] for p in profiles if p.get("name") == profile_name), "")
|
||||
|
||||
if not profile_uuid:
|
||||
) -> dict[str, Any]:
|
||||
tpl_key = node_cfg["profile_template"]
|
||||
raw_tpl = profile_templates.get(tpl_key)
|
||||
if not raw_tpl:
|
||||
@@ -212,26 +203,53 @@ def ensure_profile_and_inbound(
|
||||
rendered = (
|
||||
raw_tpl.replace("__REALITY_PRIVATE_KEY__", priv)
|
||||
.replace("__REALITY_SHORT_ID__", short_id)
|
||||
.replace("__INBOUND_TAG__", inbound_tag)
|
||||
.replace("__INBOUND_TAG__", node_cfg["inbound_tag"])
|
||||
.replace("__SELFSTEAL_DOMAIN__", node_cfg["selfsteal_domain"])
|
||||
.replace("__XHTTP_PATH__", node_cfg["xhttp_path"])
|
||||
)
|
||||
return json.loads(rendered)
|
||||
|
||||
|
||||
def ensure_profile_and_inbound(
|
||||
api: RemnawaveAPI,
|
||||
node_cfg: dict[str, Any],
|
||||
profile_templates: dict[str, str],
|
||||
changes: list[str],
|
||||
) -> tuple[str, str]:
|
||||
profile_name = node_cfg["profile_name"]
|
||||
inbound_tag = node_cfg["inbound_tag"]
|
||||
|
||||
_, profiles_resp = api.request("GET", "/config-profiles/")
|
||||
profiles = _extract_list(profiles_resp, "configProfiles")
|
||||
profile_uuid = next((p["uuid"] for p in profiles if p.get("name") == profile_name), "")
|
||||
|
||||
if not profile_uuid:
|
||||
cfg_obj = _render_profile_config(api, node_cfg, profile_templates)
|
||||
_, created = api.request(
|
||||
"POST",
|
||||
"/config-profiles/",
|
||||
{"name": profile_name, "config": json.loads(rendered)},
|
||||
{"name": profile_name, "config": cfg_obj},
|
||||
)
|
||||
profile_uuid = (created.get("response") or created).get("uuid", "")
|
||||
if not profile_uuid:
|
||||
raise RuntimeError(f"Не удалось создать config profile {profile_name}")
|
||||
changes.append(f"created profile {profile_name}")
|
||||
|
||||
def _get_inbounds() -> list[dict[str, Any]]:
|
||||
_, profile_full = api.request("GET", f"/config-profiles/{profile_uuid}")
|
||||
inbounds = _extract_list(profile_full, "inbounds")
|
||||
if not inbounds:
|
||||
inbs = _extract_list(profile_full, "inbounds")
|
||||
if not inbs:
|
||||
_, inb_resp = api.request("GET", f"/config-profiles/{profile_uuid}/inbounds")
|
||||
inbounds = _extract_list(inb_resp, "inbounds")
|
||||
inbs = _extract_list(inb_resp, "inbounds")
|
||||
return inbs
|
||||
|
||||
inbounds = _get_inbounds()
|
||||
inbound_uuid = next((i["uuid"] for i in inbounds if i.get("tag") == inbound_tag), "")
|
||||
if not inbound_uuid:
|
||||
cfg_obj = _render_profile_config(api, node_cfg, profile_templates)
|
||||
api.request("PATCH", "/config-profiles/", {"uuid": profile_uuid, "config": cfg_obj})
|
||||
changes.append(f"updated profile {profile_name} for inbound {inbound_tag}")
|
||||
inbounds = _get_inbounds()
|
||||
inbound_uuid = next((i["uuid"] for i in inbounds if i.get("tag") == inbound_tag), "")
|
||||
if not inbound_uuid:
|
||||
raise RuntimeError(f"Не найден inbound {inbound_tag} в профиле {profile_uuid}")
|
||||
|
||||
Reference in new issue
Block a user