Skip to content

Commit

Permalink
🎨 added frontend api and runs
Browse files Browse the repository at this point in the history
  • Loading branch information
Wytamma committed Aug 11, 2021
1 parent df4bb4b commit 2ba5527
Show file tree
Hide file tree
Showing 104 changed files with 595 additions and 2,572 deletions.
2 changes: 1 addition & 1 deletion backend/beastiary/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .main import app
from .main import api
2 changes: 0 additions & 2 deletions backend/beastiary/api/endpoints/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

@router.get("/", response_model=List[schemas.Run])
def get_runs(
token: str = None,
db: Session = Depends(deps.get_db),
skip: int = 0,
limit: int = 100,
Expand All @@ -37,7 +36,6 @@ def get_headers(path):
@router.post("/", response_model=schemas.Run)
def create_run(
*,
token: str = None,
db: Session = Depends(deps.get_db),
run_in: schemas.RunCreate,
) -> Any:
Expand Down
1 change: 0 additions & 1 deletion backend/beastiary/api/endpoints/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def get_samples(
run_id: int,
limit: int = 100,
get_all: bool = False,
token: str = None,
db: Session = Depends(deps.get_db),
) -> Any:
"""
Expand Down
26 changes: 16 additions & 10 deletions backend/beastiary/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,54 @@

from beastiary.api.endpoints import runs, samples

app = FastAPI()
api = FastAPI()


@app.get("/")
@api.get("/")
async def index():
return FileResponse("beastiary/webapp-dist/index.html")


@app.get("/api/security/token", tags=["security"])
@api.get("/api/security/token", tags=["security"])
async def test_token() -> Any:
return {"data": app.token}
return {"data": api.token}


api_router = APIRouter(prefix="/api")
api_router.include_router(samples.router, prefix="/samples", tags=["samples"])
api_router.include_router(runs.router, prefix="/runs", tags=["runs"])
app.include_router(api_router)
api.include_router(api_router)

api.mount("/", StaticFiles(directory="beastiary/webapp-dist"))

app.mount("/", StaticFiles(directory="beastiary/webapp-dist"))


@app.middleware("http")
@api.middleware("http")
async def auth_check(request: Request, call_next):
if "/api/" in request.url.path and request.app.security == True:
token = request.headers.get("Authorization").split()[1]
if not token:
return JSONResponse(
content={"detail": "Authorization header not provided!"},
status_code=401,
)
else:
token = token.split()[1]
print(token)
if token != request.app.token:
return JSONResponse(content={"detail": "Invalid token!"}, status_code=401)
response = await call_next(request)
return response


@app.middleware("http")
@api.middleware("http")
async def add_custom_header(request: Request, call_next):
response = await call_next(request)
if response.status_code == 404:
return FileResponse("beastiary/webapp-dist/index.html")
return response


app.add_middleware(
api.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
Expand Down
8 changes: 4 additions & 4 deletions backend/beastiary/main.py → backend/beastiary/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import typer
import uvicorn

from .api import app as api
from .api import api
from beastiary.db.init_db import init_db
from beastiary.db.session import SessionLocal
import uuid
Expand All @@ -17,14 +17,14 @@
def main(
debug: bool = typer.Option(False, help="Set debug mode."),
security: bool = typer.Option(True, help="Turn off token requirement."),
host: str = typer.Argument("127.0.0.1"),
port: str = typer.Argument(5000),
token: str = typer.Option(str(uuid.uuid4())),
host: str = typer.Option("127.0.0.1"),
port: str = typer.Option(5000),
):
"""
Realtime and remote trace inspection with BEASTIARY.
"""
typer.echo("🐁 STARTING BEASTIARY 🐁")
token = str(uuid.uuid4())
typer.echo(f"Go to http://{host}:{port}/login?token={token}")
typer.echo(f"If prompted enter token: {token}")
api.token = token
Expand Down
5 changes: 5 additions & 0 deletions backend/beastiary/webapp-dist/css/chunk-vendors.1c5e8582.css

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions backend/beastiary/webapp-dist/css/chunk-vendors.d2c19747.css

This file was deleted.

1 change: 1 addition & 0 deletions backend/beastiary/webapp-dist/css/login.713abf43.css

Large diffs are not rendered by default.

Large diffs are not rendered by default.

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

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

Loading

0 comments on commit 2ba5527

Please sign in to comment.