summaryrefslogtreecommitdiff
path: root/__main__.py
blob: 9dba64531db4594442fff1cfab8fe0e92070712c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from contextlib import asynccontextmanager
from typing import Annotated

from fastapi import FastAPI, Depends

from .apirouters import agents
from .modules import database


@asynccontextmanager
async def lifespan(app: FastAPI):
    database.cursor.execute(
        "CREATE TABLE IF NOT EXISTS agents(primary_key INTEGER PRIMARY KEY, callsign TEXT NOT NULL UNIQUE, token_hash TEXT NOT NULL)")
    yield


app = FastAPI(lifespan=lifespan)
app.include_router(agents.router)


@app.get("/{callsign}/tasks")
async def get_tasks(callsign: str, token: Annotated[str, Depends(agents.oauth2_scheme)]):
    return f'{{"callsign": "{callsign}", "token": "{token}"}}'