提交 35a7df2776d53c92b0badbb7fc06c63dc8b3e46b

作者 qianyingz
1 个父辈 34516e9b

除service模块外接口控制

  1 +from functools import wraps
  2 +from re import I
  3 +from authlib.integrations.flask_oauth2 import current_token
  4 +from flask import abort
  5 +from sqlalchemy.sql.elements import Null
  6 +from sqlalchemy.sql.functions import mode
  7 +from app.util.component.ParameterUtil import ParameterUtil
  8 +from app.models import db
  9 +from app.modules.auth.oauth2 import require_oauth
  10 +
  11 +# 认证装饰器
  12 +
  13 +class auth_decorator(object):
  14 + def __init__(self, action='', permission=''):
  15 + self.permission = permission
  16 + self.action = action
  17 +
  18 + def __call__(self, func):
  19 + @wraps(func)
  20 + @require_oauth("profile")
  21 + def wrapped_function(*args, **kwargs):
  22 + if current_token and current_token.user and current_token.user.role:
  23 + print(func.__name__)
  24 + if self.permission and len(self.permission) > 0:
  25 + # 判断角色是否在permission列表中
  26 + role = current_token.user.role
  27 + for p in self.permission:
  28 + if role == p:
  29 + return func(*args, **kwargs)
  30 +
  31 + abort(403)
  32 + else:
  33 + # 无permission,不校验
  34 + return func(*args, **kwargs)
  35 + else:
  36 + pass # 无token,401
  37 +
  38 + return wrapped_function
@@ -10,6 +10,8 @@ from .oauth2 import authorization, require_oauth, generate_user_info @@ -10,6 +10,8 @@ from .oauth2 import authorization, require_oauth, generate_user_info
10 from authlib.oauth2 import OAuth2Error 10 from authlib.oauth2 import OAuth2Error
11 from authlib.integrations.flask_oauth2 import current_token 11 from authlib.integrations.flask_oauth2 import current_token
12 from . import user_create, client_create, client_query, user_query, user_update, user_delete 12 from . import user_create, client_create, client_query, user_query, user_update, user_delete
  13 +import configure
  14 +from app.decorators.auth_decorator import auth_decorator
