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 diff --git a/env_v3.py b/env_v3.py index ac9c4e3de7..a7f13a7604 100644 --- a/env_v3.py +++ b/env_v3.py @@ -45,23 +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", - str(BK_SAAS_HOSTS["bk_gsekit"][BKSAAS_DEFAULT_MODULE_NAME]).rstrip("/") + BK_SAAS_HOSTS.get("bk_gsekit", {}).get(BKSAAS_DEFAULT_MODULE_NAME, "").rstrip("/") + "/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")) @@ -147,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", "") 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