-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
61 lines (49 loc) · 2.48 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
# This work is co-funded by the EOSC-hub project (Horizon 2020) under Grant number 777536.
import logging
from app.api.endpoints.healthcheck import router as healthcheck_router
from app.api.endpoints.objects import router as api_router
from app.api.endpoints.transfer import router as transfer_router
from app.api.endpoints.globus import router as globus_router
from app.api.endpoints.oauth import router as oauth_router
from app.api.endpoints.serviceinfo import router as service_info_router
from app.core.config import API_V1_STR, PROJECT_NAME, HOST, PORT, SESSION_SECRET_KEY
from app.core.exception import http_exception_handler
from app.business.globus_client import load_app_client
from app.business.oauth_client import load_oauth_client
from app.business.serviceinfo import create_service_info
#from core.openapi import custom_openapi#
from app.db.db_utils import close_postgres_connection, connect_to_postgres
from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
from starlette.middleware.sessions import SessionMiddleware
# from app.core.openapi import custom_openapi
app = FastAPI(title=PROJECT_NAME)
app.add_event_handler("startup", connect_to_postgres)
app.add_event_handler("startup", load_app_client)
app.add_event_handler("startup", load_oauth_client)
app.add_event_handler("startup", create_service_info)
app.add_event_handler("shutdown", close_postgres_connection)
app.add_exception_handler(Exception, http_exception_handler)
def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi(
title="Reference Data Set Distribution Service",
description="Provides a GA4GH DRS compatible interface datasets stored within the ELIXIR network. This work is co-funded by the EOSC-hub project (Horizon 2020) under Grant number 777536.",
version="2.0.0",
routes=app.routes
)
openapi_schema['basePath'] = API_V1_STR
app.openapi_schema = openapi_schema
return app.openapi_schema
app.openapi = custom_openapi
app.include_router(api_router, prefix=API_V1_STR)
app.include_router(healthcheck_router, prefix='/health-check')
app.include_router(transfer_router, prefix='/transfer')
app.include_router(globus_router, prefix='/globus')
app.include_router(oauth_router, prefix='/oauth')
app.include_router(service_info_router, prefix='/service-info')
app.add_middleware(SessionMiddleware, secret_key=SESSION_SECRET_KEY)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host=HOST, port=PORT)