Merge pull request #26 from beatz174-bit/codex/add-logging-and-env-var-for-log-level-lkuozx
mtls-bridge: enhance logging/timing and fix docker-compose cert/env
This commit is contained in:
@@ -3,7 +3,7 @@ import os
|
||||
import time
|
||||
|
||||
import requests
|
||||
from flask import Flask, Response, request
|
||||
from flask import Flask, Response, g, request
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -12,6 +12,7 @@ logging.basicConfig(
|
||||
format="%(asctime)s %(levelname)s %(message)s",
|
||||
)
|
||||
logger = logging.getLogger("mtls-bridge")
|
||||
logging.getLogger("werkzeug").setLevel(logging.WARNING)
|
||||
|
||||
# Config via env
|
||||
TARGET_URL = os.environ.get("TARGET_URL")
|
||||
@@ -33,9 +34,29 @@ logger.info(
|
||||
|
||||
@app.route("/health", methods=["GET"])
|
||||
def health():
|
||||
logger.debug("healthcheck request from %s", request.remote_addr)
|
||||
return "OK", 200
|
||||
|
||||
|
||||
@app.before_request
|
||||
def before_request():
|
||||
g.request_start = time.time()
|
||||
|
||||
|
||||
@app.after_request
|
||||
def after_request(response):
|
||||
elapsed_ms = int((time.time() - g.request_start) * 1000)
|
||||
if request.path != "/health":
|
||||
logger.info(
|
||||
"request complete method=%s path=%s status=%s elapsed_ms=%s",
|
||||
request.method,
|
||||
request.path,
|
||||
response.status_code,
|
||||
elapsed_ms,
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
@app.route("/", defaults={"path": ""}, methods=["GET", "POST", "PUT", "DELETE", "PATCH"])
|
||||
@app.route("/<path:path>", methods=["GET", "POST", "PUT", "DELETE", "PATCH"])
|
||||
def proxy(path):
|
||||
|
||||
@@ -9,7 +9,7 @@ services:
|
||||
- TARGET_URL=https://node-red.lan.ddnsgeek.com/docker-update-lockouts/clear
|
||||
- CLIENT_CERT=/certs/clients/office-pc/office-pc.crt
|
||||
- CLIENT_KEY=/certs/clients/office-pc/office-pc.key
|
||||
- CA_CERT=/certs/ca/clents-ca.crt
|
||||
- CA_CERT=/certs/ca/clients-ca.crt
|
||||
- TIMEOUT=5
|
||||
- LOG_LEVEL=${MTLS_BRIDGE_LOG_LEVEL:-INFO}
|
||||
volumes:
|
||||
|
||||
Reference in New Issue
Block a user