forked from lugvitc/pwncore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add app_lifespan and make start.py adhere with models from lug…
- Loading branch information
Showing
6 changed files
with
86 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,33 @@ | ||
from fastapi import FastAPI | ||
from contextlib import asynccontextmanager | ||
|
||
from tortoise.contrib.fastapi import register_tortoise | ||
|
||
import pwncore.docs as docs | ||
import pwncore.routes as routes | ||
from pwncore.container import docker_client | ||
from pwncore.config import config | ||
|
||
app = FastAPI( | ||
title="Pwncore", openapi_tags=docs.tags_metadata, description=docs.description | ||
) | ||
|
||
app.include_router(routes.router) | ||
@asynccontextmanager | ||
async def app_lifespan(app: FastAPI): | ||
# Startup | ||
register_tortoise( | ||
app, | ||
db_url=config.db_url, | ||
modules={"models": ["pwncore.models"]}, | ||
generate_schemas=True, | ||
add_exception_handlers=True, | ||
) | ||
yield | ||
# Shutdown | ||
await docker_client.close() | ||
|
||
register_tortoise( | ||
app, | ||
db_url=config.db_url, | ||
modules={"models": ["pwncore.db"]}, | ||
generate_schemas=True, | ||
add_exception_handlers=True | ||
|
||
app = FastAPI( | ||
title="Pwncore", | ||
openapi_tags=docs.tags_metadata, | ||
description=docs.description, | ||
lifespan=app_lifespan, | ||
) | ||
app.include_router(routes.router) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,3 @@ | ||
import aiodocker | ||
import atexit | ||
import asyncio | ||
|
||
docker_client = aiodocker.Docker() | ||
|
||
|
||
async def docker_cleanup(): | ||
await docker_client.close() | ||
|
||
atexit.register(lambda: asyncio.run(docker_cleanup())) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters