-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
65 lines (56 loc) · 1.79 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
from fastapi import FastAPI, Request, status, Request
from fastapi.exceptions import RequestValidationError
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from fastapi.exceptions import HTTPException
from starlette.responses import HTMLResponse
from routers import routes, noop
from config import settings
import logging
import logging.config
logging.config.dictConfig({
'version': 1,
'formatters': {'default': {
'format': '[%(asctime)s] %(levelname)5s %(module)s.%(funcName)5s: %(message)s',
}},
'handlers': {'console': {
'level': settings.log_level,
'class': 'logging.StreamHandler',
'stream': 'ext://sys.stdout',
'formatter': 'default'
}},
'loggers': {
'uvicorn': {
'propagate': True
},
'fastapi': {
'propagate': True
}
},
'root': {
'level': settings.log_level,
'handlers': ['console']
}
})
app = FastAPI(title="GWA Kubernetes API",
description="Description: API to create resources in Openshift using Kubectl",
version="1.0.0")
app.include_router(noop.router)
app.include_router(routes.router)
logger = logging.getLogger(__name__)
@app.exception_handler(RequestValidationError)
async def validation_exception_handler(request: Request, exc: RequestValidationError):
return JSONResponse(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
content=jsonable_encoder({"detail": exc.errors(), "body": exc.body}),
)
@app.get("/health")
async def get_health():
return {"status": "up"}
@app.get("/")
def main():
title = """
<h1>
GWA KUBE API
</h1> """
return HTMLResponse(title)