From 2e04f4e735fdf38dab35e0fcbc8a886316f3bf4d Mon Sep 17 00:00:00 2001 From: waylon <1158341873@qq.com> Date: Mon, 23 Sep 2024 14:32:43 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E5=9F=BA=E7=A1=80=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E8=B0=83=E6=95=B4=20--story=3D119806440?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 5 ++--- settings.py | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/requirements.txt b/requirements.txt index ff6bbfc0df..acd5115175 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ # Base Django==3.2.15 -PyMySQL==0.6.7 -mysqlclient==2.0.3 +pymysql==1.0.2 requests==2.25.1 httplib2==0.19.0 Mako==1.1.4 @@ -61,7 +60,7 @@ importlib-metadata==3.7.3 protobuf==3.19.4 # blueapps -blueapps[opentelemetry,bkcrypto]==4.8.0 +blueapps[opentelemetry,bkcrypto]==4.14.0 whitenoise==5.2.0 raven==6.5.0 python-json-logger==2.0.1 diff --git a/settings.py b/settings.py index 628d6203d9..b4df5117f6 100644 --- a/settings.py +++ b/settings.py @@ -17,24 +17,27 @@ import os +import pymysql + +pymysql.install_as_MySQLdb() + # V3判断环境的环境变量为BKPAAS_ENVIRONMENT -if 'BKPAAS_ENVIRONMENT' in os.environ: - ENVIRONMENT = os.getenv('BKPAAS_ENVIRONMENT', 'dev') +if "BKPAAS_ENVIRONMENT" in os.environ: + ENVIRONMENT = os.getenv("BKPAAS_ENVIRONMENT", "dev") # V2判断环境的环境变量为BK_ENV else: - PAAS_V2_ENVIRONMENT = os.environ.get('BK_ENV', 'development') + PAAS_V2_ENVIRONMENT = os.environ.get("BK_ENV", "development") ENVIRONMENT = { - 'development': 'dev', - 'testing': 'stag', - 'production': 'prod', + "development": "dev", + "testing": "stag", + "production": "prod", }.get(PAAS_V2_ENVIRONMENT) -DJANGO_CONF_MODULE = 'config.{env}'.format(env=ENVIRONMENT) +DJANGO_CONF_MODULE = "config.{env}".format(env=ENVIRONMENT) try: - _module = __import__(DJANGO_CONF_MODULE, globals(), locals(), ['*']) + _module = __import__(DJANGO_CONF_MODULE, globals(), locals(), ["*"]) except ImportError as e: - raise ImportError("Could not import config '%s' (Is it on sys.path?): %s" - % (DJANGO_CONF_MODULE, e)) + raise ImportError("Could not import config '%s' (Is it on sys.path?): %s" % (DJANGO_CONF_MODULE, e)) for _setting in dir(_module): if _setting == _setting.upper(): From d03c65f811324bca27de70eb8b857c77ad8e2e43 Mon Sep 17 00:00:00 2001 From: waylon <1158341873@qq.com> Date: Thu, 26 Sep 2024 11:22:09 +0800 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=20batch=5Fdelete=20=E6=9D=83=E9=99=90=E9=97=AE=E9=A2=98=20#757?= =?UTF-8?q?2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gcloud/template_base/apis/drf/viewsets/template.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gcloud/template_base/apis/drf/viewsets/template.py b/gcloud/template_base/apis/drf/viewsets/template.py index 523be12462..16ef4c8ab8 100644 --- a/gcloud/template_base/apis/drf/viewsets/template.py +++ b/gcloud/template_base/apis/drf/viewsets/template.py @@ -13,7 +13,7 @@ import logging from drf_yasg.utils import swagger_auto_schema -from rest_framework import viewsets, permissions +from rest_framework import viewsets from rest_framework.decorators import action from rest_framework.exceptions import APIException from rest_framework.response import Response @@ -21,8 +21,8 @@ from gcloud.common_template.models import CommonTemplate from gcloud.core.apis.drf.viewsets import ApiMixin from gcloud.tasktmpl3.models import TaskTemplate -from gcloud.template_base.apis.drf.permission import ProjectTemplatePermission, CommonTemplatePermission -from gcloud.template_base.apis.drf.serilaziers.template import TemplateIdsSerializer, BatchDeleteSerialzer +from gcloud.template_base.apis.drf.permission import CommonTemplatePermission, ProjectTemplatePermission +from gcloud.template_base.apis.drf.serilaziers.template import BatchDeleteSerialzer, TemplateIdsSerializer from gcloud.template_base.domains.template_manager import TemplateManager logger = logging.getLogger("root") @@ -49,13 +49,13 @@ def batch_delete(self, request, *args, **kwargs): class ProjectTemplateViewSet(TemplateViewSet): queryset = TaskTemplate.objects.all() - permission_classes = [permissions.IsAuthenticated | ProjectTemplatePermission] + permission_classes = [ProjectTemplatePermission] template_type = "project" tmpl_model = TaskTemplate class CommonTemplateViewSet(TemplateViewSet): queryset = CommonTemplate.objects.all() - permission_classes = [permissions.IsAuthenticated | CommonTemplatePermission] + permission_classes = [CommonTemplatePermission] template_type = "common" tmpl_model = CommonTemplate From b515f88961aa91a79a5a297558af8c7fee479700 Mon Sep 17 00:00:00 2001 From: waylon <1158341873@qq.com> Date: Thu, 26 Sep 2024 15:07:17 +0800 Subject: [PATCH 3/5] =?UTF-8?q?perf:=20batch=5Frequest=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=95=B0=E6=8D=AE=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91=20#7574?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/utils/request.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/api/utils/request.py b/api/utils/request.py index 04170f48b4..2448c0973f 100644 --- a/api/utils/request.py +++ b/api/utils/request.py @@ -10,13 +10,15 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ -from django.utils.translation import ugettext_lazy as _ import logging +from django.utils.translation import ugettext_lazy as _ + from gcloud.conf import settings from gcloud.exceptions import ApiRequestError from gcloud.iam_auth.utils import check_and_raise_raw_auth_fail_exception from gcloud.utils.handlers import handle_api_error + from .thread import ThreadPool logger = logging.getLogger("root") @@ -126,6 +128,11 @@ def batch_request( check_and_raise_raw_auth_fail_exception(result, message) raise ApiRequestError(message) - data.extend(get_data(result)) + try: + data.extend(get_data(result)) + except Exception as e: + message = handle_api_error("[batch_request get_data]", func.path, params_and_future["params"], result) + logger.exception(f"{e}: {message}") + raise ApiRequestError(message) return data From 73bf1dca8cf6cb4f00b66ec93b8e3df3714e4f73 Mon Sep 17 00:00:00 2001 From: waylon <1158341873@qq.com> Date: Thu, 26 Sep 2024 15:52:13 +0800 Subject: [PATCH 4/5] feat: release V3.32.1-p2 #7567 --- app.yml | 2 +- app_desc.yaml | 2 +- config/default.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app.yml b/app.yml index cede19f9a8..1dedbf048f 100644 --- a/app.yml +++ b/app.yml @@ -6,7 +6,7 @@ is_use_celery: True author: 蓝鲸智云 introduction: 标准运维是通过一套成熟稳定的任务调度引擎,把在多系统间的工作整合到一个流程,助力运维实现跨系统调度自动化的SaaS应用。 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. -version: 3.32.1-p1 +version: 3.32.1-p2 category: 运维工具 language_support: 中文 desktop: diff --git a/app_desc.yaml b/app_desc.yaml index cd8c3594db..4ebea3fc05 100644 --- a/app_desc.yaml +++ b/app_desc.yaml @@ -1,5 +1,5 @@ spec_version: 2 -app_version: "3.32.1-p1" +app_version: "3.32.1-p2" app: region: default bk_app_code: bk_sops diff --git a/config/default.py b/config/default.py index 774b27ab80..ba5c58e90a 100644 --- a/config/default.py +++ b/config/default.py @@ -214,7 +214,7 @@ # mako模板中: # 如果静态资源修改了以后,上线前改这个版本号即可 -STATIC_VERSION = "3.32.1-p1" +STATIC_VERSION = "3.32.1-p2" DEPLOY_DATETIME = datetime.datetime.now().strftime("%Y%m%d%H%M%S") STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")] From 8bf1b75ac0b95535fcd3ae4d8f25a03c1b5cce9c Mon Sep 17 00:00:00 2001 From: pagezz Date: Fri, 27 Sep 2024 10:59:33 +0800 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E8=8E=B7=E5=8F=96=E6=96=B9=E5=BC=8F?= =?UTF-8?q?,=E9=99=8D=E4=BD=8E=E6=9C=AC=E5=9C=B0=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=88=90=E6=9C=AC=20(#7277)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 优化环境变量获取方式,降低本地开发配置成本 * refactor: 优化环境变量获取方式,降低本地开发配置成本 --------- Co-authored-by: pagezz-canway --- env_v3.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/env_v3.py b/env_v3.py index 44a0965753..dc974690b0 100644 --- a/env_v3.py +++ b/env_v3.py @@ -45,22 +45,34 @@ os.getenv("BKPAAS_ENVIRONMENT", "prod") ] + +def get_app_host(app_code): + app_host_key = "%s_HOST" % app_code.upper() + app_host = os.getenv(app_host_key) + if app_host: + return app_host + if app_code in BK_SAAS_HOSTS: + return BK_SAAS_HOSTS[app_code][BKSAAS_DEFAULT_MODULE_NAME] + return None + + BK_CC_HOST = os.getenv("BK_CC_HOST") BK_JOB_HOST = os.getenv("BK_JOB_HOST") -BK_NODEMAN_HOST = os.getenv("BK_NODEMAN_HOST", BK_SAAS_HOSTS["bk_nodeman"][BKSAAS_DEFAULT_MODULE_NAME]) +BK_NODEMAN_HOST = get_app_host("bk_nodeman") -BK_SOPS_HOST = os.getenv("BK_SOPS_HOST", BK_SAAS_HOSTS["bk_sops"][BKSAAS_DEFAULT_MODULE_NAME]) +BK_SOPS_HOST = get_app_host("bk_sops") # 兼容没有部署 GSEKIT 的情况 BK_GSE_KIT_PAGE_URL_TEMPLATE = os.getenv( "BK_GSEKIT_PAGE_URL_TEMPLATE", - BK_SAAS_HOSTS["bk_gsekit"][BKSAAS_DEFAULT_MODULE_NAME] + "/task-history/detail/{job_id}?biz={bk_biz_id}", + BK_SAAS_HOSTS.get("bk_gsekit", {}).get(BKSAAS_DEFAULT_MODULE_NAME, "") + + "/task-history/detail/{job_id}?biz={bk_biz_id}", ) # 用户管理配置 -BK_USER_MANAGE_HOST = os.getenv("BK_USER_MANAGE_HOST", BK_SAAS_HOSTS["bk_user_manage"][BKSAAS_DEFAULT_MODULE_NAME]) +BK_USER_MANAGE_HOST = get_app_host("bk_user_manage") # 文档中心 BK_DOC_CENTER_HOST = os.getenv("BK_DOC_CENTER_HOST", os.getenv("BK_DOCS_URL_PREFIX")) @@ -146,15 +158,18 @@ # CALLBACK 回调地址 BKAPP_INNER_CALLBACK_HOST = os.getenv( - "BKAPP_INNER_CALLBACK_HOST", BK_SAAS_HOSTS[APP_CODE][SOPS_CALLBACK_MODULE_NAME] or BK_PAAS_INNER_HOST + SITE_URL + "BKAPP_INNER_CALLBACK_HOST", + BK_SAAS_HOSTS[APP_CODE][SOPS_CALLBACK_MODULE_NAME] if BK_SAAS_HOSTS else BK_PAAS_INNER_HOST + SITE_URL, ) # APIGW CALLBACK SERVER服务地址 BKAPP_APIGW_CALLBACK_HOST = os.getenv( - "BKAPP_APIGW_CALLBACK_HOST", BK_SAAS_HOSTS[APP_CODE][SOPS_CALLBACK_MODULE_NAME] or BK_PAAS_INNER_HOST + SITE_URL + "BKAPP_APIGW_CALLBACK_HOST", + BK_SAAS_HOSTS[APP_CODE][SOPS_CALLBACK_MODULE_NAME] if BK_SAAS_HOSTS else BK_PAAS_INNER_HOST + SITE_URL, ) # API SERVER服务地址 BKAPP_APIGW_API_HOST = os.getenv( - "BKAPP_APIGW_API_HOST", BK_SAAS_HOSTS[APP_CODE][SOPS_API_SERVER_MODULE_NAME] or BK_PAAS_INNER_HOST + SITE_URL + "BKAPP_APIGW_API_HOST", + BK_SAAS_HOSTS[APP_CODE][SOPS_API_SERVER_MODULE_NAME] if BK_SAAS_HOSTS else BK_PAAS_INNER_HOST + SITE_URL, ) BKAPP_FILE_UPLOAD_ENTRY = os.getenv("BKAPP_FILE_UPLOAD_ENTRY", "")