From e1b0f1153e69148de15c0b86313fcb39029682ae Mon Sep 17 00:00:00 2001 From: benya Date: Sun, 8 Feb 2026 02:28:41 +0300 Subject: [PATCH] Normalize NPMplus base_url to /api --- services/npmplus.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/services/npmplus.py b/services/npmplus.py index 517b5ca..a6b80e0 100644 --- a/services/npmplus.py +++ b/services/npmplus.py @@ -55,9 +55,19 @@ def _request_json( return json.loads(payload) +def _api_base(cfg: dict[str, Any]) -> str: + npm_cfg = cfg.get("npmplus", {}) + base = (npm_cfg.get("base_url") or "").rstrip("/") + if not base: + return "" + if not base.endswith("/api"): + base = f"{base}/api" + return base + + def _get_token(cfg: dict[str, Any]) -> str: npm_cfg = cfg.get("npmplus", {}) - base_url = (npm_cfg.get("base_url") or "").rstrip("/") + base_url = _api_base(cfg) identity = npm_cfg.get("identity") secret = npm_cfg.get("secret") static_token = npm_cfg.get("token") @@ -113,7 +123,7 @@ def _get_token(cfg: dict[str, Any]) -> str: def fetch_certificates(cfg: dict[str, Any]) -> list[dict[str, Any]]: npm_cfg = cfg.get("npmplus", {}) - base_url = (npm_cfg.get("base_url") or "").rstrip("/") + base_url = _api_base(cfg) verify_tls = npm_cfg.get("verify_tls", True) if not base_url: @@ -134,7 +144,7 @@ def fetch_certificates(cfg: dict[str, Any]) -> list[dict[str, Any]]: def list_proxy_hosts(cfg: dict[str, Any]) -> list[dict[str, Any]]: npm_cfg = cfg.get("npmplus", {}) - base_url = (npm_cfg.get("base_url") or "").rstrip("/") + base_url = _api_base(cfg) verify_tls = npm_cfg.get("verify_tls", True) if not base_url: raise ValueError("NPMplus base_url not configured") @@ -153,7 +163,7 @@ def list_proxy_hosts(cfg: dict[str, Any]) -> list[dict[str, Any]]: def set_proxy_host(cfg: dict[str, Any], host_id: int, enabled: bool) -> tuple[bool, str]: npm_cfg = cfg.get("npmplus", {}) - base_url = (npm_cfg.get("base_url") or "").rstrip("/") + base_url = _api_base(cfg) verify_tls = npm_cfg.get("verify_tls", True) if not base_url: return False, "NPMplus base_url not configured"