intermediate commit
This commit is contained in:
@@ -15,10 +15,8 @@ import subprocess
|
||||
import sys
|
||||
import tomllib
|
||||
from typing import Any
|
||||
from urllib.error import URLError
|
||||
from urllib.parse import urlparse
|
||||
from urllib.request import Request, urlopen
|
||||
|
||||
from govoplan_release.http_fetch import fetch_http, validate_http_url
|
||||
|
||||
META_ROOT = Path(__file__).resolve().parents[2]
|
||||
ROOT = Path(os.environ.get("GOVOPLAN_CORE_ROOT", META_ROOT.parent / "govoplan-core")).resolve()
|
||||
@@ -1208,14 +1206,11 @@ def safe_directory_argv(path: Path) -> list[str]:
|
||||
|
||||
|
||||
def check_url(url: str) -> dict[str, Any]:
|
||||
parsed = urlparse(url)
|
||||
if parsed.scheme not in {"http", "https"} or not parsed.netloc:
|
||||
return {"ok": False, "error": "URL must use http:// or https:// with a hostname", "url": url}
|
||||
request = Request(url, method="HEAD")
|
||||
try:
|
||||
with urlopen(request, timeout=8) as response: # noqa: S310 - validated operator-requested release availability check. # nosemgrep: python.lang.security.audit.dynamic-urllib-use-detected.dynamic-urllib-use-detected
|
||||
return {"ok": 200 <= response.status < 400, "status": response.status, "url": url}
|
||||
except URLError as exc:
|
||||
checked_url = validate_http_url(url)
|
||||
response = fetch_http(checked_url, timeout=8, method="HEAD")
|
||||
return {"ok": 200 <= response.status < 400, "status": response.status, "url": checked_url}
|
||||
except (ValueError, OSError) as exc:
|
||||
return {"ok": False, "error": str(exc), "url": url}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user