13 15
14 16
15 def current_user(): 17 def current_user():
@@ -32,68 +34,6 @@ def split_by_crlf(s): @@ -32,68 +34,6 @@ def split_by_crlf(s):
32 class DataManager(BlueprintApi): 34 class DataManager(BlueprintApi):
33 bp = Blueprint("Auth", __name__, url_prefix="/auth") 35 bp = Blueprint("Auth", __name__, url_prefix="/auth")
34 36
35 - # @staticmethod  
36 - # @bp.route("/test", methods=("GET", "POST"))  
37 - # def Test():  
38 - # res = {}  
39 - # try:  
40 - # res["user"] = User.query.all()  
41 - # except Exception as e:  
42 - # raise e  
43 - # return res  
44 -  
45 - # @staticmethod  
46 - # @bp.route("/login", methods=("GET", "POST"))  
47 - # def Login():  
48 - # if request.method == "POST":  
49 - # username = request.form["username"]  
50 - # password = request.form["password"]  
51 - # user = User.query.filter_by(username=username).first()  
52 - # if not user:  
53 - # user = User(username=username,  
54 - # password=password, role="admin")  
55 - # db.session.add(user)  
56 - # db.session.commit()  
57 - # session["id"] = user.id  
58 - # return redirect("/auth/authorize")  
59 - # user = current_user()  
60 - # if user:  
61 - # clients = OAuth2Client.query.filter_by(user_id=user.id).all()  
62 - # else:  
63 - # clients = []  
64 - # return render_template("auth/authorize.html", user=user, clients=clients)  
65 -  
66 - # @staticmethod  
67 - # @bp.route("/create_client", methods=("GET", "POST"))  
68 - # def create_client():  
69 - # user = current_user()  
70 - # if not user:  
71 - # return redirect("/auth/login")  
72 - # if request.method == "GET":  
73 - # return render_template("auth/create_client.html")  
74 - # form = request.form  
75 - # client_id = gen_salt(24)  
76 - # client = OAuth2Client(client_id=client_id, user_id=user.id)  
77 - # # Mixin doesn"t set the issue_at date  
78 - # client.client_id_issued_at = int(time.time())  
79 - # if client.token_endpoint_auth_method == "none":  
80 - # client.client_secret = ""  
81 - # else:  
82 - # client.client_secret = gen_salt(48)  
83 - # client_metadata = {  
84 - # "client_name": form["client_name"],  
85 - # "client_uri": form["client_uri"],  
86 - # "grant_types": split_by_crlf(form["grant_type"]),  
87 - # "redirect_uris": split_by_crlf(form["redirect_uri"]),  
88 - # "response_types": split_by_crlf(form["response_type"]),  
89 - # "scope": form["scope"],  
90 - # "token_endpoint_auth_method": form["token_endpoint_auth_method"]  
91 - # }  
92 - # client.set_client_metadata(client_metadata)  
93 - # db.session.add(client)  
94 - # db.session.commit()  
95 - # return redirect("/auth/login")  
96 -  
97 @staticmethod 37 @staticmethod
98 @bp.route("/authorize", methods=("GET", "POST")) 38 @bp.route("/authorize", methods=("GET", "POST"))
99 def authorize(): 39 def authorize():
@@ -132,10 +72,7 @@ class DataManager(BlueprintApi): @@ -132,10 +72,7 @@ class DataManager(BlueprintApi):
132 return jsonify(dict(error.get_body())) 72 return jsonify(dict(error.get_body()))
133 return render_template("auth/authorize.html", user=user, grant=grant, error=error) 73 return render_template("auth/authorize.html", user=user, grant=grant, error=error)
134 74
135 - # if request.form["confirm"]:  
136 - # grant_user = user  
137 - # else:  
138 - # grant_user = None 75 +
139 76
140 @staticmethod 77 @staticmethod
141 @bp.route("/token", methods=["POST"]) 78 @bp.route("/token", methods=["POST"])
@@ -153,7 +90,6 @@ class DataManager(BlueprintApi): @@ -153,7 +90,6 @@ class DataManager(BlueprintApi):
153 90
154 @staticmethod 91 @staticmethod
155 @bp.route("/logout", methods=["GET"]) 92 @bp.route("/logout", methods=["GET"])
156 - # @require_oauth("profile")  
157 def logout(): 93 def logout():
158 url = '' 94 url = ''
159 try: 95 try:
@@ -170,24 +106,13 @@ class DataManager(BlueprintApi): @@ -170,24 +106,13 @@ class DataManager(BlueprintApi):
170 except OAuth2Error as error: 106 except OAuth2Error as error:
171 return jsonify(dict(error.get_body())) 107 return jsonify(dict(error.get_body()))
172 return redirect(url) 108 return redirect(url)
173 - # if current_token:  
174 - # remove_user()  
175 - # # accesstoken = OAuth2Token.query.filter_by(  
176 - # # access_token=current_token.access_token).first()  
177 - # try:  
178 - # # accesstoken.revoked = True  
179 - # # db.session.commit()  
180 - # except error as e:  
181 - # return jsonify(dict(e.get_body()))  
182 - # else:  
183 - # return jsonify({"result": False, "message": "access_token is null"})  
184 -  
185 - # return jsonify({"result": True, "message": "logout success"})  
186 - 109 +
  110 +
187 """接口""" 111 """接口"""
188 @staticmethod 112 @staticmethod
189 @bp.route("/users", methods=["GET"]) 113 @bp.route("/users", methods=["GET"])
190 @swag_from(user_query.Api.api_doc) 114 @swag_from(user_query.Api.api_doc)
  115 + @auth_decorator(configure.UserPermission)
191 def user_query(): 116 def user_query():
192 """ 117 """
193 获取用户列表 118 获取用户列表
@@ -197,6 +122,7 @@ class DataManager(BlueprintApi): @@ -197,6 +122,7 @@ class DataManager(BlueprintApi):
197 @staticmethod 122 @staticmethod
198 @bp.route("/users", methods=["POST"]) 123 @bp.route("/users", methods=["POST"])
199 @swag_from(user_create.Api.api_doc) 124 @swag_from(user_create.Api.api_doc)
  125 + @auth_decorator(configure.UserPermission)
