"""Container health probe: https when SSL_CRT_FILE is set, else http.

Used by the Dockerfile HEALTHCHECK so the same image works with and without local TLS.
Exit code 1 when the app does not answer.
"""
import os
import ssl
import sys
import urllib.request

scheme = "https" if os.environ.get("SSL_CRT_FILE") else "http"
context = ssl._create_unverified_context() if scheme == "https" else None
try:
    urllib.request.urlopen(f"{scheme}://127.0.0.1:5000/login", timeout=4, context=context)
except Exception:
    sys.exit(1)
