提交 036571b376ed1c48c725957a756d241b43afd77f

作者 qianyingz
2 个父辈 34516e9b 97ad9010

权限控制

  1 +from functools import wraps
  2 +from authlib.integrations.flask_oauth2 import current_token
  3 +from flask import abort
  4 +from app.modules.auth.oauth2 import require_oauth
  5 +from flask import request
  6 +
  7 +# 认证装饰器
  8 +
  9 +
  10 +class auth_decorator(object):
  11 + def __init__(self, action='', permission='', scope='profile'):
  12 + self.permission = permission
  13 + self.action = action
  14 + self.scope = scope
  15 +
  16 + def __call__(self, func):
  17 +
  18 + @wraps(func)
  19 + def wrapped_function(*args, **kwargs):
  20 + token = request.headers.get('Authorization')
  21 + if not token:
  22 + abort(401)
  23 + validate_token()
  24 + if current_token and current_token.user and current_token.user.role:
  25 + print(func.__name__)
  26 + if self.permission and len(self.permission) > 0:
  27 + # 判断角色是否在permission列表中
  28 + role = current_token.user.role
  29 + for p in self.permission:
  30 + if role == p:
  31 + return func(*args, **kwargs)
  32 +
  33 + abort(403)
  34 + else:
  35 + # 无permission,不校验
  36 + return func(*args, **kwargs)
  37 + else:
  38 + abort(401) # 无token,401
  39 +
  40 + @require_oauth(self.scope)
  41 + def validate_token():
  42 + pass
  43 +
  44 + return wrapped_function
  1 +from functools import wraps
  2 +from authlib.integrations.flask_oauth2 import current_token
  3 +from flask import abort
  4 +from app.modules.auth.oauth2 import require_oauth
  5 +from flask import request
  6 +
  7 +# 认证装饰器
  8 +
  9 +
  10 +class token_decorator(object):
  11 + def __init__(self, scope='profile'):
  12 + self.scope = scope
  13 +
  14 + def __call__(self, func):
  15 + @wraps(func)
  16 + def wrapped_function(*args, **kwargs):
  17 + token = request.headers.get('Authorization')
  18 + if token:
  19 + validate_token()
  20 + if current_token and current_token.user:
  21 + return func(*args, **kwargs)
  22 + else:
  23 + abort(403)
  24 +
  25 + else:
  26 + abort(401) # 无token,401
  27 +
  28 + @require_oauth(self.scope)
  29 + def validate_token():
  30 + pass
  31 +
  32 + return wrapped_function
@@ -6,10 +6,13 @@ from app.util import BlueprintApi @@ -6,10 +6,13 @@ from app.util import BlueprintApi
6 from flask import Blueprint, render_template, redirect, request, session, jsonify 6 from flask import Blueprint, render_template, redirect, request, session, jsonify
7 from sqlalchemy import and_ 7 from sqlalchemy import and_
8 from .models import * 8 from .models import *
9 -from .oauth2 import authorization, require_oauth, generate_user_info 9 +from .oauth2 import authorization, 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
  15 +from app.decorators.token_decorator import token_decorator
