feat: add realtime capturing
This commit is contained in:
@@ -17,6 +17,8 @@ from utils.policy.resolver import resolve
|
||||
|
||||
router = APIRouter(prefix="/api/policy", tags=["policy"])
|
||||
|
||||
POLICY_CHANGED_CHANNEL = "policy_changed"
|
||||
|
||||
|
||||
class EffectiveQuery(BaseModel):
|
||||
account_id: int
|
||||
@@ -55,9 +57,11 @@ async def effective_policy(
|
||||
async def create_policy(
|
||||
pool: FromDishka[asyncpg.Pool], body: PolicyCreate
|
||||
) -> PolicyRecord:
|
||||
return await repository.create_policy(
|
||||
record = await repository.create_policy(
|
||||
pool, body.account_id, body.scope_type, body.scope_id, body
|
||||
)
|
||||
await pool.execute(f"NOTIFY {POLICY_CHANGED_CHANNEL}")
|
||||
return record
|
||||
|
||||
|
||||
@router.get("/{policy_id}")
|
||||
@@ -77,6 +81,7 @@ async def update_policy(
|
||||
record = await repository.update_policy(pool, policy_id, body)
|
||||
if record is None:
|
||||
raise HTTPException(status_code=404, detail="policy not found")
|
||||
await pool.execute(f"NOTIFY {POLICY_CHANGED_CHANNEL}")
|
||||
return record
|
||||
|
||||
|
||||
@@ -85,3 +90,4 @@ async def update_policy(
|
||||
async def delete_policy(pool: FromDishka[asyncpg.Pool], policy_id: int) -> None:
|
||||
if not await repository.delete_policy(pool, policy_id):
|
||||
raise HTTPException(status_code=404, detail="policy not found")
|
||||
await pool.execute(f"NOTIFY {POLICY_CHANGED_CHANNEL}")
|
||||
|
||||
Reference in New Issue
Block a user