Skip to content

Commit

Permalink
Trace for the API requests (#83)
Browse files Browse the repository at this point in the history
* fix: CORS configuration

* trace for the api requests
  • Loading branch information
sanjibansg authored Feb 19, 2024
1 parent 8e99a4e commit 3478375
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 14 additions & 1 deletion api/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json

from fastapi import Request

import substrait_validator as sv
from duckdb import DuckDBPyConnection
from fastapi import (Depends, FastAPI, File, Form, HTTPException, UploadFile,
Expand Down Expand Up @@ -235,6 +237,7 @@ def add_schema(
############################################################
@router.post("/parse/", status_code=status.HTTP_200_OK)
def parse_to_substrait(
request: Request,
data: dict,
headers: dict = Depends(verify_token),
db_conn: DuckDBPyConnection = Depends(get_duck_conn),
Expand All @@ -252,7 +255,17 @@ def parse_to_substrait(
response (dict): Response JSON for translated
Substrait plan
'''
content_type = request.headers.get("Content-Type")
authorization = request.headers.get("Authorization")
url = request.url

logger.info("content type: " + str(content_type))
logger.info("authorization: " + str(authorization))
logger.info("url: " + str(url))
logger.info("headers: " + str(headers))
logger.info("input data: " + str(data))
response = parse_from_duckDB(data.get("query"), db_conn)
logger.info("Response: " + str(response))
return response


Expand All @@ -273,7 +286,7 @@ def substrait_fiddle_openapi():
return app.openapi_schema


app = FastAPI()
app = FastAPI(debug=True)
app.include_router(router, prefix="/api/route")
app.openapi = substrait_fiddle_openapi

Expand Down
3 changes: 3 additions & 0 deletions api/components/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os

from loguru import logger
import jwt
from fastapi import Depends, HTTPException, status
from fastapi.security import OAuth2PasswordBearer
Expand All @@ -11,8 +12,10 @@
############################################################
def verify_token(token: str = Depends(oauth2_scheme)):
try:
logger.info("token: " + str(token))
payload = jwt.decode(token, os.environ.get("VITE_SESSION_SECRET"),
algorithms=["HS256"])
logger.info("payload: " + str(payload))
return payload
except jwt.exceptions.DecodeError:
raise HTTPException(
Expand Down

0 comments on commit 3478375

Please sign in to comment.