Skip to content

Commit

Permalink
新增sql执行行数限制 (#2366)
Browse files Browse the repository at this point in the history
* 新增cas登录

* 新增cas登录

* 新增cas登录

* 新增cas登录

* 新增cas登录

* black格式化

* 修改模块引用错误

* 修改模块引用错误

* 修改模块引用错误

* 新增最大SQL提交数

* Update mssql.py

格式化代码

* black 代码

---------

Co-authored-by: lanjiaxuan <lanjiaxuan@e6yun.com>
  • Loading branch information
lanheader and lanjiaxuan authored Nov 6, 2023
1 parent f959849 commit d32d7bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions common/templates/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ <h5 style="color: darkgrey"><b>SQL上线</b></h5>
placeholder="自动驳回的等级,1表示警告驳回,2和空表示错误才驳回,其他表示不驳回" />
</div>
</div>
<div class="form-group">
<label for="max_sql_length"
class="col-sm-4 control-label">MAX_SQL_LENGTH</label>
<div class="col-sm-5">
<input type="number" class="form-control"
id="max_sql_length"
key="max_sql_length"
value="{{ config.max_sql_length }}"
placeholder="最大执行sql行数,默认10000条"/>
</div>
</div>
<div class="form-group">
<label for="enable_backup_switch"
class="col-sm-4 control-label">ENABLE_BACKUP_SWITCH</label>
Expand Down
5 changes: 5 additions & 0 deletions sql_api/api_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ def post(self, request):
check_result = check_engine.execute_check(
db_name=db_name, sql=request.data["full_sql"].strip()
)
max_sql_length = SysConfig().get("max_sql_length", default_value=10000)
if len(check_result.rows) > int(max_sql_length):
raise serializers.ValidationError(
{"errors": f"执行行数超过{str(max_sql_length)}行,请联系DBA核查!"}
)
except Exception as e:
raise serializers.ValidationError({"errors": f"{e}"})
check_result.rows = check_result.to_dict()
Expand Down

0 comments on commit d32d7bc

Please sign in to comment.