42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
"""Process entrypoint: logging, signals, ``.env``, the config, then ``app.run``."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import contextlib
|
|
import logging
|
|
import signal
|
|
|
|
import uvloop
|
|
from dotenv import load_dotenv
|
|
|
|
from beaver_gateway import app, config
|
|
from beaver_gateway.security.redact import install as install_redaction
|
|
from beaver_gateway.security.redact import load_secrets as load_secrets_to_mask
|
|
from beaver_gateway.settings import Settings
|
|
|
|
|
|
def main() -> None:
|
|
logging.basicConfig(
|
|
level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s"
|
|
)
|
|
install_redaction()
|
|
_sigterm_as_interrupt()
|
|
asyncio.run(_run(), loop_factory=uvloop.new_event_loop)
|
|
|
|
|
|
async def _run() -> None:
|
|
load_dotenv(override=False)
|
|
load_secrets_to_mask()
|
|
settings = Settings() # ty: ignore[missing-argument]
|
|
gateway = config.load(settings.config_path)
|
|
await app.run(gateway, settings)
|
|
|
|
|
|
def _sigterm_as_interrupt() -> None:
|
|
def _raise_interrupt(_signum: int, _frame: object) -> None:
|
|
raise KeyboardInterrupt
|
|
|
|
with contextlib.suppress(ValueError, OSError):
|
|
signal.signal(signal.SIGTERM, _raise_interrupt)
|