-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
82 lines (64 loc) · 2.28 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import logging
import os
import aiohttp_cors
import coloredlogs
import sentry_sdk
from aiohttp import web
from fhirpy.lib import AsyncFHIRClient
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
from sentry_sdk.integrations.logging import LoggingIntegration
coloredlogs.install(level="DEBUG", fmt="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.DEBUG
)
logging.getLogger("aidbox_sdk").setLevel(logging.INFO)
logging.getLogger("urllib3").setLevel(logging.INFO)
logging.getLogger("faker").setLevel(logging.WARNING)
sentry_logging = LoggingIntegration(
level=logging.DEBUG, # Capture info and above as breadcrumbs
event_level=logging.WARNING, # Send warnings as events
)
sentry_sdk.init(integrations=[AioHttpIntegration(), sentry_logging])
async def create_gunicorn_app():
if os.getenv("APP_ID") is None:
return create_fhir_app()
else:
return create_app()
# TODO: Add config param for aidbox-python-sdk pytest plugin
# to select create_app
def create_app():
from aidbox_python_sdk.main import init as init_aidbox_app
from aidbox_python_sdk.main import setup_routes as setup_aidbox_app_routes
from app.aidbox import sdk
app = web.Application()
app.cleanup_ctx.append(init_aidbox_app)
app.update(
settings=sdk.settings,
sdk=sdk,
)
setup_aidbox_app_routes(app)
return app
async def fhir_app_on_startup(app: web.Application):
from app.fhir_server.settings import settings
app["settings"] = settings
app["client"] = AsyncFHIRClient(settings.BASE_URL, authorization=f"Basic {settings.AUTH_TOKEN}")
def create_fhir_app():
from app.fhir_server.operations import routes as fhir_routes
app = web.Application()
app.add_routes(fhir_routes)
app.on_startup.append(fhir_app_on_startup)
# Configure default CORS settings.
cors = aiohttp_cors.setup(
app,
defaults={
"*": aiohttp_cors.ResourceOptions(
allow_credentials=True,
expose_headers="*",
allow_headers="*",
)
},
)
# Configure CORS on all routes.
for route in list(app.router.routes()):
cors.add(route)
return app