mirror of
https://github.com/Xevion/linkpulse.git
synced 2025-12-06 15:15:34 -06:00
Add misc router for health/migration routes, rename 'authentication' router to 'auth'
This commit is contained in:
@@ -10,7 +10,6 @@ from fastapi import FastAPI
|
|||||||
from fastapi.responses import ORJSONResponse
|
from fastapi.responses import ORJSONResponse
|
||||||
from fastapi_cache import FastAPICache
|
from fastapi_cache import FastAPICache
|
||||||
from fastapi_cache.backends.inmemory import InMemoryBackend
|
from fastapi_cache.backends.inmemory import InMemoryBackend
|
||||||
from fastapi_cache.decorator import cache
|
|
||||||
from linkpulse.logging import setup_logging
|
from linkpulse.logging import setup_logging
|
||||||
from linkpulse.middleware import LoggingMiddleware
|
from linkpulse.middleware import LoggingMiddleware
|
||||||
from linkpulse.utilities import get_db, is_development
|
from linkpulse.utilities import get_db, is_development
|
||||||
@@ -45,10 +44,11 @@ async def lifespan(_: FastAPI) -> AsyncIterator[None]:
|
|||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
from linkpulse.routers import authentication
|
from linkpulse.routers import auth, misc
|
||||||
|
|
||||||
app = FastAPI(lifespan=lifespan, default_response_class=ORJSONResponse)
|
app = FastAPI(lifespan=lifespan, default_response_class=ORJSONResponse)
|
||||||
app.include_router(authentication.router)
|
app.include_router(auth.router)
|
||||||
|
app.include_router(misc.router)
|
||||||
|
|
||||||
setup_logging()
|
setup_logging()
|
||||||
|
|
||||||
@@ -70,23 +70,3 @@ if is_development:
|
|||||||
|
|
||||||
app.add_middleware(LoggingMiddleware)
|
app.add_middleware(LoggingMiddleware)
|
||||||
app.add_middleware(CorrelationIdMiddleware)
|
app.add_middleware(CorrelationIdMiddleware)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/health")
|
|
||||||
async def health():
|
|
||||||
# TODO: Check database connection
|
|
||||||
return "OK"
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api/migration")
|
|
||||||
@cache(expire=60)
|
|
||||||
async def get_migration():
|
|
||||||
"""
|
|
||||||
Returns the details of the most recent migration.
|
|
||||||
"""
|
|
||||||
# Kind of insecure, but this is just a demo thing to show that migratehistory is available.
|
|
||||||
cursor = db.execute_sql(
|
|
||||||
"SELECT name, migrated_at FROM migratehistory ORDER BY migrated_at DESC LIMIT 1"
|
|
||||||
)
|
|
||||||
name, migrated_at = cursor.fetchone()
|
|
||||||
return {"name": name, "migrated_at": migrated_at}
|
|
||||||
|
|||||||
27
backend/linkpulse/routers/misc.py
Normal file
27
backend/linkpulse/routers/misc.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
from fastapi import APIRouter
|
||||||
|
from fastapi_cache.decorator import cache
|
||||||
|
from linkpulse.utilities import get_db
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
db = get_db()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/health")
|
||||||
|
async def health():
|
||||||
|
# TODO: Check database connection
|
||||||
|
return "OK"
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/api/migration")
|
||||||
|
@cache(expire=60)
|
||||||
|
async def get_migration():
|
||||||
|
"""
|
||||||
|
Returns the details of the most recent migration.
|
||||||
|
"""
|
||||||
|
# Kind of insecure, but this is just a demo thing to show that migratehistory is available.
|
||||||
|
cursor = db.execute_sql(
|
||||||
|
"SELECT name, migrated_at FROM migratehistory ORDER BY migrated_at DESC LIMIT 1"
|
||||||
|
)
|
||||||
|
name, migrated_at = cursor.fetchone()
|
||||||
|
return {"name": name, "migrated_at": migrated_at}
|
||||||
@@ -6,7 +6,7 @@ from linkpulse.models import Session
|
|||||||
from linkpulse.tests.random import random_string
|
from linkpulse.tests.random import random_string
|
||||||
from linkpulse.tests.test_user import user
|
from linkpulse.tests.test_user import user
|
||||||
from linkpulse.utilities import utc_now
|
from linkpulse.utilities import utc_now
|
||||||
from linkpulse.routers.authentication import validate_session
|
from linkpulse.routers.auth import validate_session
|
||||||
|
|
||||||
from peewee import IntegrityError
|
from peewee import IntegrityError
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user