make app configurable via CLI and ENV parameters
This commit is contained in:
parent
9b97500516
commit
a1aa89132d
3 changed files with 57 additions and 7 deletions
|
|
@ -1,8 +1,51 @@
|
|||
from dooris_api.app import app
|
||||
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",
|
||||
)
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue