def api_permission_control(request_info):
"""
API权限控制装饰器
:param info:
:return:
"""
def _access_control(func):
def wrap_func(*args, *kwargs):
try:
endpoint = request_info.endpoint
http_method = request_info.method
headers = request_info.headers
user_id = headers["User-Id"]
role = get_role(user_id)
Permissions = get_api_permission()
res=Permissions[role][endpoint][http_method]
if not method_dict[res]:
return jsonify({‘error‘: ‘no permission‘,"code":403})
return func(args, **kwargs)
except KeyError:
return jsonify({‘error‘: ‘no permission‘,"code":403})
except Exception as e:
return jsonify({‘error‘: ‘api permission control error,error msg %s‘ % str(e), "code": 500})
return wrap_func
return _access_control
原文地址:http://blog.51cto.com/yylinux/2059054
时间: 2024-10-11 10:45:30