Normalize NPMplus base_url to /api
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user