51 lines
1.7 KiB
Python
51 lines
1.7 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 ccchh-roles"),
|
|
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",
|
|
)
|
|
args = argp.parse_args()
|
|
|
|
app_config.set(args)
|
|
import uvicorn
|
|
from dooris_api.app import app
|
|
|
|
config = uvicorn.Config(app, port=8000, log_level="debug")
|
|
server = uvicorn.Server(config)
|
|
server.run()
|