13 16
14 17
15 def current_user(): 18 def current_user():
@@ -32,68 +35,6 @@ def split_by_crlf(s): @@ -32,68 +35,6 @@ def split_by_crlf(s):
32 class DataManager(BlueprintApi): 35 class DataManager(BlueprintApi):
33 bp = Blueprint("Auth", __name__, url_prefix="/auth") 36 bp = Blueprint("Auth", __name__, url_prefix="/auth")
34 37
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 38 @staticmethod
98 @bp.route("/authorize", methods=("GET", "POST")) 39 @bp.route("/authorize", methods=("GET", "POST"))
99 def authorize(): 40 def authorize():
@@ -132,10 +73,7 @@ class DataManager(BlueprintApi): @@ -132,10 +73,7 @@ class DataManager(BlueprintApi):
132 return jsonify(dict(error.get_body())) 73 return jsonify(dict(error.get_body()))
133 return render_template("auth/authorize.html", user=user, grant=grant, error=error) 74 return render_template("auth/authorize.html", user=user, grant=grant, error=error)
134 75
135 - # if request.form["confirm"]:  
136 - # grant_user = user  
137 - # else:  
138 - # grant_user = None 76 +
139 77
140 @staticmethod 78 @staticmethod
141 @bp.route("/token", methods=["POST"]) 79 @bp.route("/token", methods=["POST"])
@@ -144,7 +82,7 @@ class DataManager(BlueprintApi): @@ -144,7 +82,7 @@ class DataManager(BlueprintApi):
144 82
145 @staticmethod 83 @staticmethod
146 @bp.route("/userinfo") 84 @bp.route("/userinfo")
147 - @require_oauth("profile") 85 + @token_decorator("profile")
148 def api_me(): 86 def api_me():
149 try: 87 try:
150 return jsonify(generate_user_info(current_token.user, current_token.scope)) 88 return jsonify(generate_user_info(current_token.user, current_token.scope))
@@ -153,7 +91,6 @@ class DataManager(BlueprintApi): @@ -153,7 +91,6 @@ class DataManager(BlueprintApi):
153 91
154 @staticmethod 92 @staticmethod
155 @bp.route("/logout", methods=["GET"]) 93 @bp.route("/logout", methods=["GET"])
156 - # @require_oauth("profile")  
157 def logout(): 94 def logout():
158 url = '' 95 url = ''
159 try: 96 try:
@@ -170,24 +107,13 @@ class DataManager(BlueprintApi): @@ -170,24 +107,13 @@ class DataManager(BlueprintApi):
170 except OAuth2Error as error: 107 except OAuth2Error as error:
171 return jsonify(dict(error.get_body())) 108 return jsonify(dict(error.get_body()))
172 return redirect(url) 109 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 - 110 +
  111 +
187 """接口""" 112 """接口"""
188 @staticmethod 113 @staticmethod
189 @bp.route("/users", methods=["GET"]) 114 @bp.route("/users", methods=["GET"])
190 @swag_from(user_query.Api.api_doc) 115 @swag_from(user_query.Api.api_doc)
  116 + @auth_decorator(configure.UserPermission)
191 def user_query(): 117 def user_query():
192 """ 118 """
193 获取用户列表 119 获取用户列表
@@ -197,6 +123,7 @@ class DataManager(BlueprintApi): @@ -197,6 +123,7 @@ class DataManager(BlueprintApi):
197 @staticmethod 123 @staticmethod
198 @bp.route("/users", methods=["POST"]) 124 @bp.route("/users", methods=["POST"])
199 @swag_from(user_create.Api.api_doc) 125 @swag_from(user_create.Api.api_doc)
  126 + @auth_decorator(configure.UserPermission)
200 def user_create(): 127 def user_create():
201 """ 128 """
202 创建用户 129 创建用户
@@ -206,6 +133,7 @@ class DataManager(BlueprintApi): @@ -206,6 +133,7 @@ class DataManager(BlueprintApi):
206 @staticmethod 133 @staticmethod
207 @bp.route("/userEdit", methods=["POST"]) 134 @bp.route("/userEdit", methods=["POST"])
208 @swag_from(user_update.Api.api_doc) 135 @swag_from(user_update.Api.api_doc)
  136 + @auth_decorator(configure.UserPermission)
209 def user_update(): 137 def user_update():
210 """ 138 """
211 更新用户信息 139 更新用户信息
@@ -215,6 +143,7 @@ class DataManager(BlueprintApi): @@ -215,6 +143,7 @@ class DataManager(BlueprintApi):
215 @staticmethod 143 @staticmethod
216 @bp.route("/userDelete", methods=["POST"]) 144 @bp.route("/userDelete", methods=["POST"])
217 @swag_from(user_delete.Api.api_doc) 145 @swag_from(user_delete.Api.api_doc)
  146 + @auth_decorator(configure.UserPermission)
218 def user_delete(): 147 def user_delete():
219 """ 148 """
220 删除用户 149 删除用户
@@ -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 数据抽稀删除
1 # coding=utf-8 1 # coding=utf-8
2 -#author: 4N 2 +# author: 4N
3 #createtime: 2021/3/1 3 #createtime: 2021/3/1
4 #email: nheweijun@sina.com 4 #email: nheweijun@sina.com
5 5
@@ -11,12 +11,13 @@ from . import task_detail @@ -11,12 +11,13 @@ 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.token_decorator import token_decorator
  15 +