200 def user_create(): 126 def user_create():
201 """ 127 """
202 创建用户 128 创建用户
@@ -206,6 +132,7 @@ class DataManager(BlueprintApi): @@ -206,6 +132,7 @@ class DataManager(BlueprintApi):
206 @staticmethod 132 @staticmethod
207 @bp.route("/userEdit", methods=["POST"]) 133 @bp.route("/userEdit", methods=["POST"])
208 @swag_from(user_update.Api.api_doc) 134 @swag_from(user_update.Api.api_doc)
  135 + @auth_decorator(configure.UserPermission)
209 def user_update(): 136 def user_update():
210 """ 137 """
211 更新用户信息 138 更新用户信息
@@ -215,6 +142,7 @@ class DataManager(BlueprintApi): @@ -215,6 +142,7 @@ class DataManager(BlueprintApi):
215 @staticmethod 142 @staticmethod
216 @bp.route("/userDelete", methods=["POST"]) 143 @bp.route("/userDelete", methods=["POST"])
217 @swag_from(user_delete.Api.api_doc) 144 @swag_from(user_delete.Api.api_doc)
  145 + @auth_decorator(configure.UserPermission)
218 def user_delete(): 146 def user_delete():
219 """ 147 """
220 删除用户 148 删除用户
@@ -17,6 +17,8 @@ from . import database_edit @@ -17,6 +17,8 @@ from . import database_edit
17 from . import database_alias_check 17 from . import database_alias_check
18 from . import database_connect_test 18 from . import database_connect_test
19 from . import database_info 19 from . import database_info
  20 +import configure
  21 +from app.decorators.auth_decorator import auth_decorator
20 22
21 class DataManager(BlueprintApi): 23 class DataManager(BlueprintApi):
22 24
@@ -26,6 +28,7 @@ class DataManager(BlueprintApi): @@ -26,6 +28,7 @@ class DataManager(BlueprintApi):
26 @staticmethod 28 @staticmethod
27 @bp.route('/Register', methods=['POST']) 29 @bp.route('/Register', methods=['POST'])
28 @swag_from(database_register.Api.api_doc) 30 @swag_from(database_register.Api.api_doc)
  31 + @auth_decorator(configure.DataPermission)
29 def api_database_register(): 32 def api_database_register():
30 """ 33 """
31 数据源注册 34 数据源注册
@@ -35,6 +38,7 @@ class DataManager(BlueprintApi): @@ -35,6 +38,7 @@ class DataManager(BlueprintApi):
35 @staticmethod 38 @staticmethod
36 @bp.route('/List', methods=['POST']) 39 @bp.route('/List', methods=['POST'])
37 @swag_from(database_list.Api.api_doc) 40 @swag_from(database_list.Api.api_doc)
  41 + @auth_decorator(configure.DataPermission)
38 def api_database_list(): 42 def api_database_list():
39 """ 43 """
40 数据源列表 44 数据源列表
@@ -44,6 +48,7 @@ class DataManager(BlueprintApi): @@ -44,6 +48,7 @@ class DataManager(BlueprintApi):
44 @staticmethod 48 @staticmethod
45 @bp.route('/Delete', methods=['POST']) 49 @bp.route('/Delete', methods=['POST'])
46 @swag_from(database_delete.Api.api_doc) 50 @swag_from(database_delete.Api.api_doc)
  51 + @auth_decorator(configure.DataPermission)
47 def api_database_delete(): 52 def api_database_delete():
48 """ 53 """
49 数据源注销 54 数据源注销
@@ -53,6 +58,7 @@ class DataManager(BlueprintApi): @@ -53,6 +58,7 @@ class DataManager(BlueprintApi):
53 @staticmethod 58 @staticmethod
54 @bp.route('/Edit', methods=['POST']) 59 @bp.route('/Edit', methods=['POST'])
55 @swag_from(database_edit.Api.api_doc) 60 @swag_from(database_edit.Api.api_doc)
  61 + @auth_decorator(configure.DataPermission)
56 def database_edit(): 62 def database_edit():
57 """ 63 """
58 修改数据源 64 修改数据源
@@ -62,6 +68,7 @@ class DataManager(BlueprintApi): @@ -62,6 +68,7 @@ class DataManager(BlueprintApi):
62 @staticmethod 68 @staticmethod
63 @bp.route('/Test', methods=['POST']) 69 @bp.route('/Test', methods=['POST'])
64 @swag_from(database_test.Api.api_doc) 70 @swag_from(database_test.Api.api_doc)
  71 + @auth_decorator(configure.DataPermission)
65 def api_database_test(): 72 def api_database_test():
66 """ 73 """
67 数据源测试 74 数据源测试
@@ -71,6 +78,7 @@ class DataManager(BlueprintApi): @@ -71,6 +78,7 @@ class DataManager(BlueprintApi):
71 @staticmethod 78 @staticmethod
72 @bp.route('/CheckAlias', methods=['POST']) 79 @bp.route('/CheckAlias', methods=['POST'])
73 @swag_from(database_alias_check.Api.api_doc) 80 @swag_from(database_alias_check.Api.api_doc)
  81 + @auth_decorator(configure.DataPermission)
74 def api_database_alias_check(): 82 def api_database_alias_check():
75 """ 83 """
76 数据源别名测试 84 数据源别名测试
@@ -80,6 +88,7 @@ class DataManager(BlueprintApi): @@ -80,6 +88,7 @@ class DataManager(BlueprintApi):
80 @staticmethod 88 @staticmethod
81 @bp.route('/CheckConnect', methods=['POST']) 89 @bp.route('/CheckConnect', methods=['POST'])
82 @swag_from(database_connect_test.Api.api_doc) 90 @swag_from(database_connect_test.Api.api_doc)
  91 + @auth_decorator(configure.DataPermission)
83 def api_database_connect_test(): 92 def api_database_connect_test():
84 """ 93 """
85 数据源连接测试 94 数据源连接测试
@@ -13,6 +13,8 @@ from . import get_meta @@ -13,6 +13,8 @@ from . import get_meta
13 from . import data_entry_by_meta 13 from . import data_entry_by_meta
14 from . import get_data_list 14 from . import get_data_list
15 from . import data_entry_simple 15 from . import data_entry_simple
  16 +import configure
  17 +from app.decorators.auth_decorator import auth_decorator
16 18
17 class DataManager(BlueprintApi): 19 class DataManager(BlueprintApi):
18 20
@@ -21,6 +23,7 @@ class DataManager(BlueprintApi): @@ -21,6 +23,7 @@ class DataManager(BlueprintApi):
21 23
22 @staticmethod 24 @staticmethod
23 @bp.route('/Download/<file>', methods=['GET']) 25 @bp.route('/Download/<file>', methods=['GET'])
  26 + @auth_decorator(configure.DataPermission)
24 def table_download_file(file): 27 def table_download_file(file):
25 parent = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 28 parent = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
26 dirpath = os.path.join(parent,"file_tmp") 29 dirpath = os.path.join(parent,"file_tmp")
@@ -41,6 +44,7 @@ class DataManager(BlueprintApi): @@ -41,6 +44,7 @@ class DataManager(BlueprintApi):
41 44
42 @staticmethod 45 @staticmethod
43 @bp.route('/DeleteFile/<file>', methods=['GET']) 46 @bp.route('/DeleteFile/<file>', methods=['GET'])
  47 + @auth_decorator(configure.DataPermission)
44 def d_file(file): 48 def d_file(file):
45 parent = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 49 parent = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
46 dirpath = os.path.join(parent, "file_tmp") 50 dirpath = os.path.join(parent, "file_tmp")
@@ -59,6 +63,7 @@ class DataManager(BlueprintApi): @@ -59,6 +63,7 @@ class DataManager(BlueprintApi):
59 @staticmethod 63 @staticmethod
60 @bp.route('/DataDownloadTask', methods=['POST']) 64 @bp.route('/DataDownloadTask', methods=['POST'])
61 @swag_from(data_download_task.Api.api_doc) 65 @swag_from(data_download_task.Api.api_doc)
  66 + @auth_decorator(configure.DataPermission)
62 def api_data_download_task(): 67 def api_data_download_task():
63 """ 68 """
64 下载数据任务 69 下载数据任务
@@ -69,6 +74,7 @@ class DataManager(BlueprintApi): @@ -69,6 +74,7 @@ class DataManager(BlueprintApi):
69 @staticmethod 74 @staticmethod
70 @bp.route('/GetMeta', methods=['POST']) 75 @bp.route('/GetMeta', methods=['POST'])
71 @swag_from(get_meta.Api.api_doc) 76 @swag_from(get_meta.Api.api_doc)
  77 + @auth_decorator(configure.DataPermission)
