Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joocer committed Jul 27, 2024
1 parent 091220c commit 562fc8d
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 16 deletions.
12 changes: 8 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@
from uvicorn import run

from tarchia import __version__
from tarchia.api.middlewares import AuditMiddleware
from tarchia.api.middlewares import AuthorizationMiddleware
from tarchia.api.middlewares import audit_middleware
from tarchia.api.middlewares import authorization_middleware
from tarchia.api.middlewares import brotli_middleware
from tarchia.api.middlewares import cors_middleware
from tarchia.api.v1 import v1_router

application = FastAPI(title="Tarchia Metastore", version=__version__)

application.include_router(v1_router)
application.add_middleware(AuthorizationMiddleware)
application.add_middleware(AuditMiddleware)
brotli_middleware.bind(application)
audit_middleware.bind(application)
authorization_middleware.bind(application)
cors_middleware.bind(application)

if __name__ == "__main__": # pragma: no cover
try:
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
brotli-asgi
cityhash
fastapi
fastavro
Expand All @@ -6,4 +7,5 @@ orjson
orso
pyarrow
pydantic
uvicorn
zstandard
2 changes: 0 additions & 2 deletions tarchia/api/middlewares/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
from .audit_middleware import AuditMiddleware
from .authorization_middleware import AuthorizationMiddleware
5 changes: 5 additions & 0 deletions tarchia/api/middlewares/audit_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from typing import Callable

import orjson
from fastapi import FastAPI
from fastapi import HTTPException
from fastapi import Request
from starlette.middleware.base import BaseHTTPMiddleware
Expand Down Expand Up @@ -75,3 +76,7 @@ async def dispatch(
audit_record["outcome"] = outcome

print(orjson.dumps(audit_record).decode())


def bind(app: FastAPI):
app.add_middleware(AuditMiddleware)
5 changes: 5 additions & 0 deletions tarchia/api/middlewares/authorization_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Awaitable
from typing import Callable

from fastapi import FastAPI
from fastapi import Request
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.responses import Response
Expand All @@ -33,3 +34,7 @@ async def dispatch(
return Response(status_code=403)

return await call_next(request)


def bind(app: FastAPI):
app.add_middleware(AuthorizationMiddleware)
6 changes: 6 additions & 0 deletions tarchia/api/middlewares/brotli_middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from brotli_asgi import BrotliMiddleware
from fastapi import FastAPI


def bind(app: FastAPI):
app.add_middleware(BrotliMiddleware)
14 changes: 14 additions & 0 deletions tarchia/api/middlewares/cors_middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

allowed_origins_regex = "http(s)?:\/\/.(localhost|.*\.run\.app)(:\d{1,5})?$"


def bind(app: FastAPI):
app.add_middleware(
CORSMiddleware,
allow_origin_regex=allowed_origins_regex,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
2 changes: 2 additions & 0 deletions tarchia/api/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .branch_management import router as branch_router
from .commit_management import router as commit_router
from .data_management import router as data_router
from .hook_management import router as hook_router
from .owner_management import router as owner_router
from .search import router as search_router
from .table_management import router as table_router
Expand All @@ -11,6 +12,7 @@
v1_router.include_router(branch_router, tags=["Branch Management"])
v1_router.include_router(commit_router, tags=["Commit Management"])
v1_router.include_router(data_router, tags=["Data Management"])
v1_router.include_router(hook_router, tags=["Hook Management"])
v1_router.include_router(owner_router, tags=["Owner Management"])
v1_router.include_router(search_router, tags=["Search"])
v1_router.include_router(table_router, tags=["Table Management"])
76 changes: 76 additions & 0 deletions tarchia/api/v1/hook_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"""
/tables/{owner}/{table}/hooks
/owners/{owner}/hooks
/{hook_id}/
/{hook_id}/ping
we only record the latest attempt
"""

from fastapi import APIRouter
from fastapi import Request
from fastapi.responses import ORJSONResponse

router = APIRouter()


@router.get("/tables/{owner}/{table}/hooks", response_class=ORJSONResponse)
async def get_table_hooks(request: Request, owner: str):
raise NotImplementedError("Not Implemented")


@router.post("/tables/{owner}/{table}/hooks", response_class=ORJSONResponse)
async def create_table_hooks(request: Request, owner: str):
raise NotImplementedError("Not Implemented")


@router.get("/tables/{owner}/{table}/hooks/{hook}", response_class=ORJSONResponse)
async def get_table_hooks_by_id(request: Request, owner: str):
raise NotImplementedError("Not Implemented")


@router.patch("/tables/{owner}/{table}/hooks/{hook}", response_class=ORJSONResponse)
async def update_table_hooks_by_id(request: Request, owner: str):
raise NotImplementedError("Not Implemented")


@router.delete("/tables/{owner}/{table}/hooks/{hook}", response_class=ORJSONResponse)
async def delete_table_hooks_by_id(request: Request, owner: str):
raise NotImplementedError("Not Implemented")


@router.get("/tables/{owner}/{table}/hooks/{hook}/ping", response_class=ORJSONResponse)
async def ping_table_hooks_by_id(request: Request, owner: str):
raise NotImplementedError("Not Implemented")


@router.get("/owner/{owner}/hooks", response_class=ORJSONResponse)
async def get_owner_hooks(request: Request, owner: str):
raise NotImplementedError("Not Implemented")


@router.post("/owner/{owner}/hooks", response_class=ORJSONResponse)
async def create_owner_hooks(request: Request, owner: str):
raise NotImplementedError("Not Implemented")


@router.get("/owner/{owner}/hooks/{hook}", response_class=ORJSONResponse)
async def get_owner_hooks_by_id(request: Request, owner: str):
raise NotImplementedError("Not Implemented")


@router.patch("/owner/{owner}/hooks/{hook}", response_class=ORJSONResponse)
async def update_owner_hooks_by_id(request: Request, owner: str):
raise NotImplementedError("Not Implemented")


@router.delete("/owner/{owner}/hooks/{hook}", response_class=ORJSONResponse)
async def delete_owner_hooks_by_id(request: Request, owner: str):
raise NotImplementedError("Not Implemented")


@router.get("/owner/{owner}/hooks/{hook}/ping", response_class=ORJSONResponse)
async def ping_owner_hooks_by_id(request: Request, owner: str):
raise NotImplementedError("Not Implemented")
10 changes: 0 additions & 10 deletions tarchia/api/v1/subscription_management.py

This file was deleted.

0 comments on commit 562fc8d

Please sign in to comment.