pipeline_core/wwwroot/secrets/get_secret_audit.dspy

25 lines
931 B
Plaintext

# get_secret_audit.dspy - 我的凭据操作审计(仅本人/本机构相关记录)
import json
uid = await get_user()
if not uid:
return []
org = (await get_userorgid()) or ''
out = []
async with DBPools().sqlorContext('pipeline') as sor:
rows = await sor.sqlExe(
"SELECT action, detail, who, exe_timestamp FROM audit_log "
"WHERE (tenant_id=${u}$ OR tenant_id=${o}$) AND action LIKE ${p}$ "
"ORDER BY exe_timestamp DESC LIMIT 100",
{"u": uid, "o": org or '', "p": "secret_%"})
await sor.sqlExe("COMMIT", {})
for r in (rows or []):
d = dict(r)
out.append({
"action": str(d.get("action", "")),
"detail": str(d.get("detail", ""))[:120],
"who": str(d.get("who", "")),
"created_at": str(d.get("exe_timestamp", ""))[:19],
})
# Tabular 数据契约 = {total, rows}(同 get_user_secrets 实测教训)
return {"total": len(out), "rows": out}