All checks were successful
Build Container / Build Container (push) Successful in 1m32s
79 lines
2.9 KiB
Python
79 lines
2.9 KiB
Python
import os
|
|
from contextvars import ContextVar
|
|
from argparse import ArgumentParser, Namespace
|
|
|
|
|
|
app_config: ContextVar[Namespace] = ContextVar("app_config")
|
|
|
|
|
|
def main():
|
|
argp = ArgumentParser(
|
|
"dooris-api",
|
|
description="Server to interact with CCCHH doors via locks over CCUJACK over HomeMatic over WiFi",
|
|
)
|
|
argp.add_argument(
|
|
"--openid-issuer",
|
|
required="DOORIS_OPENID_ISSUER" not in os.environ,
|
|
default=os.environ.get("DOORIS_OPENID_ISSUER", None),
|
|
help="The Keycloak OpenID isser to use for authentication",
|
|
)
|
|
argp.add_argument(
|
|
"--openid-scope",
|
|
default=os.environ.get("DOORIS_OPENID_SCOPE", "openid profile"),
|
|
help="The Keycloak OpenID isser to use for authentication",
|
|
)
|
|
argp.add_argument(
|
|
"--openid-client-id",
|
|
required="DOORIS_OPENID_CLIENT_ID" not in os.environ,
|
|
default=os.environ.get("DOORIS_OPENID_CLIENT_ID", None),
|
|
help="The Keycloak OpenID client-id to use for authentication",
|
|
)
|
|
argp.add_argument(
|
|
"--openid-client-secret",
|
|
required="DOORIS_OPENID_CLIENT_SECRET" not in os.environ,
|
|
default=os.environ.get("DOORIS_OPENID_CLIENT_SECRET", None),
|
|
help="The Keycloak OpenID client secret to use for authentication",
|
|
)
|
|
argp.add_argument(
|
|
"--base-url",
|
|
required="DOORIS_BASE_URL" not in os.environ,
|
|
default=os.environ.get("DOORIS_BASE_URL", None),
|
|
help="The Base-URL that this application is reachable under",
|
|
)
|
|
argp.add_argument(
|
|
"--serve-static",
|
|
required=False,
|
|
default=os.environ.get("DOORIS_SERVE_STATIC", None),
|
|
help="In addition to the API functionality, serve static files from this path",
|
|
)
|
|
argp.add_argument(
|
|
"--ccujack-url",
|
|
required=False,
|
|
default=os.environ.get("DOORIS_CCUJACK_URL", "https://hmdooris-ccu.ccchh.net:2122"),
|
|
help="The URL under which a CCUJACK instance is hosted that actually operates the locks",
|
|
)
|
|
argp.add_argument(
|
|
"--ccujack-user",
|
|
required="DOORIS_CCUJACK_USER" not in os.environ,
|
|
default=os.environ.get("DOORIS_CCUJACK_USER", None),
|
|
help="The username used to authenticate against the CCUJACK",
|
|
)
|
|
argp.add_argument(
|
|
"--ccujack-password",
|
|
required="DOORIS_CCUJACK_PASSWORD" not in os.environ,
|
|
default=os.environ.get("DOORIS_CCUJACK_PASSWORD", None),
|
|
help="The password used to authenticate against the CCUJACK"
|
|
)
|
|
args = argp.parse_args()
|
|
|
|
app_config.set(args)
|
|
import uvicorn
|
|
from dooris_api.app import app
|
|
|
|
if args.serve_static:
|
|
from fastapi.staticfiles import StaticFiles
|
|
app.mount("/", StaticFiles(directory=args.serve_static, html=True), name="static")
|
|
|
|
config = uvicorn.Config(app, port=8000, log_level="debug")
|
|
server = uvicorn.Server(config)
|
|
server.run()
|