72 def get_meta(): 78 def get_meta():
73 """ 79 """
74 数据Meta 80 数据Meta
@@ -78,6 +84,7 @@ class DataManager(BlueprintApi): @@ -78,6 +84,7 @@ class DataManager(BlueprintApi):
78 @staticmethod 84 @staticmethod
79 @bp.route('/GetDataList', methods=['POST']) 85 @bp.route('/GetDataList', methods=['POST'])
80 @swag_from(get_data_list.Api.api_doc) 86 @swag_from(get_data_list.Api.api_doc)
  87 + @auth_decorator(configure.DataPermission)
81 def get_data_list(): 88 def get_data_list():
82 """ 89 """
83 本地数据list 90 本地数据list
@@ -87,6 +94,7 @@ class DataManager(BlueprintApi): @@ -87,6 +94,7 @@ class DataManager(BlueprintApi):
87 @staticmethod 94 @staticmethod
88 @bp.route('/DataEntryByMeta', methods=['POST']) 95 @bp.route('/DataEntryByMeta', methods=['POST'])
89 @swag_from(data_entry_by_meta.Api.api_doc) 96 @swag_from(data_entry_by_meta.Api.api_doc)
  97 + @auth_decorator(configure.DataPermission)
90 def data_entry_by_meta(): 98 def data_entry_by_meta():
91 """ 99 """
92 数据入库ByMeta 100 数据入库ByMeta
@@ -96,6 +104,7 @@ class DataManager(BlueprintApi): @@ -96,6 +104,7 @@ class DataManager(BlueprintApi):
96 @staticmethod 104 @staticmethod
97 @bp.route('/DataEntrySimple', methods=['POST']) 105 @bp.route('/DataEntrySimple', methods=['POST'])
98 @swag_from(data_entry_simple.Api.api_doc) 106 @swag_from(data_entry_simple.Api.api_doc)
  107 + @auth_decorator(configure.DataPermission)
99 def data_entry_simple(): 108 def data_entry_simple():
100 """ 109 """
101 数据入库Simple 110 数据入库Simple
@@ -23,6 +23,9 @@ from . import table_vacuate_info @@ -23,6 +23,9 @@ from . import table_vacuate_info
23 from . import table_vacuate_ref 23 from . import table_vacuate_ref
24 from . import table_vacuate_delete 24 from . import table_vacuate_delete
25 from . import field_value 25 from . import field_value
  26 +import configure
  27 +from app.decorators.auth_decorator import auth_decorator
  28 +
26 class DataManager(BlueprintApi): 29 class DataManager(BlueprintApi):
27 30
28 bp = Blueprint("DataManager", __name__, url_prefix="/API/Manager") 31 bp = Blueprint("DataManager", __name__, url_prefix="/API/Manager")
@@ -30,6 +33,7 @@ class DataManager(BlueprintApi): @@ -30,6 +33,7 @@ class DataManager(BlueprintApi):
30 @staticmethod 33 @staticmethod
31 @bp.route('/FieldEdit', methods=['POST']) 34 @bp.route('/FieldEdit', methods=['POST'])
32 @swag_from(field_edit.Api.api_doc) 35 @swag_from(field_edit.Api.api_doc)
  36 + @auth_decorator(configure.DataPermission)
33 def field_edit(): 37 def field_edit():
34 """ 38 """
35 修改属性别名 39 修改属性别名
@@ -48,6 +52,7 @@ class DataManager(BlueprintApi): @@ -48,6 +52,7 @@ class DataManager(BlueprintApi):
48 @staticmethod 52 @staticmethod
49 @bp.route('/FieldValue', methods=['POST']) 53 @bp.route('/FieldValue', methods=['POST'])
50 @swag_from(field_value.Api.api_doc) 54 @swag_from(field_value.Api.api_doc)
  55 + @auth_decorator(configure.DataPermission)
51 def field_value(): 56 def field_value():
52 """ 57 """
53 属性值 58 属性值
@@ -67,6 +72,7 @@ class DataManager(BlueprintApi): @@ -67,6 +72,7 @@ class DataManager(BlueprintApi):
67 @staticmethod 72 @staticmethod
68 @bp.route('/TableEdit', methods=['POST']) 73 @bp.route('/TableEdit', methods=['POST'])
69 @swag_from(table_edit.Api.api_doc) 74 @swag_from(table_edit.Api.api_doc)
  75 + @auth_decorator(configure.DataPermission)
