"""Tiny read-only Docker Engine API client over the unix socket (stdlib only). Used by the cve and config-drift sources. HTTP/1.0 so the daemon sends the whole body then closes the connection (no chunked decoding needed). """ import json import socket SOCK = "/var/run/docker.sock" def available(): try: s = socket.socket(socket.AF_UNIX) s.connect(SOCK) s.close() return True except OSError: return False def get(path): s = socket.socket(socket.AF_UNIX) s.settimeout(30) s.connect(SOCK) s.sendall(f"GET {path} HTTP/1.0\r\nHost: docker\r\n\r\n".encode()) buf = b"" while True: chunk = s.recv(65536) if not chunk: break buf += chunk s.close() body = buf.split(b"\r\n\r\n", 1)[1] if b"\r\n\r\n" in buf else b"" return json.loads(body or b"null")