正在显示
15 个修改的文件
包含
175 行增加
和
98 行删除
app/decorators/auth_decorator.py
0 → 100644
| 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 | ... | ... |
app/decorators/token_decorator.py
0 → 100644
| 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 | 6 | from flask import Blueprint, render_template, redirect, request, session, jsonify |
| 7 | 7 | from sqlalchemy import and_ |
| 8 | 8 | from .models import * |
| 9 | -from .oauth2 import authorization, require_oauth, generate_user_info | |
| 9 | +from .oauth2 import authorization, generate_user_info | |
| 10 | 10 | from authlib.oauth2 import OAuth2Error |
| 11 | 11 | from authlib.integrations.flask_oauth2 import current_token |
| 12 | 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 | 18 | def current_user(): |
| ... | ... | @@ -32,68 +35,6 @@ def split_by_crlf(s): |
| 32 | 35 | class DataManager(BlueprintApi): |
| 33 | 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 | 38 | @staticmethod |
| 98 | 39 | @bp.route("/authorize", methods=("GET", "POST")) |
| 99 | 40 | def authorize(): |
| ... | ... | @@ -132,10 +73,7 @@ class DataManager(BlueprintApi): |
| 132 | 73 | return jsonify(dict(error.get_body())) |
| 133 | 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 | 78 | @staticmethod |
| 141 | 79 | @bp.route("/token", methods=["POST"]) |
| ... | ... | @@ -144,7 +82,7 @@ class DataManager(BlueprintApi): |
| 144 | 82 | |
| 145 | 83 | @staticmethod |
| 146 | 84 | @bp.route("/userinfo") |
| 147 | - @require_oauth("profile") | |
| 85 | + @token_decorator("profile") | |
| 148 | 86 | def api_me(): |
| 149 | 87 | try: |
| 150 | 88 | return jsonify(generate_user_info(current_token.user, current_token.scope)) |
| ... | ... | @@ -153,7 +91,6 @@ class DataManager(BlueprintApi): |
| 153 | 91 | |
| 154 | 92 | @staticmethod |
| 155 | 93 | @bp.route("/logout", methods=["GET"]) |
| 156 | - # @require_oauth("profile") | |
| 157 | 94 | def logout(): |
| 158 | 95 | url = '' |
| 159 | 96 | try: |
| ... | ... | @@ -170,24 +107,13 @@ class DataManager(BlueprintApi): |
| 170 | 107 | except OAuth2Error as error: |
| 171 | 108 | return jsonify(dict(error.get_body())) |
| 172 | 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 | 113 | @staticmethod |
| 189 | 114 | @bp.route("/users", methods=["GET"]) |
| 190 | 115 | @swag_from(user_query.Api.api_doc) |
| 116 | + @auth_decorator(configure.UserPermission) | |
| 191 | 117 | def user_query(): |
| 192 | 118 | """ |
| 193 | 119 | 获取用户列表 |
| ... | ... | @@ -197,6 +123,7 @@ class DataManager(BlueprintApi): |
| 197 | 123 | @staticmethod |
| 198 | 124 | @bp.route("/users", methods=["POST"]) |
| 199 | 125 | @swag_from(user_create.Api.api_doc) |
| 126 | + @auth_decorator(configure.UserPermission) | |
| 200 | 127 | def user_create(): |
| 201 | 128 | """ |
| 202 | 129 | 创建用户 |
| ... | ... | @@ -206,6 +133,7 @@ class DataManager(BlueprintApi): |
| 206 | 133 | @staticmethod |
| 207 | 134 | @bp.route("/userEdit", methods=["POST"]) |
| 208 | 135 | @swag_from(user_update.Api.api_doc) |
| 136 | + @auth_decorator(configure.UserPermission) | |
| 209 | 137 | def user_update(): |
| 210 | 138 | """ |
| 211 | 139 | 更新用户信息 |
| ... | ... | @@ -215,6 +143,7 @@ class DataManager(BlueprintApi): |
| 215 | 143 | @staticmethod |
| 216 | 144 | @bp.route("/userDelete", methods=["POST"]) |
| 217 | 145 | @swag_from(user_delete.Api.api_doc) |
| 146 | + @auth_decorator(configure.UserPermission) | |
| 218 | 147 | def user_delete(): |
| 219 | 148 | """ |
| 220 | 149 | 删除用户 | ... | ... |
| ... | ... | @@ -4,11 +4,9 @@ |
| 4 | 4 | #email: nheweijun@sina.com |
| 5 | 5 | |
| 6 | 6 | |
| 7 | - | |
| 8 | 7 | from flasgger import swag_from |
| 9 | 8 | from flask import Blueprint |
| 10 | 9 | from app.util import BlueprintApi |
| 11 | - | |
| 12 | 10 | from . import database_register |
| 13 | 11 | from . import database_test |
| 14 | 12 | from . import database_list |
| ... | ... | @@ -18,6 +16,9 @@ from . import database_alias_check |
| 18 | 16 | from . import database_connect_test |
| 19 | 17 | from . import database_info |
| 20 | 18 | from . import database_detail |
| 19 | +import configure | |
| 20 | +from app.decorators.auth_decorator import auth_decorator | |
| 21 | + | |
| 21 | 22 | |
| 22 | 23 | class DataManager(BlueprintApi): |
| 23 | 24 | |
| ... | ... | @@ -27,6 +28,7 @@ class DataManager(BlueprintApi): |
| 27 | 28 | @staticmethod |
| 28 | 29 | @bp.route('/Register', methods=['POST']) |
| 29 | 30 | @swag_from(database_register.Api.api_doc) |
| 31 | + @auth_decorator(configure.DataPermission) | |
| 30 | 32 | def api_database_register(): |
| 31 | 33 | """ |
| 32 | 34 | 数据源注册 |
| ... | ... | @@ -36,6 +38,7 @@ class DataManager(BlueprintApi): |
| 36 | 38 | @staticmethod |
| 37 | 39 | @bp.route('/List', methods=['POST']) |
| 38 | 40 | @swag_from(database_list.Api.api_doc) |
| 41 | + @auth_decorator(configure.DataPermission) | |
| 39 | 42 | def api_database_list(): |
| 40 | 43 | """ |
| 41 | 44 | 数据源列表 |
| ... | ... | @@ -45,6 +48,7 @@ class DataManager(BlueprintApi): |
| 45 | 48 | @staticmethod |
| 46 | 49 | @bp.route('/Delete', methods=['POST']) |
| 47 | 50 | @swag_from(database_delete.Api.api_doc) |
| 51 | + @auth_decorator(configure.DataPermission) | |
| 48 | 52 | def api_database_delete(): |
| 49 | 53 | """ |
| 50 | 54 | 数据源注销 |
| ... | ... | @@ -54,6 +58,7 @@ class DataManager(BlueprintApi): |
| 54 | 58 | @staticmethod |
| 55 | 59 | @bp.route('/Edit', methods=['POST']) |
| 56 | 60 | @swag_from(database_edit.Api.api_doc) |
| 61 | + @auth_decorator(configure.DataPermission) | |
| 57 | 62 | def database_edit(): |
| 58 | 63 | """ |
| 59 | 64 | 修改数据源 |
| ... | ... | @@ -63,6 +68,7 @@ class DataManager(BlueprintApi): |
| 63 | 68 | @staticmethod |
| 64 | 69 | @bp.route('/Test', methods=['POST']) |
| 65 | 70 | @swag_from(database_test.Api.api_doc) |
| 71 | + @auth_decorator(configure.DataPermission) | |
| 66 | 72 | def api_database_test(): |
| 67 | 73 | """ |
| 68 | 74 | 数据源测试 |
| ... | ... | @@ -72,6 +78,7 @@ class DataManager(BlueprintApi): |
| 72 | 78 | @staticmethod |
| 73 | 79 | @bp.route('/CheckAlias', methods=['POST']) |
| 74 | 80 | @swag_from(database_alias_check.Api.api_doc) |
| 81 | + @auth_decorator(configure.DataPermission) | |
| 75 | 82 | def api_database_alias_check(): |
| 76 | 83 | """ |
| 77 | 84 | 数据源别名测试 |
| ... | ... | @@ -81,6 +88,7 @@ class DataManager(BlueprintApi): |
| 81 | 88 | @staticmethod |
| 82 | 89 | @bp.route('/CheckConnect', methods=['POST']) |
| 83 | 90 | @swag_from(database_connect_test.Api.api_doc) |
| 91 | + @auth_decorator(configure.DataPermission) | |
| 84 | 92 | def api_database_connect_test(): |
| 85 | 93 | """ |
| 86 | 94 | 数据源连接测试 | ... | ... |
| ... | ... | @@ -13,6 +13,8 @@ from . import get_meta |
| 13 | 13 | from . import data_entry_by_meta |
| 14 | 14 | from . import get_data_list |
| 15 | 15 | from . import data_entry_simple |
| 16 | +import configure | |
| 17 | +from app.decorators.auth_decorator import auth_decorator | |
| 16 | 18 | |
| 17 | 19 | class DataManager(BlueprintApi): |
| 18 | 20 | |
| ... | ... | @@ -21,6 +23,7 @@ class DataManager(BlueprintApi): |
| 21 | 23 | |
| 22 | 24 | @staticmethod |
| 23 | 25 | @bp.route('/Download/<file>', methods=['GET']) |
| 26 | + @auth_decorator(configure.DataPermission) | |
| 24 | 27 | def table_download_file(file): |
| 25 | 28 | parent = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) |
| 26 | 29 | dirpath = os.path.join(parent,"file_tmp") |
| ... | ... | @@ -41,6 +44,7 @@ class DataManager(BlueprintApi): |
| 41 | 44 | |
| 42 | 45 | @staticmethod |
| 43 | 46 | @bp.route('/DeleteFile/<file>', methods=['GET']) |
| 47 | + @auth_decorator(configure.DataPermission) | |
| 44 | 48 | def d_file(file): |
| 45 | 49 | parent = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) |
| 46 | 50 | dirpath = os.path.join(parent, "file_tmp") |
| ... | ... | @@ -59,6 +63,7 @@ class DataManager(BlueprintApi): |
| 59 | 63 | @staticmethod |
| 60 | 64 | @bp.route('/DataDownloadTask', methods=['POST']) |
| 61 | 65 | @swag_from(data_download_task.Api.api_doc) |
| 66 | + @auth_decorator(configure.DataPermission) | |
| 62 | 67 | def api_data_download_task(): |
| 63 | 68 | """ |
| 64 | 69 | 下载数据任务 |
| ... | ... | @@ -69,6 +74,7 @@ class DataManager(BlueprintApi): |
| 69 | 74 | @staticmethod |
| 70 | 75 | @bp.route('/GetMeta', methods=['POST']) |
| 71 | 76 | @swag_from(get_meta.Api.api_doc) |
| 77 | + @auth_decorator(configure.DataPermission) | |
| 72 | 78 | def get_meta(): |
| 73 | 79 | """ |
| 74 | 80 | 数据Meta |
| ... | ... | @@ -78,6 +84,7 @@ class DataManager(BlueprintApi): |
| 78 | 84 | @staticmethod |
| 79 | 85 | @bp.route('/GetDataList', methods=['POST']) |
| 80 | 86 | @swag_from(get_data_list.Api.api_doc) |
| 87 | + @auth_decorator(configure.DataPermission) | |
| 81 | 88 | def get_data_list(): |
| 82 | 89 | """ |
| 83 | 90 | 本地数据list |
| ... | ... | @@ -87,6 +94,7 @@ class DataManager(BlueprintApi): |
| 87 | 94 | @staticmethod |
| 88 | 95 | @bp.route('/DataEntryByMeta', methods=['POST']) |
| 89 | 96 | @swag_from(data_entry_by_meta.Api.api_doc) |
| 97 | + @auth_decorator(configure.DataPermission) | |
| 90 | 98 | def data_entry_by_meta(): |
| 91 | 99 | """ |
| 92 | 100 | 数据入库ByMeta |
| ... | ... | @@ -96,6 +104,7 @@ class DataManager(BlueprintApi): |
| 96 | 104 | @staticmethod |
| 97 | 105 | @bp.route('/DataEntrySimple', methods=['POST']) |
| 98 | 106 | @swag_from(data_entry_simple.Api.api_doc) |
| 107 | + @auth_decorator(configure.DataPermission) | |
| 99 | 108 | def data_entry_simple(): |
| 100 | 109 | """ |
| 101 | 110 | 数据入库Simple | ... | ... |
| ... | ... | @@ -24,6 +24,10 @@ from . import table_vacuate_ref |
| 24 | 24 | from . import table_vacuate_delete |
| 25 | 25 | from . import field_value |
| 26 | 26 | from . import table_check |
| 27 | +import configure | |
| 28 | +from app.decorators.auth_decorator import auth_decorator | |
| 29 | + | |
| 30 | + | |
| 27 | 31 | class DataManager(BlueprintApi): |
| 28 | 32 | |
| 29 | 33 | bp = Blueprint("DataManager", __name__, url_prefix="/API/Manager") |
| ... | ... | @@ -31,6 +35,7 @@ class DataManager(BlueprintApi): |
| 31 | 35 | @staticmethod |
| 32 | 36 | @bp.route('/FieldEdit', methods=['POST']) |
| 33 | 37 | @swag_from(field_edit.Api.api_doc) |
| 38 | + @auth_decorator(configure.DataPermission) | |
| 34 | 39 | def field_edit(): |
| 35 | 40 | """ |
| 36 | 41 | 修改属性别名 |
| ... | ... | @@ -49,6 +54,7 @@ class DataManager(BlueprintApi): |
| 49 | 54 | @staticmethod |
| 50 | 55 | @bp.route('/FieldValue', methods=['POST']) |
| 51 | 56 | @swag_from(field_value.Api.api_doc) |
| 57 | + @auth_decorator(configure.DataPermission) | |
| 52 | 58 | def field_value(): |
| 53 | 59 | """ |
| 54 | 60 | 属性值 |
| ... | ... | @@ -68,6 +74,7 @@ class DataManager(BlueprintApi): |
| 68 | 74 | @staticmethod |
| 69 | 75 | @bp.route('/TableEdit', methods=['POST']) |
| 70 | 76 | @swag_from(table_edit.Api.api_doc) |
| 77 | + @auth_decorator(configure.DataPermission) | |
| 71 | 78 | def table_edit(): |
| 72 | 79 | """ |
| 73 | 80 | 修改数据 |
| ... | ... | @@ -78,6 +85,7 @@ class DataManager(BlueprintApi): |
| 78 | 85 | @staticmethod |
| 79 | 86 | @bp.route('/TableDelete', methods=['POST']) |
| 80 | 87 | @swag_from(table_delete.Api.api_doc) |
| 88 | + @auth_decorator(configure.DataPermission) | |
| 81 | 89 | def table_delete(): |
| 82 | 90 | """ |
| 83 | 91 | 删除数据 |
| ... | ... | @@ -107,6 +115,7 @@ class DataManager(BlueprintApi): |
| 107 | 115 | @staticmethod |
| 108 | 116 | @bp.route('/TableRefresh', methods=['POST']) |
| 109 | 117 | @swag_from(table_refresh.Api.api_doc) |
| 118 | + @auth_decorator(configure.DataPermission) | |
| 110 | 119 | def table_refresh(): |
| 111 | 120 | """ |
| 112 | 121 | 刷新数据 |
| ... | ... | @@ -126,6 +135,7 @@ class DataManager(BlueprintApi): |
| 126 | 135 | @staticmethod |
| 127 | 136 | @bp.route('/TableVacuate', methods=['POST']) |
| 128 | 137 | @swag_from(table_vacuate.Api.api_doc) |
| 138 | + @auth_decorator(configure.DataPermission) | |
| 129 | 139 | def table_vacuate(): |
| 130 | 140 | """ |
| 131 | 141 | 数据抽稀 |
| ... | ... | @@ -135,6 +145,7 @@ class DataManager(BlueprintApi): |
| 135 | 145 | @staticmethod |
| 136 | 146 | @bp.route('/TableVacuateOne', methods=['POST']) |
| 137 | 147 | @swag_from(table_vacuate_one.Api.api_doc) |
| 148 | + @auth_decorator(configure.DataPermission) | |
| 138 | 149 | def api_table_vacuate_one(): |
| 139 | 150 | """ |
| 140 | 151 | 单独数据抽稀 |
| ... | ... | @@ -163,6 +174,7 @@ class DataManager(BlueprintApi): |
| 163 | 174 | @staticmethod |
| 164 | 175 | @bp.route('/TableVacuateDelete', methods=['POST']) |
| 165 | 176 | @swag_from(table_vacuate_delete.Api.api_doc) |
| 177 | + @auth_decorator(configure.DataPermission) | |
| 166 | 178 | def api_table_vacuate_delete(): |
| 167 | 179 | """ |
| 168 | 180 | 数据抽稀删除 | ... | ... |
| 1 | 1 | # coding=utf-8 |
| 2 | -#author: 4N | |
| 2 | +# author: 4N | |
| 3 | 3 | #createtime: 2021/3/1 |
| 4 | 4 | #email: nheweijun@sina.com |
| 5 | 5 | |
| ... | ... | @@ -11,12 +11,13 @@ from . import task_detail |
| 11 | 11 | from . import task_delete |
| 12 | 12 | from . import task_count |
| 13 | 13 | from . import task_kill |
| 14 | +from app.decorators.token_decorator import token_decorator | |
| 15 | + | |
| 14 | 16 | |
| 15 | 17 | class DataManager(BlueprintApi): |
| 16 | 18 | |
| 17 | 19 | bp = Blueprint("Task", __name__, url_prefix="/API/Task") |
| 18 | 20 | |
| 19 | - | |
| 20 | 21 | @staticmethod |
| 21 | 22 | @bp.route('/List', methods=['POST']) |
| 22 | 23 | @swag_from(task_list.Api.api_doc) |
| ... | ... | @@ -38,6 +39,7 @@ class DataManager(BlueprintApi): |
| 38 | 39 | @staticmethod |
| 39 | 40 | @bp.route('/Delete', methods=['POST']) |
| 40 | 41 | @swag_from(task_delete.Api.api_doc) |
| 42 | + @token_decorator("profile") | |
| 41 | 43 | def task_delete(): |
| 42 | 44 | """ |
| 43 | 45 | 删除任务 |
| ... | ... | @@ -47,6 +49,7 @@ class DataManager(BlueprintApi): |
| 47 | 49 | @staticmethod |
| 48 | 50 | @bp.route('/Kill', methods=['POST']) |
| 49 | 51 | @swag_from(task_kill.Api.api_doc) |
| 52 | + @token_decorator("profile") | |
| 50 | 53 | def task_kill(): |
| 51 | 54 | """ |
| 52 | 55 | Kill任务 |
| ... | ... | @@ -61,5 +64,3 @@ class DataManager(BlueprintApi): |
| 61 | 64 | 任务统计 |
| 62 | 65 | """ |
| 63 | 66 | return task_count.Api().result |
| 64 | - | |
| 65 | - | ... | ... |
| ... | ... | @@ -8,7 +8,8 @@ from flasgger import swag_from |
| 8 | 8 | from flask import Blueprint |
| 9 | 9 | from app.util import BlueprintApi |
| 10 | 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 | 14 | user_socket_list = [] |
| 14 | 15 | user_socket_dict = {} |
| ... | ... | @@ -48,6 +49,7 @@ class Monitor(BlueprintApi): |
| 48 | 49 | @staticmethod |
| 49 | 50 | @bp.route('/RegisterHost', methods=['POST']) |
| 50 | 51 | @swag_from(monitor_host_create.Api.api_doc) |
| 52 | + @auth_decorator(configure.MonitorPermission) | |
| 51 | 53 | def monitor_host_create(): |
| 52 | 54 | ''' |
| 53 | 55 | 注册监控主机 |
| ... | ... | @@ -66,6 +68,7 @@ class Monitor(BlueprintApi): |
| 66 | 68 | @staticmethod |
| 67 | 69 | @bp.route('/HostDelete', methods=['POST']) |
| 68 | 70 | @swag_from(monitor_host_delete.Api.api_doc) |
| 71 | + @auth_decorator(configure.MonitorPermission) | |
| 69 | 72 | def monitor_host_delete(): |
| 70 | 73 | ''' |
| 71 | 74 | 删除主机 |
| ... | ... | @@ -75,6 +78,7 @@ class Monitor(BlueprintApi): |
| 75 | 78 | @staticmethod |
| 76 | 79 | @bp.route('/HostEdit', methods=['POST']) |
| 77 | 80 | @swag_from(monitor_host_edit.Api.api_doc) |
| 81 | + @auth_decorator(configure.MonitorPermission) | |
| 78 | 82 | def monitor_host_edit(): |
| 79 | 83 | ''' |
| 80 | 84 | 编辑主机配置 | ... | ... |
| ... | ... | @@ -17,6 +17,7 @@ from . import service_edit |
| 17 | 17 | from . import service_reload |
| 18 | 18 | import os |
| 19 | 19 | from flask import send_from_directory |
| 20 | +from app.decorators.token_decorator import token_decorator | |
| 20 | 21 | |
| 21 | 22 | |
| 22 | 23 | class DataManager(BlueprintApi): |
| ... | ... | @@ -28,6 +29,7 @@ class DataManager(BlueprintApi): |
| 28 | 29 | @staticmethod |
| 29 | 30 | @bp.route('/Register', methods=['POST']) |
| 30 | 31 | @swag_from(service_register.Api.api_doc) |
| 32 | + @token_decorator("profile") | |
| 31 | 33 | def api_service_register(): |
| 32 | 34 | """ |
| 33 | 35 | 服务注册 |
| ... | ... | @@ -46,6 +48,7 @@ class DataManager(BlueprintApi): |
| 46 | 48 | @staticmethod |
| 47 | 49 | @bp.route('/State', methods=['POST']) |
| 48 | 50 | @swag_from(service_state.Api.api_doc) |
| 51 | + @token_decorator("profile") | |
| 49 | 52 | def api_service_state(): |
| 50 | 53 | """ |
| 51 | 54 | 修改服务状态 |
| ... | ... | @@ -83,6 +86,7 @@ class DataManager(BlueprintApi): |
| 83 | 86 | @staticmethod |
| 84 | 87 | @bp.route('/Edit', methods=['POST']) |
| 85 | 88 | @swag_from(service_edit.Api.api_doc) |
| 89 | + @token_decorator("profile") | |
| 86 | 90 | def api_service_edit(): |
| 87 | 91 | """ |
| 88 | 92 | 服务Edit |
| ... | ... | @@ -102,6 +106,7 @@ class DataManager(BlueprintApi): |
| 102 | 106 | @staticmethod |
| 103 | 107 | @bp.route('/Delete', methods=['POST']) |
| 104 | 108 | @swag_from(service_delete.Api.api_doc) |
| 109 | + @token_decorator("profile") | |
| 105 | 110 | def api_service_delete(): |
| 106 | 111 | """ |
| 107 | 112 | 服务删除 | ... | ... |
| ... | ... | @@ -12,13 +12,19 @@ from . import service_engine_delete |
| 12 | 12 | from . import service_engine_edit |
| 13 | 13 | from . import service_engine_list |
| 14 | 14 | from . import service_engine_info |
| 15 | + | |
| 15 | 16 | from . import service_engine_deploy |
| 17 | + | |
| 18 | +import configure | |
| 19 | +from app.decorators.auth_decorator import auth_decorator | |
| 20 | + | |
| 16 | 21 | class EngineManager(BlueprintApi): |
| 17 | 22 | |
| 18 | 23 | bp = Blueprint("Engine", __name__, url_prefix="/API/Service/Engine") |
| 19 | 24 | |
| 20 | 25 | @staticmethod |
| 21 | 26 | @bp.route('/Register', methods=['POST']) |
| 27 | + @auth_decorator(configure.MonitorPermission) | |
| 22 | 28 | @swag_from(service_engine_register.Api.api_doc) |
| 23 | 29 | def service_engine_register(): |
| 24 | 30 | """ |
| ... | ... | @@ -46,6 +52,7 @@ class EngineManager(BlueprintApi): |
| 46 | 52 | |
| 47 | 53 | @staticmethod |
| 48 | 54 | @bp.route('/Edit', methods=['POST']) |
| 55 | + @auth_decorator(configure.MonitorPermission) | |
| 49 | 56 | @swag_from(service_engine_edit.Api.api_doc) |
| 50 | 57 | def service_engine_edit(): |
| 51 | 58 | """ |
| ... | ... | @@ -57,6 +64,7 @@ class EngineManager(BlueprintApi): |
| 57 | 64 | @staticmethod |
| 58 | 65 | @bp.route('/Delete', methods=['POST']) |
| 59 | 66 | @swag_from(service_engine_delete.Api.api_doc) |
| 67 | + @auth_decorator(configure.MonitorPermission) | |
| 60 | 68 | def service_engine_delete(): |
| 61 | 69 | """ |
| 62 | 70 | Engine Delete | ... | ... |
| ... | ... | @@ -7,6 +7,7 @@ from flasgger import swag_from |
| 7 | 7 | from flask import Blueprint |
| 8 | 8 | from app.util import BlueprintApi |
| 9 | 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 | 12 | class DataManager(BlueprintApi): |
| 12 | 13 | |
| ... | ... | @@ -17,6 +18,7 @@ class DataManager(BlueprintApi): |
| 17 | 18 | @staticmethod |
| 18 | 19 | @bp.route('/BuildPyramid', methods=['POST']) |
| 19 | 20 | @swag_from(image_build_pyramid.Api.api_doc) |
| 21 | + @token_decorator("profile") | |
| 20 | 22 | def api_image_build_pyramid(): |
| 21 | 23 | """ |
| 22 | 24 | 创建影像金字塔 |
| ... | ... | @@ -26,6 +28,7 @@ class DataManager(BlueprintApi): |
| 26 | 28 | @staticmethod |
| 27 | 29 | @bp.route('/Register', methods=['POST']) |
| 28 | 30 | @swag_from(image_service_register.Api.api_doc) |
| 31 | + @token_decorator("profile") | |
| 29 | 32 | def api_image_service_register(): |
| 30 | 33 | """ |
| 31 | 34 | 注册ImageService |
| ... | ... | @@ -35,6 +38,7 @@ class DataManager(BlueprintApi): |
| 35 | 38 | @staticmethod |
| 36 | 39 | @bp.route('/Edit', methods=['POST']) |
| 37 | 40 | @swag_from(image_service_edit.Api.api_doc) |
| 41 | + @token_decorator("profile") | |
| 38 | 42 | def api_image_service_edit(): |
| 39 | 43 | """ |
| 40 | 44 | 修改ImageService |
| ... | ... | @@ -44,8 +48,9 @@ class DataManager(BlueprintApi): |
| 44 | 48 | @staticmethod |
| 45 | 49 | @bp.route('/Delete', methods=['POST']) |
| 46 | 50 | @swag_from(image_service_delete.Api.api_doc) |
| 51 | + @token_decorator("profile") | |
| 47 | 52 | def api_image_service_delete(): |
| 48 | 53 | """ |
| 49 | 54 | ImageService Delete |
| 50 | 55 | """ |
| 51 | - return image_service_delete.Api().result | |
| 56 | + return image_service_delete.Api().result | |
| \ No newline at end of file | ... | ... |
| 1 | 1 | # coding=utf-8 |
| 2 | -#author: 4N | |
| 2 | +# author: 4N | |
| 3 | 3 | #createtime: 2021/9/14 |
| 4 | 4 | #email: nheweijun@sina.com |
| 5 | 5 | |
| 6 | 6 | from flasgger import swag_from |
| 7 | 7 | from flask import Blueprint |
| 8 | 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 | 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 | 17 | service_type = ["地图服务"] |
| 15 | 18 | |
| 16 | 19 | @staticmethod |
| 17 | 20 | @bp.route('/Register', methods=['POST']) |
| 18 | 21 | @swag_from(map_service_register.Api.api_doc) |
| 22 | + @token_decorator("profile") | |
| 19 | 23 | def api_wms_register(): |
| 20 | 24 | """ |
| 21 | 25 | 注册MapService |
| 22 | 26 | """ |
| 23 | 27 | return map_service_register.Api().result |
| 24 | 28 | |
| 25 | - | |
| 26 | 29 | @staticmethod |
| 27 | 30 | @bp.route('/Edit', methods=['POST']) |
| 28 | 31 | @swag_from(map_service_edit.Api.api_doc) |
| 32 | + @token_decorator("profile") | |
| 29 | 33 | def api_wms_edit(): |
| 30 | 34 | """ |
| 31 | 35 | 修改MapService |
| 32 | 36 | """ |
| 33 | - return map_service_edit.Api().result | |
| \ No newline at end of file | ||
| 37 | + return map_service_edit.Api().result | ... | ... |
| ... | ... | @@ -14,6 +14,8 @@ from . import scheme_edit |
| 14 | 14 | from . import scheme_list |
| 15 | 15 | from . import scheme_resolve |
| 16 | 16 | from . import scheme_info |
| 17 | +from app.decorators.token_decorator import token_decorator | |
| 18 | + | |
| 17 | 19 | |
| 18 | 20 | class SchemeManager(BlueprintApi): |
| 19 | 21 | |
| ... | ... | @@ -23,6 +25,7 @@ class SchemeManager(BlueprintApi): |
| 23 | 25 | @staticmethod |
| 24 | 26 | @bp.route('/Create', methods=['POST']) |
| 25 | 27 | @swag_from(scheme_create.Api.api_doc) |
| 28 | + @token_decorator("profile") | |
| 26 | 29 | def api_scheme_create(): |
| 27 | 30 | """ |
| 28 | 31 | 创建切片方案 |
| ... | ... | @@ -33,6 +36,7 @@ class SchemeManager(BlueprintApi): |
| 33 | 36 | @staticmethod |
| 34 | 37 | @bp.route('/Delete', methods=['POST']) |
| 35 | 38 | @swag_from(scheme_delete.Api.api_doc) |
| 39 | + @token_decorator("profile") | |
| 36 | 40 | def api_scheme_delete(): |
| 37 | 41 | """ |
| 38 | 42 | 删除切片方案 |
| ... | ... | @@ -42,6 +46,7 @@ class SchemeManager(BlueprintApi): |
| 42 | 46 | @staticmethod |
| 43 | 47 | @bp.route('/Edit', methods=['POST']) |
| 44 | 48 | @swag_from(scheme_edit.Api.api_doc) |
| 49 | + @token_decorator("profile") | |
| 45 | 50 | def api_scheme_edit(): |
| 46 | 51 | """ |
| 47 | 52 | 修改切片方案 | ... | ... |
| ... | ... | @@ -8,7 +8,7 @@ from flasgger import swag_from |
| 8 | 8 | from flask import Blueprint |
| 9 | 9 | from app.util import BlueprintApi |
| 10 | 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 | 14 | class DataManager(BlueprintApi): |
| ... | ... | @@ -30,6 +30,7 @@ class DataManager(BlueprintApi): |
| 30 | 30 | @staticmethod |
| 31 | 31 | @bp.route('/Register', methods=['POST']) |
| 32 | 32 | @swag_from(tile_service_register.Api.api_doc) |
| 33 | + @token_decorator("profile") | |
| 33 | 34 | def api_wmts_register(): |
| 34 | 35 | """ |
| 35 | 36 | 注册TileService |
| ... | ... | @@ -39,6 +40,7 @@ class DataManager(BlueprintApi): |
| 39 | 40 | @staticmethod |
| 40 | 41 | @bp.route('/Edit', methods=['POST']) |
| 41 | 42 | @swag_from(tile_service_edit.Api.api_doc) |
| 43 | + @token_decorator("profile") | |
| 42 | 44 | def api_wmts_edit(): |
| 43 | 45 | """ |
| 44 | 46 | 修改TileService | ... | ... |
| ... | ... | @@ -4,24 +4,33 @@ import logging |
| 4 | 4 | deploy_ip_host = "172.26.40.105:8840" |
| 5 | 5 | # 系统数据库 |
| 6 | 6 | |
| 7 | + | |
| 7 | 8 | SQLALCHEMY_DATABASE_URI = "postgresql://postgres:chinadci@172.26.60.100:5432/dmap_manager" |
| 8 | 9 | |
| 10 | + | |
| 9 | 11 | # 指定精华表所在位置(必须为空间库),设置为None则存放在各自的实体库中 |
| 10 | 12 | #VACUATE_DB_URI = None |
| 11 | 13 | VACUATE_DB_URI = SQLALCHEMY_DATABASE_URI |
| 12 | 14 | |
| 13 | 15 | zookeeper = "172.26.99.168:2181" |
| 14 | 16 | |
| 17 | + | |
| 15 | 18 | #切片引擎 |
| 16 | 19 | tile_engine = "http://172.26.99.160:6060" |
| 17 | 20 | #矢量引擎 |
| 18 | 21 | vector_engine = "http://172.26.99.160:6060" |
| 19 | 22 | |
| 23 | + | |
| 20 | 24 | # 固定配置不需要修改 |
| 21 | 25 | swagger_configure = {"title": "DMapManager"} |
| 22 | 26 | entry_data_thread = 3 |
| 23 | 27 | scan_module = ["app.modules"] # API所在的模块 |
| 24 | 28 | SECRET_KEY = b'_5#y2L"F4Q8z\n\xec]/' |
| 29 | +# 权限 | |
| 30 | +UserPermission = ['admin'] | |
| 31 | +MonitorPermission = ['admin'] | |
| 32 | +DataPermission = ['admin', 'dataman'] | |
| 33 | +PublishPermission = ['admin', 'dataman', 'publisher'] | |
| 34 | +ServicePermission = ['admin', 'dataman', 'publisher'] | |
| 25 | 35 | |
| 26 | 36 | log_level = logging.INFO |
| 27 | - | ... | ... |
请
注册
或
登录
后发表评论