Skip to content

Commit 3a5a207

Browse files
committed
refactor: 通过环境变量控制job插件文件上传大小 --story=125211216
# Reviewed, transaction id: 54771
1 parent 7532e6f commit 3a5a207

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ is_use_celery: True
66
author: 蓝鲸智云
77
introduction: 标准运维是通过一套成熟稳定的任务调度引擎,把在多系统间的工作整合到一个流程,助力运维实现跨系统调度自动化的SaaS应用。
88
introduction_en: SOPS is a SaaS application that utilizes a set of mature and stable task scheduling engines to help realize cross-system scheduling automation, and integrates the work among multiple systems into a single process.
9-
version: 3.32.1-p8
9+
version: 3.32.1-p9
1010
category: 运维工具
1111
language_support: 中文
1212
desktop:

app_desc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
spec_version: 2
2-
app_version: "3.32.1-p8"
2+
app_version: "3.32.1-p9"
33
app:
44
region: default
55
bk_app_code: bk_sops

config/default.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215
# mako模板中:<script src="/a.js?v=${ STATIC_VERSION }"></script>
216216
# 如果静态资源修改了以后,上线前改这个版本号即可
217217

218-
STATIC_VERSION = "3.32.1-p8"
218+
STATIC_VERSION = "3.32.1-p9"
219219
DEPLOY_DATETIME = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
220220

221221
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
@@ -920,6 +920,9 @@ def check_engine_admin_permission(request, *args, **kwargs):
920920
CLEAN_EXPIRED_STATISTICS_BATCH_NUM = env.CLEAN_EXPIRED_STATISTICS_BATCH_NUM
921921
CLEAN_EXPIRED_STATISTICS_CRON = env.CLEAN_EXPIRED_STATISTICS_CRON
922922

923+
# JOB插件文件上传大小限制
924+
JOB_UPLOAD_FILE_SIZE_LIMIT = env.JOB_UPLOAD_FILE_SIZE_LIMIT
925+
923926
# 允许的HTTP插件域名
924927
ENABLE_HTTP_PLUGIN_DOMAINS_CHECK = env.ENABLE_HTTP_PLUGIN_DOMAINS_CHECK
925928
ALLOWED_HTTP_PLUGIN_DOMAINS = env.ALLOWED_HTTP_PLUGIN_DOMAINS

env.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@
189189
CLEAN_EXPIRED_STATISTICS_BATCH_NUM = int(os.getenv("BKAPP_CLEAN_EXPIRED_STATISTICS_BATCH_NUM", 100))
190190
CLEAN_EXPIRED_STATISTICS_CRON = tuple(os.getenv("BKAPP_CLEAN_EXPIRED_STATISTICS_CRON", "30 0 * * *").split())
191191

192+
# JOB插件文件上传大小限制
193+
JOB_UPLOAD_FILE_SIZE_LIMIT = int(os.getenv("BKAPP_JOB_UPLOAD_FILE_SIZE_LIMIT", 20 * 1024 * 1024))
194+
192195
# 允许的HTTP插件域名
193196
ENABLE_HTTP_PLUGIN_DOMAINS_CHECK = bool(int(os.getenv("ENABLE_HTTP_PLUGIN_DOMAINS_CHECK", 1)))
194197
ALLOWED_HTTP_PLUGIN_DOMAINS = os.getenv("ALLOWED_HTTP_PLUGIN_DOMAINS", "")

gcloud/apigw/views/job_file_upload.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
1111
specific language governing permissions and limitations under the License.
1212
"""
13+
from apigw_manager.apigw.decorators import apigw_require
14+
from blueapps.account.decorators import login_exempt
15+
from django.conf import settings
1316
from django.http import JsonResponse
1417
from django.views.decorators.csrf import csrf_exempt
1518
from django.views.decorators.http import require_POST
1619

17-
from blueapps.account.decorators import login_exempt
18-
1920
from gcloud import err_code
20-
from gcloud.core.models import Project
2121
from gcloud.apigw.constants import PROJECT_SCOPE_CMDB_BIZ
2222
from gcloud.apigw.decorators import (
23+
check_job_file_upload_white_apps,
2324
mark_request_whether_is_trust,
2425
return_json_response,
25-
check_job_file_upload_white_apps,
2626
)
2727
from gcloud.apigw.utils import get_project_with
28-
from apigw_manager.apigw.decorators import apigw_require
28+
from gcloud.core.models import Project
2929
from pipeline_plugins.components.query.sites.open.file_upload import file_upload
3030

3131

@@ -57,11 +57,14 @@ def job_file_upload(request, project_id, **kwargs):
5757
request.META["HTTP_APP_PROJECTID"] = project.id
5858

5959
# 文件大小不能大于 20M
60-
if request.FILES["file"].size > 20 * 1024 * 1024:
60+
if request.FILES["file"].size > settings.JOB_UPLOAD_FILE_SIZE_LIMIT:
6161
return JsonResponse(
6262
{
6363
"result": False,
64-
"message": "File upload failed: The file size cannot exceed 20M.",
64+
"message": (
65+
"File upload failed: The file size cannot exceed"
66+
f"{settings.JOB_UPLOAD_FILE_SIZE_LIMIT / 1024 / 1024}M."
67+
),
6568
"code": err_code.VALIDATION_ERROR.code,
6669
}
6770
)

0 commit comments

Comments
 (0)