app_audit/scripts/load_path.py
yumoqing 6bcc1469eb feat: app_audit 审计日志全局模块(独立仓库)
- audit_service.py: audit_log 写入 + is_audit_role + list/backup/delete
- init.py: load_app_audit 建 sd_audit_logs 表 + owner.audit 角色
- audit.dspy: list/backup/delete 仅 owner.audit(审计独立性)
- models + load_path.py + README
2026-08-14 12:19:38 +08:00

50 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""RBAC path registration for app_audit module.
审计 API 仅 owner.audit 角色审计独立性superuser 也不给)。
"""
import os, sys, subprocess
MOD = "app_audit"
# 审计日志 API仅 owner.audit 角色
PATHS_AUDIT = [
f"/{MOD}/api/audit.dspy",
]
def find_app_root():
# 从 scripts/ 向上逐层查找 set_role_perm.py位于宿主 app 根目录)
d = os.path.dirname(os.path.abspath(__file__))
for _ in range(6):
if os.path.isfile(os.path.join(d, "set_role_perm.py")):
return d
parent = os.path.dirname(d)
if parent == d:
break
d = parent
return None
def main():
root = find_app_root()
if not root:
print("ERROR: app root not found")
sys.exit(1)
set_perm = os.path.join(root, "set_role_perm.py")
py = sys.executable
count = 0
for role, paths in [("owner.audit", PATHS_AUDIT)]:
for path in paths:
cmd = [py, set_perm, role, path]
r = subprocess.run(cmd, capture_output=True, text=True, cwd=root)
if r.returncode == 0:
count += 1
else:
print(f" WARN: {path} -> {r.stderr.strip()[-80:]}")
print(f"Registered {count}/{len(PATHS_AUDIT)} paths for {MOD}")
if __name__ == "__main__":
main()