Merge dev to main: Security improvements and comprehensive test infrastructure #39
@@ -7,7 +7,15 @@ from fastapi import APIRouter, Query
|
|||||||
from config import DOCKER_HOST
|
from config import DOCKER_HOST
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
client = docker.DockerClient(base_url=DOCKER_HOST, timeout=10)
|
|
||||||
|
_client = None
|
||||||
|
|
||||||
|
def get_docker_client():
|
||||||
|
"""Get or create Docker client (lazy initialization)."""
|
||||||
|
global _client
|
||||||
|
if _client is None:
|
||||||
|
_client = docker.DockerClient(base_url=DOCKER_HOST, timeout=10)
|
||||||
|
return _client
|
||||||
|
|
||||||
_tz_cst = timezone(timedelta(hours=8))
|
_tz_cst = timezone(timedelta(hours=8))
|
||||||
|
|
||||||
@@ -190,6 +198,7 @@ def security_logs(
|
|||||||
|
|
||||||
# Authelia logs
|
# Authelia logs
|
||||||
try:
|
try:
|
||||||
|
client = get_docker_client()
|
||||||
authelia = client.containers.get("authelia")
|
authelia = client.containers.get("authelia")
|
||||||
raw = authelia.logs(tail=tail, timestamps=False).decode(errors="replace")
|
raw = authelia.logs(tail=tail, timestamps=False).decode(errors="replace")
|
||||||
results.extend(_parse_authelia_logs(raw, limit))
|
results.extend(_parse_authelia_logs(raw, limit))
|
||||||
@@ -214,6 +223,7 @@ def security_stats(tail: int = Query(500, le=2000)):
|
|||||||
caddy_entries = []
|
caddy_entries = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
client = get_docker_client()
|
||||||
authelia = client.containers.get("authelia")
|
authelia = client.containers.get("authelia")
|
||||||
raw = authelia.logs(tail=tail, timestamps=False).decode(errors="replace")
|
raw = authelia.logs(tail=tail, timestamps=False).decode(errors="replace")
|
||||||
auth_entries = _parse_authelia_logs(raw, 1000)
|
auth_entries = _parse_authelia_logs(raw, 1000)
|
||||||
|
|||||||
Reference in New Issue
Block a user