66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""script_engine 模块 RBAC 权限注册(显式路径,禁用通配符)。"""
|
|
import os
|
|
import sys
|
|
|
|
MODULE = 'script_engine'
|
|
|
|
PATHS_LOGINED = [
|
|
'/{0}'.format(MODULE),
|
|
'/{0}/index.ui'.format(MODULE),
|
|
'/{0}/script_engine'.format(MODULE),
|
|
'/{0}/script_engine/index.ui'.format(MODULE),
|
|
'/{0}/script_engine/get_script_engine.dspy'.format(MODULE),
|
|
'/{0}/script_engine/add_script_engine.dspy'.format(MODULE),
|
|
'/{0}/script_engine/update_script_engine.dspy'.format(MODULE),
|
|
'/{0}/script_engine/delete_script_engine.dspy'.format(MODULE),
|
|
'/{0}/api/execute_script.dspy'.format(MODULE),
|
|
'/{0}/api/validate_script.dspy'.format(MODULE),
|
|
'/{0}/api/script_engine_create.dspy'.format(MODULE),
|
|
'/{0}/api/script_engine_update.dspy'.format(MODULE),
|
|
'/{0}/api/script_engine_delete.dspy'.format(MODULE),
|
|
'/{0}/api/get_search_world_id.dspy'.format(MODULE),
|
|
'/{0}/api/get_search_scene_id.dspy'.format(MODULE),
|
|
'/{0}/api/get_search_entity_id.dspy'.format(MODULE),
|
|
'/{0}/api/get_search_script_type.dspy'.format(MODULE),
|
|
'/{0}/api/get_search_status.dspy'.format(MODULE),
|
|
]
|
|
|
|
PATHS_ANY = []
|
|
|
|
|
|
def find_sage_root():
|
|
cur = os.path.dirname(os.path.abspath(__file__))
|
|
for _ in range(6):
|
|
if os.path.isdir(os.path.join(cur, 'wwwroot')) and os.path.isdir(os.path.join(cur, 'py3', 'bin')):
|
|
return cur
|
|
parent = os.path.dirname(cur)
|
|
if parent == cur:
|
|
break
|
|
cur = parent
|
|
return None
|
|
|
|
|
|
def main():
|
|
sage_root = find_sage_root()
|
|
if not sage_root:
|
|
print('[{0}] Sage root not found, skip RBAC registration'.format(MODULE))
|
|
return
|
|
sys.path.insert(0, sage_root)
|
|
try:
|
|
from set_role_perm import set_role_perm
|
|
except ImportError:
|
|
print('[{0}] set_role_perm not found, skip RBAC registration'.format(MODULE))
|
|
return
|
|
for path in PATHS_ANY:
|
|
set_role_perm(path, 'any')
|
|
for path in PATHS_LOGINED:
|
|
set_role_perm(path, 'logined')
|
|
print('[{0}] registered {1} any + {2} logined paths'.format(
|
|
MODULE, len(PATHS_ANY), len(PATHS_LOGINED)))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|