14 16
15 class DataManager(BlueprintApi): 17 class DataManager(BlueprintApi):
16 18
17 bp = Blueprint("Task", __name__, url_prefix="/API/Task") 19 bp = Blueprint("Task", __name__, url_prefix="/API/Task")
18 20
19 -  
20 @staticmethod 21 @staticmethod
21 @bp.route('/List', methods=['POST']) 22 @bp.route('/List', methods=['POST'])
22 @swag_from(task_list.Api.api_doc) 23 @swag_from(task_list.Api.api_doc)
@@ -38,6 +39,7 @@ class DataManager(BlueprintApi): @@ -38,6 +39,7 @@ class DataManager(BlueprintApi):
38 @staticmethod 39 @staticmethod
39 @bp.route('/Delete', methods=['POST']) 40 @bp.route('/Delete', methods=['POST'])
40 @swag_from(task_delete.Api.api_doc) 41 @swag_from(task_delete.Api.api_doc)
  42 + @token_decorator("profile")
41 def task_delete(): 43 def task_delete():
42 """ 44 """
43 删除任务 45 删除任务
@@ -47,6 +49,7 @@ class DataManager(BlueprintApi): @@ -47,6 +49,7 @@ class DataManager(BlueprintApi):
47 @staticmethod 49 @staticmethod
48 @bp.route('/Kill', methods=['POST']) 50 @bp.route('/Kill', methods=['POST'])
49 @swag_from(task_kill.Api.api_doc) 51 @swag_from(task_kill.Api.api_doc)
  52 + @token_decorator("profile")
50 def task_kill(): 53 def task_kill():
51 """ 54 """
52 Kill任务 55 Kill任务
@@ -61,5 +64,3 @@ class DataManager(BlueprintApi): @@ -61,5 +64,3 @@ class DataManager(BlueprintApi):
61 任务统计 64 任务统计
62 """ 65 """
63 return task_count.Api().result 66 return task_count.Api().result
64 -  
65 -  
@@ -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 编辑主机配置
@@ -16,6 +16,7 @@ from . import service_info @@ -16,6 +16,7 @@ from . import service_info
16 from . import service_edit 16 from . import service_edit
17 import os 17 import os
18 from flask import send_from_directory 18 from flask import send_from_directory
  19 +from app.decorators.token_decorator import token_decorator
19 20
20 21
21 class DataManager(BlueprintApi): 22 class DataManager(BlueprintApi):
@@ -27,6 +28,7 @@ class DataManager(BlueprintApi): @@ -27,6 +28,7 @@ class DataManager(BlueprintApi):
27 @staticmethod 28 @staticmethod
28 @bp.route('/Register', methods=['POST']) 29 @bp.route('/Register', methods=['POST'])
29 @swag_from(service_register.Api.api_doc) 30 @swag_from(service_register.Api.api_doc)
  31 + @token_decorator("profile")
30 def api_service_register(): 32 def api_service_register():
31 """ 33 """
32 服务注册 34 服务注册
@@ -45,6 +47,7 @@ class DataManager(BlueprintApi): @@ -45,6 +47,7 @@ class DataManager(BlueprintApi):
45 @staticmethod 47 @staticmethod
46 @bp.route('/State', methods=['POST']) 48 @bp.route('/State', methods=['POST'])
47 @swag_from(service_state.Api.api_doc) 49 @swag_from(service_state.Api.api_doc)
  50 + @token_decorator("profile")
48 def api_service_state(): 51 def api_service_state():
49 """ 52 """
50 修改服务状态 53 修改服务状态
@@ -82,6 +85,7 @@ class DataManager(BlueprintApi): @@ -82,6 +85,7 @@ class DataManager(BlueprintApi):
82 @staticmethod 85 @staticmethod
83 @bp.route('/Edit', methods=['POST']) 86 @bp.route('/Edit', methods=['POST'])
84 @swag_from(service_edit.Api.api_doc) 87 @swag_from(service_edit.Api.api_doc)
  88 + @token_decorator("profile")
85 def api_service_edit(): 89 def api_service_edit():
86 """ 90 """
87 服务Edit 91 服务Edit
@@ -93,6 +97,7 @@ class DataManager(BlueprintApi): @@ -93,6 +97,7 @@ class DataManager(BlueprintApi):
93 @staticmethod 97 @staticmethod
94 @bp.route('/Delete', methods=['POST']) 98 @bp.route('/Delete', methods=['POST'])
95 @swag_from(service_delete.Api.api_doc) 99 @swag_from(service_delete.Api.api_doc)
  100 + @token_decorator("profile")
96 def api_service_delete(): 101 def api_service_delete():
97 """ 102 """
98 服务删除 103 服务删除
@@ -12,6 +12,8 @@ from . import service_engine_delete @@ -12,6 +12,8 @@ from . import service_engine_delete
12 from . import service_engine_edit 12 from . import service_engine_edit
13 from . import service_engine_list 13 from . import service_engine_list
14 from . import service_engine_info 14 from . import service_engine_info
  15 +import configure
  16 +from app.decorators.auth_decorator import auth_decorator
15 17
16 class EngineManager(BlueprintApi): 18 class EngineManager(BlueprintApi):
17 19
@@ -19,6 +21,7 @@ class EngineManager(BlueprintApi): @@ -19,6 +21,7 @@ class EngineManager(BlueprintApi):
19 21
20 @staticmethod 22 @staticmethod
21 @bp.route('/Register', methods=['POST']) 23 @bp.route('/Register', methods=['POST'])
  24 + @auth_decorator(configure.MonitorPermission)
22 @swag_from(service_engine_register.Api.api_doc) 25 @swag_from(service_engine_register.Api.api_doc)
23 def service_engine_register(): 26 def service_engine_register():
24 """ 27 """
@@ -46,6 +49,7 @@ class EngineManager(BlueprintApi): @@ -46,6 +49,7 @@ class EngineManager(BlueprintApi):
46 49
47 @staticmethod 50 @staticmethod
48 @bp.route('/Edit', methods=['POST']) 51 @bp.route('/Edit', methods=['POST'])
  52 + @auth_decorator(configure.MonitorPermission)
49 @swag_from(service_engine_edit.Api.api_doc) 53 @swag_from(service_engine_edit.Api.api_doc)
50 def service_engine_edit(): 54 def service_engine_edit():
51 """ 55 """
@@ -57,6 +61,7 @@ class EngineManager(BlueprintApi): @@ -57,6 +61,7 @@ class EngineManager(BlueprintApi):
57 @staticmethod 61 @staticmethod
58 @bp.route('/Delete', methods=['POST']) 62 @bp.route('/Delete', methods=['POST'])
59 @swag_from(service_engine_delete.Api.api_doc) 63 @swag_from(service_engine_delete.Api.api_doc)
  64 + @auth_decorator(configure.MonitorPermission)
60 def service_engine_delete(): 65 def service_engine_delete():
61 """ 66 """
62 Engine Delete 67 Engine Delete
@@ -7,6 +7,7 @@ from flasgger import swag_from @@ -7,6 +7,7 @@ from flasgger import swag_from
7 from flask import Blueprint 7 from flask import Blueprint
8 from app.util import BlueprintApi 8 from app.util import BlueprintApi
9 from . import image_service_delete,image_service_register,image_service_edit,image_build_pyramid 9 from . import image_service_delete,image_service_register,image_service_edit,image_build_pyramid
  10 +from app.decorators.token_decorator import token_decorator
10 11
11 class DataManager(BlueprintApi): 12 class DataManager(BlueprintApi):
12 13
@@ -17,6 +18,7 @@ class DataManager(BlueprintApi): @@ -17,6 +18,7 @@ class DataManager(BlueprintApi):
17 @staticmethod 18 @staticmethod
18 @bp.route('/BuildPyramid', methods=['POST']) 19 @bp.route('/BuildPyramid', methods=['POST'])
19 @swag_from(image_build_pyramid.Api.api_doc) 20 @swag_from(image_build_pyramid.Api.api_doc)
  21 + @token_decorator("profile")
20 def api_image_build_pyramid(): 22 def api_image_build_pyramid():
21 """ 23 """
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(image_service_register.Api.api_doc) 30 @swag_from(image_service_register.Api.api_doc)
  31 + @token_decorator("profile")
29 def api_image_service_register(): 32 def api_image_service_register():
30 """ 33 """
31 注册ImageService 34 注册ImageService
@@ -35,6 +38,7 @@ class DataManager(BlueprintApi): @@ -35,6 +38,7 @@ class DataManager(BlueprintApi):
35 @staticmethod 38 @staticmethod
36 @bp.route('/Edit', methods=['POST']) 39 @bp.route('/Edit', methods=['POST'])
37 @swag_from(image_service_edit.Api.api_doc) 40 @swag_from(image_service_edit.Api.api_doc)
  41 + @token_decorator("profile")
38 def api_image_service_edit(): 42 def api_image_service_edit():
39 """ 43 """
40 修改ImageService 44 修改ImageService
@@ -44,8 +48,9 @@ class DataManager(BlueprintApi): @@ -44,8 +48,9 @@ class DataManager(BlueprintApi):
44 @staticmethod 48 @staticmethod
45 @bp.route('/Delete', methods=['POST']) 49 @bp.route('/Delete', methods=['POST'])
46 @swag_from(image_service_delete.Api.api_doc) 50 @swag_from(image_service_delete.Api.api_doc)
  51 + @token_decorator("profile")
47 def api_image_service_delete(): 52 def api_image_service_delete():
48 """ 53 """
49 ImageService Delete 54 ImageService Delete
50 """ 55 """
51 - return image_service_delete.Api().result 56 + return image_service_delete.Api().result
1 # coding=utf-8 1 # coding=utf-8
2 -#author: 4N 2 +# author: 4N
3 #createtime: 2021/9/14 3 #createtime: 2021/9/14
4 #email: nheweijun@sina.com 4 #email: nheweijun@sina.com
5 5
6 from flasgger import swag_from 6 from flasgger import swag_from
7 from flask import Blueprint 7 from flask import Blueprint
8 from app.util import BlueprintApi 8 from app.util import BlueprintApi
9 -from . import map_service_register,map_service_edit 9 +from . import map_service_register, map_service_edit
  10 +from app.decorators.token_decorator import token_decorator
  11 +
10 12
11 class DataManager(BlueprintApi): 13 class DataManager(BlueprintApi):
12 14
13 - bp = Blueprint("MapService", __name__, url_prefix="/API/Service/MapService") 15 + bp = Blueprint("MapService", __name__,
  16 + url_prefix="/API/Service/MapService")
14 service_type = ["地图服务"] 17 service_type = ["地图服务"]
15 18
16 @staticmethod 19 @staticmethod
17 @bp.route('/Register', methods=['POST']) 20 @bp.route('/Register', methods=['POST'])
18 @swag_from(map_service_register.Api.api_doc) 21 @swag_from(map_service_register.Api.api_doc)
  22 + @token_decorator("profile")
19 def api_wms_register(): 23 def api_wms_register():
20 """ 24 """
21 注册MapService 25 注册MapService
22 """ 26 """
23 return map_service_register.Api().result 27 return map_service_register.Api().result
24 28
25 -  
26 @staticmethod 29 @staticmethod
27 @bp.route('/Edit', methods=['POST']) 30 @bp.route('/Edit', methods=['POST'])
28 @swag_from(map_service_edit.Api.api_doc) 31 @swag_from(map_service_edit.Api.api_doc)
  32 + @token_decorator("profile")
29 def api_wms_edit(): 33 def api_wms_edit():
30 """ 34 """
31 修改MapService 35 修改MapService
32 """ 36 """
33 - return map_service_edit.Api().result  
  37 + return map_service_edit.Api().result
@@ -14,6 +14,8 @@ from . import scheme_edit @@ -14,6 +14,8 @@ from . import scheme_edit
14 from . import scheme_list 14 from . import scheme_list
15 from . import scheme_resolve 15 from . import scheme_resolve
16 from . import scheme_info 16 from . import scheme_info
  17 +from app.decorators.token_decorator import token_decorator
  18 +
17 19
18 class SchemeManager(BlueprintApi): 20 class SchemeManager(BlueprintApi):
19 21
@@ -23,6 +25,7 @@ class SchemeManager(BlueprintApi): @@ -23,6 +25,7 @@ class SchemeManager(BlueprintApi):
23 @staticmethod 25 @staticmethod
24 @bp.route('/Create', methods=['POST']) 26 @bp.route('/Create', methods=['POST'])
25 @swag_from(scheme_create.Api.api_doc) 27 @swag_from(scheme_create.Api.api_doc)
  28 + @token_decorator("profile")
26 def api_scheme_create(): 29 def api_scheme_create():
27 """ 30 """
28 创建切片方案 31 创建切片方案
@@ -33,6 +36,7 @@ class SchemeManager(BlueprintApi): @@ -33,6 +36,7 @@ class SchemeManager(BlueprintApi):
33 @staticmethod 36 @staticmethod
34 @bp.route('/Delete', methods=['POST']) 37 @bp.route('/Delete', methods=['POST'])
35 @swag_from(scheme_delete.Api.api_doc) 38 @swag_from(scheme_delete.Api.api_doc)
  39 + @token_decorator("profile")
