优化白名单函数实现机制
This commit is contained in:
parent
eed34b73e4
commit
fa42e6bb00
@ -63,7 +63,11 @@ async def handle_request(request: Request, module_path: str):
|
|||||||
处理白名单路由请求
|
处理白名单路由请求
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# 首先检查是否是白名单函数
|
# 解析模块路径并先导入模块,确保装饰器执行
|
||||||
|
module_info = parse_module_path(module_path)
|
||||||
|
module = import_module(module_info['module_path'])
|
||||||
|
|
||||||
|
# 模块导入后再检查是否是白名单函数
|
||||||
if is_whitelisted(module_path):
|
if is_whitelisted(module_path):
|
||||||
whitelist_info = get_whitelisted_function(module_path)
|
whitelist_info = get_whitelisted_function(module_path)
|
||||||
func = whitelist_info['function']
|
func = whitelist_info['function']
|
||||||
@ -88,14 +92,7 @@ async def handle_request(request: Request, module_path: str):
|
|||||||
"data": result
|
"data": result
|
||||||
})
|
})
|
||||||
|
|
||||||
# 如果不是白名单函数,使用原有的动态导入方式
|
# 非白名单:按原逻辑调用模块函数
|
||||||
# 解析模块路径
|
|
||||||
module_info = parse_module_path(module_path)
|
|
||||||
|
|
||||||
# 动态导入模块
|
|
||||||
module = import_module(module_info['module_path'])
|
|
||||||
|
|
||||||
# 获取函数
|
|
||||||
function_name = module_info['function_name']
|
function_name = module_info['function_name']
|
||||||
if not hasattr(module, function_name):
|
if not hasattr(module, function_name):
|
||||||
raise HTTPException(status_code=404, detail=f"Function {function_name} not found in module {module_info['module_path']}")
|
raise HTTPException(status_code=404, detail=f"Function {function_name} not found in module {module_info['module_path']}")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user