Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,9 @@ ASCII art text. Returns string.
## Development

```
brew bundle
uv sync --locked
```

```
prek install
```

```
uv sync --locked
```
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ tlacuilo = "tlacuilo.api.routes:main"

[dependency-groups]
dev = [
"prek>=0.3.8",
"pytest>=9.0.2",
"pytest-cov>=7.0.0",
"ruff>=0.14.14",
Expand Down
13 changes: 13 additions & 0 deletions src/tlacuilo/api/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from fastapi import HTTPException, Security
from fastapi.security import APIKeyHeader

from tlacuilo.core import config

API_KEY = config.API_KEY
api_key_header = APIKeyHeader(name="X-API-Key")


def verify_key(key: str = Security(api_key_header)):
if key != API_KEY:
raise HTTPException(status_code=403, detail="Invalid API Key")
return key
5 changes: 3 additions & 2 deletions src/tlacuilo/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import os

import uvicorn
from fastapi import FastAPI
from fastapi import Depends, FastAPI
from pydantic import BaseModel

from tlacuilo.api.auth import verify_key
from tlacuilo.core.config import BUILTIN_TEMPLATES_DIR, USER_TEMPLATES_DIR
from tlacuilo.core.log_config import LOGGING_CONFIG
from tlacuilo.printer.print import render_and_execute_template
Expand All @@ -20,7 +21,7 @@ class TodoRequest(BaseModel):
todo: str


@app.post("/todo")
@app.post("/todo", dependencies=[Depends(verify_key)])
def create_todo(req: TodoRequest):
log.info("Todo Received")
printer = get_printer()
Expand Down
2 changes: 2 additions & 0 deletions src/tlacuilo/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@

USER_TEMPLATES_DIR = Path("templates")
BUILTIN_TEMPLATES_DIR = Path("src/tlacuilo/templates/builtin")

API_KEY = os.getenv("API_KEY")
26 changes: 26 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading