diff --git a/dbm-ui/backend/bk_web/middleware.py b/dbm-ui/backend/bk_web/middleware.py index 9cfd4e0853..55af29dc52 100644 --- a/dbm-ui/backend/bk_web/middleware.py +++ b/dbm-ui/backend/bk_web/middleware.py @@ -213,8 +213,9 @@ def __parser_request_url(self, request): """外部转发接口进行路由映射""" if self.__check_non_proxy_routing(request): return - self.__verify_request_url(request) - self.__check_specific_request_params(request) + if env.ENABLE_EXTERNAL_PROXY: + self.__verify_request_url(request) + self.__check_specific_request_params(request) request.path = f"/external/{request.path.lstrip('/')}" request.path_info = request.path setattr(request, "_dont_enforce_csrf_checks", True) @@ -222,7 +223,7 @@ def __parser_request_url(self, request): @error_handler(return_response=True) def __call__(self, request): # 外部路由转发仅提供给外部环境使用 - if env.ENABLE_EXTERNAL_PROXY: + if env.ENABLE_EXTERNAL_PROXY or env.ENABLE_OPEN_EXTERNAL_PROXY: self.__parser_request_url(request) else: # 解析来自外部转发的header diff --git a/dbm-ui/backend/bk_web/viewsets.py b/dbm-ui/backend/bk_web/viewsets.py index 006350adf8..f3284e3541 100644 --- a/dbm-ui/backend/bk_web/viewsets.py +++ b/dbm-ui/backend/bk_web/viewsets.py @@ -193,6 +193,10 @@ def after_response(self, request, response, *args, **kwargs): if ".css" in request.path: return HttpResponse(response, headers={"Content-Type": "text/css"}) + # 仅转发,提前返回response + if env.ENABLE_OPEN_EXTERNAL_PROXY: + return HttpResponse(response) + # 屏蔽iam申请的内部路由 if "/iam/get_apply_data/" in request.path or "/iam/simple_get_apply_data/" in request.path: data = response.json()["data"] diff --git a/dbm-ui/backend/configuration/views/system.py b/dbm-ui/backend/configuration/views/system.py index d7f7c40a00..27d64c1de2 100644 --- a/dbm-ui/backend/configuration/views/system.py +++ b/dbm-ui/backend/configuration/views/system.py @@ -95,7 +95,7 @@ def environ(self, request): "ENABLE_EXTERNAL_PROXY": env.ENABLE_EXTERNAL_PROXY, } # 非外部环境,补充额外环境变量 - if not env.ENABLE_EXTERNAL_PROXY: + if not env.ENABLE_EXTERNAL_PROXY and not env.ENABLE_OPEN_EXTERNAL_PROXY: envs.update( { "CC_IDLE_MODULE_ID": CcManage(env.DBA_APP_BK_BIZ_ID, "").get_biz_internal_module( diff --git a/dbm-ui/backend/env/__init__.py b/dbm-ui/backend/env/__init__.py index 8af103bb24..6bec572265 100644 --- a/dbm-ui/backend/env/__init__.py +++ b/dbm-ui/backend/env/__init__.py @@ -54,6 +54,8 @@ # 开启外部路由,供外部环境使用(DBConsole) ENABLE_EXTERNAL_PROXY = get_type_env(key="ENABLE_EXTERNAL_PROXY", _type=bool, default=False) +# 开启所有路由,不屏蔽。!!这里只用在合作伙伴环境!! +ENABLE_OPEN_EXTERNAL_PROXY = get_type_env(key="ENABLE_OPEN_EXTERNAL_PROXY", _type=bool, default=False) # ITSM 服务ID BK_ITSM_PROJECT_KEY = get_type_env(key="BK_ITSM_PROJECT_KEY", _type=str, default="0") diff --git a/dbm-ui/backend/urls.py b/dbm-ui/backend/urls.py index 19be2095b4..4c97af35cd 100644 --- a/dbm-ui/backend/urls.py +++ b/dbm-ui/backend/urls.py @@ -85,7 +85,7 @@ urlpatterns.append(path("redoc/", schema_view.with_ui("redoc", cache_timeout=0), name="schema-redoc")) # 外部路由转发仅提供给外部环境使用 -if env.ENABLE_EXTERNAL_PROXY: +if env.ENABLE_EXTERNAL_PROXY or env.ENABLE_OPEN_EXTERNAL_PROXY: methods_map = {method: "external_proxy" for method in views.APIView.http_method_names} urlpatterns.append( re_path(