70 def table_edit(): 76 def table_edit():
71 """ 77 """
72 修改数据 78 修改数据
@@ -77,6 +83,7 @@ class DataManager(BlueprintApi): @@ -77,6 +83,7 @@ class DataManager(BlueprintApi):
77 @staticmethod 83 @staticmethod
78 @bp.route('/TableDelete', methods=['POST']) 84 @bp.route('/TableDelete', methods=['POST'])
79 @swag_from(table_delete.Api.api_doc) 85 @swag_from(table_delete.Api.api_doc)
  86 + @auth_decorator(configure.DataPermission)
80 def table_delete(): 87 def table_delete():
81 """ 88 """
82 删除数据 89 删除数据
@@ -97,6 +104,7 @@ class DataManager(BlueprintApi): @@ -97,6 +104,7 @@ class DataManager(BlueprintApi):
97 @staticmethod 104 @staticmethod
98 @bp.route('/TableRefresh', methods=['POST']) 105 @bp.route('/TableRefresh', methods=['POST'])
99 @swag_from(table_refresh.Api.api_doc) 106 @swag_from(table_refresh.Api.api_doc)
  107 + @auth_decorator(configure.DataPermission)
100 def table_refresh(): 108 def table_refresh():
101 """ 109 """
102 刷新数据 110 刷新数据
@@ -116,6 +124,7 @@ class DataManager(BlueprintApi): @@ -116,6 +124,7 @@ class DataManager(BlueprintApi):
116 @staticmethod 124 @staticmethod
117 @bp.route('/TableVacuate', methods=['POST']) 125 @bp.route('/TableVacuate', methods=['POST'])
118 @swag_from(table_vacuate.Api.api_doc) 126 @swag_from(table_vacuate.Api.api_doc)
  127 + @auth_decorator(configure.DataPermission)
119 def table_vacuate(): 128 def table_vacuate():
120 """ 129 """
121 数据抽稀 130 数据抽稀
@@ -125,6 +134,7 @@ class DataManager(BlueprintApi): @@ -125,6 +134,7 @@ class DataManager(BlueprintApi):
125 @staticmethod 134 @staticmethod
126 @bp.route('/TableVacuateOne', methods=['POST']) 135 @bp.route('/TableVacuateOne', methods=['POST'])
127 @swag_from(table_vacuate_one.Api.api_doc) 136 @swag_from(table_vacuate_one.Api.api_doc)
  137 + @auth_decorator(configure.DataPermission)
128 def api_table_vacuate_one(): 138 def api_table_vacuate_one():
129 """ 139 """
130 单独数据抽稀 140 单独数据抽稀
@@ -153,6 +163,7 @@ class DataManager(BlueprintApi): @@ -153,6 +163,7 @@ class DataManager(BlueprintApi):
153 @staticmethod 163 @staticmethod
154 @bp.route('/TableVacuateDelete', methods=['POST']) 164 @bp.route('/TableVacuateDelete', methods=['POST'])
155 @swag_from(table_vacuate_delete.Api.api_doc) 165 @swag_from(table_vacuate_delete.Api.api_doc)
  166 + @auth_decorator(configure.DataPermission)
156 def api_table_vacuate_delete(): 167 def api_table_vacuate_delete():
157 """ 168 """
158 数据抽稀删除 169 数据抽稀删除
@@ -11,6 +11,9 @@ from . import task_detail @@ -11,6 +11,9 @@ from . import task_detail
11 from . import task_delete 11 from . import task_delete
12 from . import task_count 12 from . import task_count
13 from . import task_kill 13 from . import task_kill
  14 +from app.decorators.auth_decorator import auth_decorator
  15 +import configure
  16 +from app.modules.auth.oauth2 import require_oauth
14 17
15 class DataManager(BlueprintApi): 18 class DataManager(BlueprintApi):
16 19
@@ -38,6 +41,7 @@ class DataManager(BlueprintApi): @@ -38,6 +41,7 @@ class DataManager(BlueprintApi):
38 @staticmethod 41 @staticmethod
39 @bp.route('/Delete', methods=['POST']) 42 @bp.route('/Delete', methods=['POST'])
40 @swag_from(task_delete.Api.api_doc) 43 @swag_from(task_delete.Api.api_doc)
  44 + @require_oauth("profile")
