script_engine/scripts/load_path.py
2026-08-29 12:44:23 +08:00

60 lines
1.8 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
# -*- coding: utf-8 -*-
"""script_engine 模块 RBAC 显式路径注册(禁止通配符)。
运行方式(宿主应用内):
cd <SAGE_ROOT> && ./py3/bin/python <module>/scripts/load_path.py
"""
import os
import sys
MODULE = 'script_engine'
# 显式路径清单(无通配符)
PATHS_LOGINED = [
'/script_engine',
'/script_engine/index.ui',
'/script_engine/api/script_create.dspy',
'/script_engine/api/script_update.dspy',
'/script_engine/api/script_delete.dspy',
'/script_engine/api/script_get.dspy',
'/script_engine/api/script_list.dspy',
'/script_engine/api/script_execute.dspy',
'/script_engine/api/script_validate.dspy',
]
def _find_sage_root():
script_dir = os.path.dirname(os.path.abspath(__file__))
candidates = [
os.path.normpath(os.path.join(script_dir, '..', '..')),
os.path.expanduser('~/repos/sage'),
os.path.expanduser('~/sage'),
]
for cand in candidates:
if os.path.isdir(os.path.join(cand, 'wwwroot')) and os.path.isdir(os.path.join(cand, 'py3', 'bin')):
return cand
return None
def main():
sage_root = _find_sage_root()
if not sage_root:
print('[%s] 未找到宿主 Sage/wwwroot跳过 RBAC 注册' % MODULE)
sys.exit(0)
sys.path.insert(0, sage_root)
sys.path.insert(0, os.path.join(sage_root, 'py3', 'bin'))
try:
from set_role_perm import set_role_perm
except Exception as e:
print('[%s] 无法导入 set_role_perm: %s' % (MODULE, e))
sys.exit(1)
for path in PATHS_LOGINED:
set_role_perm(path, 'logined')
print('[%s] 已注册 %s -> logined' % (MODULE, path))
print('[%s] RBAC 注册完成(%d 条)' % (MODULE, len(PATHS_LOGINED)))
if __name__ == '__main__':
main()