fps_test: Zugangsdaten in URL maskieren (Hilfe/Ausgabe/Fehler)
CAMERA_URL kann Credentials enthalten (z.B. rtsp://user:pass@host). Diese werden in Hilfetext, Lauf-Ausgabe und Fehlermeldung jetzt zu ***:*** maskiert. Default im Code auf neutralen Platzhalter gesetzt. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ import argparse
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from urllib.parse import urlparse, urlunparse
|
||||
|
||||
import requests
|
||||
|
||||
@@ -25,19 +26,33 @@ except ImportError:
|
||||
pass
|
||||
|
||||
APP_URL = "http://localhost:8080/webcam_feed"
|
||||
CAM_URL = os.environ.get("CAMERA_URL", "http://192.168.10.99:81/stream")
|
||||
CAM_URL = os.environ.get("CAMERA_URL", "http://CAMERA-IP:81/stream")
|
||||
|
||||
SOI = b"\xff\xd8" # JPEG Start-of-Image
|
||||
EOI = b"\xff\xd9" # JPEG End-of-Image
|
||||
|
||||
|
||||
def redact(url: str) -> str:
|
||||
"""Zugangsdaten (user:pass@) in einer URL maskieren -> nie im Klartext anzeigen."""
|
||||
try:
|
||||
p = urlparse(url)
|
||||
if p.username or p.password:
|
||||
host = p.hostname or ""
|
||||
if p.port:
|
||||
host += f":{p.port}"
|
||||
return urlunparse(p._replace(netloc=f"***:***@{host}"))
|
||||
except Exception:
|
||||
pass
|
||||
return url
|
||||
|
||||
|
||||
def measure(url: str, seconds: float) -> int:
|
||||
print(f"Messe {seconds:.0f}s an: {url}\n", flush=True)
|
||||
print(f"Messe {seconds:.0f}s an: {redact(url)}\n", flush=True)
|
||||
try:
|
||||
resp = requests.get(url, stream=True, timeout=(5, 10))
|
||||
resp.raise_for_status()
|
||||
except requests.RequestException as exc:
|
||||
print(f"FEHLER: {exc}")
|
||||
print(f"FEHLER: {str(exc).replace(url, redact(url))}")
|
||||
return 1
|
||||
|
||||
buf = b""
|
||||
@@ -97,7 +112,7 @@ def main() -> int:
|
||||
p = argparse.ArgumentParser(description="Misst FPS/Durchsatz einer MJPEG-Quelle.")
|
||||
p.add_argument("url", nargs="?", help="MJPEG-URL (Default: App-Stream)")
|
||||
p.add_argument("--app", action="store_true", help=f"App-Pipeline messen ({APP_URL})")
|
||||
p.add_argument("--cam", action="store_true", help=f"Kamera direkt messen (CAMERA_URL: {CAM_URL})")
|
||||
p.add_argument("--cam", action="store_true", help=f"Kamera direkt messen (CAMERA_URL: {redact(CAM_URL)})")
|
||||
p.add_argument("-t", "--seconds", type=float, default=10, help="Messdauer in Sekunden (Default 10)")
|
||||
args = p.parse_args()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user