41 def task_delete(): 45 def task_delete():
42 """ 46 """
43 删除任务 47 删除任务
@@ -47,6 +51,7 @@ class DataManager(BlueprintApi): @@ -47,6 +51,7 @@ class DataManager(BlueprintApi):
47 @staticmethod 51 @staticmethod
48 @bp.route('/Kill', methods=['POST']) 52 @bp.route('/Kill', methods=['POST'])
49 @swag_from(task_kill.Api.api_doc) 53 @swag_from(task_kill.Api.api_doc)
  54 + @require_oauth("profile")
50 def task_kill(): 55 def task_kill():
51 """ 56 """
52 Kill任务 57 Kill任务
@@ -8,7 +8,8 @@ from flasgger import swag_from @@ -8,7 +8,8 @@ from flasgger import swag_from
8 from flask import Blueprint 8 from flask import Blueprint
9 from app.util import BlueprintApi 9 from app.util import BlueprintApi
10 from . import monitoring, metrics, monitor_host_create, monitor_host_list, monitor_host_delete, monitor_host_edit 10 from . import monitoring, metrics, monitor_host_create, monitor_host_list, monitor_host_delete, monitor_host_edit
11 - 11 +from app.decorators.auth_decorator import auth_decorator
  12 +import configure
12 13
13 user_socket_list = [] 14 user_socket_list = []
14 user_socket_dict = {} 15 user_socket_dict = {}
@@ -48,6 +49,7 @@ class Monitor(BlueprintApi): @@ -48,6 +49,7 @@ class Monitor(BlueprintApi):
48 @staticmethod 49 @staticmethod
49 @bp.route('/RegisterHost', methods=['POST']) 50 @bp.route('/RegisterHost', methods=['POST'])
50 @swag_from(monitor_host_create.Api.api_doc) 51 @swag_from(monitor_host_create.Api.api_doc)
  52 + @auth_decorator(configure.MonitorPermission)
51 def monitor_host_create(): 53 def monitor_host_create():
52 ''' 54 '''
53 注册监控主机 55 注册监控主机
@@ -66,6 +68,7 @@ class Monitor(BlueprintApi): @@ -66,6 +68,7 @@ class Monitor(BlueprintApi):
66 @staticmethod 68 @staticmethod
67 @bp.route('/HostDelete', methods=['POST']) 69 @bp.route('/HostDelete', methods=['POST'])
68 @swag_from(monitor_host_delete.Api.api_doc) 70 @swag_from(monitor_host_delete.Api.api_doc)
  71 + @auth_decorator(configure.MonitorPermission)
69 def monitor_host_delete(): 72 def monitor_host_delete():
70 ''' 73 '''
71 删除主机 74 删除主机
@@ -75,6 +78,7 @@ class Monitor(BlueprintApi): @@ -75,6 +78,7 @@ class Monitor(BlueprintApi):
75 @staticmethod 78 @staticmethod
76 @bp.route('/HostEdit', methods=['POST']) 79 @bp.route('/HostEdit', methods=['POST'])
77 @swag_from(monitor_host_edit.Api.api_doc) 80 @swag_from(monitor_host_edit.Api.api_doc)
  81 + @auth_decorator(configure.MonitorPermission)
78 def monitor_host_edit(): 82 def monitor_host_edit():
79 ''' 83 '''
80 编辑主机配置 84 编辑主机配置
@@ -22,6 +22,10 @@ swagger_configure = {"title": "DMapManager"} @@ -22,6 +22,10 @@ swagger_configure = {"title": "DMapManager"}
22 entry_data_thread = 3 22 entry_data_thread = 3
23 scan_module = ["app.modules"] # API所在的模块 23 scan_module = ["app.modules"] # API所在的模块
24 SECRET_KEY = b'_5#y2L"F4Q8z\n\xec]/' 24 SECRET_KEY = b'_5#y2L"F4Q8z\n\xec]/'
  25 +UserPermission = ['admin']
  26 +MonitorPermission = ['admin']
  27 +DataPermission = ['admin', 'dataman']
  28 +PublishPermission = ['admin', 'dataman', 'publisher']
25 29
26 log_level = logging.INFO 30 log_level = logging.INFO
27 31
注册登录 后发表评论