555e282cc4
pi-agent-plugin checks / lint (push) Has been cancelled
pi-agent-plugin checks / test (20) (push) Has been cancelled
pi-agent-plugin checks / test (22) (push) Has been cancelled
pi-agent-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / check_changes (push) Has been cancelled
TypeScript SDK CI / changelog_check (push) Has been cancelled
ci / changelog_check (push) Has been cancelled
ci / check_changes (push) Has been cancelled
ci / build_mem0 (3.10) (push) Has been cancelled
ci / build_mem0 (3.11) (push) Has been cancelled
ci / build_mem0 (3.12) (push) Has been cancelled
CLI Node CI / lint (push) Has been cancelled
CLI Node CI / test (20) (push) Has been cancelled
CLI Node CI / test (22) (push) Has been cancelled
CLI Node CI / build (push) Has been cancelled
CLI Python CI / lint (push) Has been cancelled
CLI Python CI / test (3.10) (push) Has been cancelled
CLI Python CI / test (3.11) (push) Has been cancelled
CLI Python CI / test (3.12) (push) Has been cancelled
CLI Python CI / build (push) Has been cancelled
openclaw checks / lint (push) Has been cancelled
openclaw checks / test (20) (push) Has been cancelled
openclaw checks / test (22) (push) Has been cancelled
openclaw checks / build (push) Has been cancelled
opencode-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (22) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (22) (push) Has been cancelled
47 lines
1.0 KiB
Python
47 lines
1.0 KiB
Python
import uuid
|
|
from datetime import datetime
|
|
|
|
from auth import require_admin
|
|
from db import get_db
|
|
from fastapi import APIRouter, Depends, Query
|
|
from models import RequestLog
|
|
from pydantic import BaseModel
|
|
from sqlalchemy import select
|
|
from sqlalchemy.orm import Session
|
|
|
|
router = APIRouter(prefix="/requests", tags=["requests"])
|
|
|
|
|
|
class RequestLogItem(BaseModel):
|
|
id: uuid.UUID
|
|
method: str
|
|
path: str
|
|
status_code: int
|
|
latency_ms: float
|
|
auth_type: str
|
|
created_at: datetime
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
API_KEY_AUTH_TYPES = ("api_key", "admin_api_key")
|
|
|
|
|
|
@router.get("", response_model=list[RequestLogItem])
|
|
def list_requests(
|
|
_auth=Depends(require_admin),
|
|
db: Session = Depends(get_db),
|
|
limit: int = Query(default=50, ge=1, le=200),
|
|
):
|
|
logs = (
|
|
db.execute(
|
|
select(RequestLog)
|
|
.where(RequestLog.auth_type.in_(API_KEY_AUTH_TYPES))
|
|
.order_by(RequestLog.created_at.desc())
|
|
.limit(limit)
|
|
)
|
|
.scalars()
|
|
.all()
|
|
)
|
|
return logs
|