Skip to content

Commit

Permalink
Merge pull request #11 from mradigen/master
Browse files Browse the repository at this point in the history
Chore: Poetry update and docs typo fix
  • Loading branch information
Meetesh-Saini authored Dec 20, 2023
2 parents 9c327f5 + e5f922d commit f6474df
Show file tree
Hide file tree
Showing 2 changed files with 455 additions and 524 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# CTF Backend

## Tech Stack:
- Framework: **FastAPI**
- Database: **PostgreSQL (ORM: Tortoise)**
- Server: **Uvicorn**
- Test: **TestClient (in FastAPI) / Tox**
- Containerization: **Docker**
- CI/CD: **Github Actions** and ship to **Github packages**

- Framework: **FastAPI**
- Database: **PostgreSQL (ORM: Tortoise)**
- Server: **Uvicorn**
- Test: **TestClient (in FastAPI) / Tox**
- Containerization: **Docker**
- CI/CD: **Github Actions** and ship to **Github packages**

## Setup:

```sh
pip install poetry
python -m venv .venv # Create a python virtual environment
Expand All @@ -17,15 +19,17 @@ poetry install # Install the dependencies
```

## Run:

```sh
python -m uvicorn app:app --reload
python -m uvicorn pwncore:app --reload
```

## Testing:

Take a look at `tests/test_login.py` as an example on writing tests.

A Github Workflow is set to automatically run pytest on all filenames beginning with `test` under tox. Regardless, you might want to run the tests on your machine locally before pushing:

```sh
tox
```
Expand All @@ -41,6 +45,7 @@ All individual routes (`/team/*`, `/ctf/*`) are then put behind `/api` in the `r
In case a certain route has multiple complex tasks, they can be separated as a submodule. For example, the route `/api/ctf/start` will perform a lot of tasks (interacting with docker etc.), and hence has a separate file for it.

`src/`:

```
docs.py # Takes metadata from each route and compiles it for FastAPI
config.py # Configuration variables
Expand All @@ -65,6 +70,7 @@ FastAPI generates documentation for the routes using OpenAPI. The documentation
There are 2 ways to add documentation for a route:

1. Explicitly mention the summary and description:

```py
@router.get("/start/{ctf_id}",
description="This description supports **Markdown**.",
Expand All @@ -73,6 +79,7 @@ There are 2 ways to add documentation for a route:
```

2. Let it infer summary from function name and description from comments:

```py
@router.get("/start/{ctf_id}")
async def start_the_docker_container(ctf_id: int): # The function name is inferred for the summary
Expand Down
Loading

0 comments on commit f6474df

Please sign in to comment.