Skip to content

Commit f48946a

Browse files
way better
1 parent 85b4257 commit f48946a

File tree

4 files changed

+101
-4
lines changed

4 files changed

+101
-4
lines changed

src/rb-api/poetry.lock

+88-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rb-api/pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ packages = [{ include = "rb", from = "." }]
99
python = "^3.11"
1010
fastapi = "^0.115.4"
1111
uvicorn = "^0.32.0"
12+
jinja2 = "^3.1.4"
13+
1214

1315
rescuebox = { path = "../../", develop = true }
1416
rb-lib = { path = "../rb-lib", develop = true }

src/rb-api/rb/api/routes/cli.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from functools import wraps
22
from typing import Callable
33

4-
from fastapi import APIRouter, HTTPException
4+
from fastapi import APIRouter, Depends, HTTPException
55
from rb.api.models import CommandResult
66
from rb.lib.stdout import Capturing # type: ignore
77

@@ -10,7 +10,11 @@
1010
cli_router = APIRouter()
1111

1212

13-
def safe_endpoint(callback: Callable, *args, **kwargs) -> CommandResult:
13+
def cli_flags(help: bool = False, stream: bool = False):
14+
return {"help": help, "stream": stream}
15+
16+
17+
def static_endpoint(callback: Callable, *args, **kwargs) -> CommandResult:
1418
with Capturing() as stdout:
1519
try:
1620
result = callback(*args, **kwargs)
@@ -26,7 +30,7 @@ def safe_endpoint(callback: Callable, *args, **kwargs) -> CommandResult:
2630
def command_callback(callback: Callable):
2731
@wraps(callback)
2832
def wrapper(*args, **kwargs):
29-
result = safe_endpoint(callback, *args, **kwargs)
33+
result = static_endpoint(callback, *args, **kwargs)
3034
if not result.success:
3135
# Return the last 10 lines of stdout
3236
raise HTTPException(
@@ -47,5 +51,6 @@ def wrapper(*args, **kwargs):
4751
methods=["POST"],
4852
name=command.callback.__name__,
4953
response_model=CommandResult,
54+
dependencies=[Depends(cli_flags)],
5055
)
5156
cli_router.include_router(router, prefix=f"/{plugin.name}", tags=[plugin.name])

src/rb-api/run

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
poetry run python -m rb.api.main

0 commit comments

Comments
 (0)