36 def api_scheme_delete(): 40 def api_scheme_delete():
37 """ 41 """
38 删除切片方案 42 删除切片方案
@@ -42,6 +46,7 @@ class SchemeManager(BlueprintApi): @@ -42,6 +46,7 @@ class SchemeManager(BlueprintApi):
42 @staticmethod 46 @staticmethod
43 @bp.route('/Edit', methods=['POST']) 47 @bp.route('/Edit', methods=['POST'])
44 @swag_from(scheme_edit.Api.api_doc) 48 @swag_from(scheme_edit.Api.api_doc)
  49 + @token_decorator("profile")
45 def api_scheme_edit(): 50 def api_scheme_edit():
46 """ 51 """
47 修改切片方案 52 修改切片方案
@@ -8,7 +8,7 @@ from flasgger import swag_from @@ -8,7 +8,7 @@ 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 upload_oview,tile_service_register,tile_service_edit,tile_service_reload 10 from . import upload_oview,tile_service_register,tile_service_edit,tile_service_reload
11 - 11 +from app.decorators.token_decorator import token_decorator
12 12
13 13
14 class DataManager(BlueprintApi): 14 class DataManager(BlueprintApi):
@@ -30,6 +30,7 @@ class DataManager(BlueprintApi): @@ -30,6 +30,7 @@ class DataManager(BlueprintApi):
30 @staticmethod 30 @staticmethod
31 @bp.route('/Register', methods=['POST']) 31 @bp.route('/Register', methods=['POST'])
32 @swag_from(tile_service_register.Api.api_doc) 32 @swag_from(tile_service_register.Api.api_doc)
  33 + @token_decorator("profile")
33 def api_wmts_register(): 34 def api_wmts_register():
34 """ 35 """
35 注册TileService 36 注册TileService
@@ -39,6 +40,7 @@ class DataManager(BlueprintApi): @@ -39,6 +40,7 @@ class DataManager(BlueprintApi):
39 @staticmethod 40 @staticmethod
40 @bp.route('/Edit', methods=['POST']) 41 @bp.route('/Edit', methods=['POST'])
41 @swag_from(tile_service_edit.Api.api_doc) 42 @swag_from(tile_service_edit.Api.api_doc)
  43 + @token_decorator("profile")
42 def api_wmts_edit(): 44 def api_wmts_edit():
43 """ 45 """
44 修改TileService 46 修改TileService
@@ -4,8 +4,8 @@ import logging @@ -4,8 +4,8 @@ import logging
4 deploy_ip_host = "172.26.40.105:8840" 4 deploy_ip_host = "172.26.40.105:8840"
5 # 系统数据库 5 # 系统数据库
6 6
7 -SQLALCHEMY_DATABASE_URI = "postgresql://postgres:chinadci@172.26.60.100:5432/dmap_manager_test"  
8 -# SQLALCHEMY_DATABASE_URI = "postgresql://postgres:postgres@localhost:5433/dmap_dms_test" 7 +# SQLALCHEMY_DATABASE_URI = "postgresql://postgres:chinadci@172.26.60.100:5432/dmap_manager_test"
  8 +SQLALCHEMY_DATABASE_URI = "postgresql://postgres:postgres@localhost:5433/dmap_dms_test"
9 9
10 # 指定精华表所在位置(必须为空间库),设置为None则存放在各自的实体库中 10 # 指定精华表所在位置(必须为空间库),设置为None则存放在各自的实体库中
11 #VACUATE_DB_URI = None 11 #VACUATE_DB_URI = None
@@ -13,7 +13,7 @@ VACUATE_DB_URI = SQLALCHEMY_DATABASE_URI @@ -13,7 +13,7 @@ VACUATE_DB_URI = SQLALCHEMY_DATABASE_URI
13 13
14 zookeeper = "172.26.99.168:2181" 14 zookeeper = "172.26.99.168:2181"
15 15
16 -#WMTS服务器 16 +# WMTS服务器
17 wmts_url = "http://172.26.99.160:6060" 17 wmts_url = "http://172.26.99.160:6060"
18 wms_url = "" 18 wms_url = ""
19 19
@@ -22,6 +22,11 @@ swagger_configure = {"title": "DMapManager"} @@ -22,6 +22,11 @@ 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 +# 权限
  26 +UserPermission = ['admin']
  27 +MonitorPermission = ['admin']
  28 +DataPermission = ['admin', 'dataman']
  29 +PublishPermission = ['admin', 'dataman', 'publisher']
  30 +ServicePermission = ['admin', 'dataman', 'publisher']
25 31
26 log_level = logging.INFO 32 log_level = logging.INFO
27 -  
注册登录 后发表评论