From fa397d7b6757c963a2cf5a5b173422e3943f18ad Mon Sep 17 00:00:00 2001 From: iSecloud <869820505@qq.com> Date: Fri, 11 Oct 2024 17:02:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E4=BF=AE=E5=A4=8D=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=B1=A0=E5=88=97=E8=A1=A8cc=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=8A=A5=E9=94=99=20#7300?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/backend/components/mysql_priv_manager/client.py | 3 ++- dbm-ui/backend/configuration/constants.py | 1 + dbm-ui/backend/configuration/handlers/password.py | 4 +++- dbm-ui/backend/db_meta/models/app.py | 1 + dbm-ui/backend/db_services/dbresource/handlers.py | 9 ++------- dbm-ui/backend/db_services/dbresource/views/resource.py | 2 +- dbm-ui/backend/db_services/plugin/bf/views.py | 7 +++++-- 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/dbm-ui/backend/components/mysql_priv_manager/client.py b/dbm-ui/backend/components/mysql_priv_manager/client.py index ae170f5b33..8b0f78ef88 100644 --- a/dbm-ui/backend/components/mysql_priv_manager/client.py +++ b/dbm-ui/backend/components/mysql_priv_manager/client.py @@ -18,7 +18,8 @@ class _DBPrivManagerApi(BaseApi): MODULE = _("DB权限管理") BASE = MYSQL_PRIV_MANAGER_APIGW_DOMAIN - # 权限相关操作的默认超时时间,暂定3h + # 权限相关操作的默认超时时间,暂定3h,请在调用接口的时候按需使用 + # eg: DBPrivManagerApi.modify_admin_password(params=xxx,timeout=DBPrivManagerApi.TIMEOUT) TIMEOUT = 3 * 60 * 60 def __init__(self): diff --git a/dbm-ui/backend/configuration/constants.py b/dbm-ui/backend/configuration/constants.py index a10e19be90..c23135329d 100644 --- a/dbm-ui/backend/configuration/constants.py +++ b/dbm-ui/backend/configuration/constants.py @@ -87,6 +87,7 @@ class SystemSettingsEnum(str, StructuredEnum): FREE_BK_MODULE_ID = EnumField("FREE_BK_MODULE_ID", _("业务空闲模块ID")) # 主机默认统一转移到 DBM 业务下托管,若业务 ID 属于这个列表,则转移到对应的业务下 INDEPENDENT_HOSTING_BIZS = EnumField("INDEPENDENT_HOSTING_BIZS", _("独立托管机器的业务列表")) + BF_WHITELIST_BIZS = EnumField("BF_WHITELIST_BIZS", _("BF业务白名单")) SPEC_OFFSET = EnumField("SPEC_OFFSET", _("默认的规格参数偏移量")) DEVICE_CLASSES = EnumField("DEVICE_CLASSES", _("机型列表")) BKM_DUTY_NOTICE = EnumField("BKM_DUTY_NOTICE", _("轮值通知设置")) diff --git a/dbm-ui/backend/configuration/handlers/password.py b/dbm-ui/backend/configuration/handlers/password.py index d10486855b..e6496ddf47 100644 --- a/dbm-ui/backend/configuration/handlers/password.py +++ b/dbm-ui/backend/configuration/handlers/password.py @@ -183,7 +183,9 @@ def modify_admin_password(cls, operator: str, password: str, lock_hour: int, ins "security_rule_name": DBM_PASSWORD_SECURITY_NAME, "async": False, } - data = DBPrivManagerApi.modify_admin_password(params=modify_password_params, raw=True)["data"] + data = DBPrivManagerApi.modify_admin_password( + params=modify_password_params, raw=True, timeout=DBPrivManagerApi.TIMEOUT + )["data"] return data @classmethod diff --git a/dbm-ui/backend/db_meta/models/app.py b/dbm-ui/backend/db_meta/models/app.py index a7cef38ba4..86896815f7 100644 --- a/dbm-ui/backend/db_meta/models/app.py +++ b/dbm-ui/backend/db_meta/models/app.py @@ -73,6 +73,7 @@ def get_app_attr(cls, bk_biz_id, attr_name="db_app_abbr", default=""): @classmethod def batch_get_app_attr(cls, bk_biz_ids, attr_name="db_app_abbr"): + bk_biz_ids = list(set(bk_biz_ids)) apps = cls.objects.filter(bk_biz_id__in=bk_biz_ids) infos = apps.values("bk_biz_id", attr_name) if set(apps.values_list("bk_biz_id", flat=True)) != set(bk_biz_ids): diff --git a/dbm-ui/backend/db_services/dbresource/handlers.py b/dbm-ui/backend/db_services/dbresource/handlers.py index 8af5189cfc..d606f90b2c 100644 --- a/dbm-ui/backend/db_services/dbresource/handlers.py +++ b/dbm-ui/backend/db_services/dbresource/handlers.py @@ -394,17 +394,12 @@ def spec_resource_count(cls, bk_biz_id: int, bk_cloud_id: int, spec_ids: List[in resource_type = ClusterType.cluster_type_to_db_type(spec_cluster_type[0]) # 构造申请参数 spec_count_details = [ - spec.get_group_apply_params( - group_mark=str(spec.spec_id), - count=1, - group_count=1, - bk_cloud_id=bk_cloud_id, - location_spec={"city": city, "sub_zone_ids": []}, - ) + spec.get_group_apply_params(group_mark=str(spec.spec_id), count=1, group_count=1, bk_cloud_id=bk_cloud_id) for spec in specs ] spec_count_details = list(itertools.chain(*spec_count_details)) spec_count_params = { + "location_spec": {"city": "" if city == "default" else city, "sub_zone_ids": []}, "for_biz_id": bk_biz_id, "resource_type": resource_type, "bk_cloud_id": bk_cloud_id, diff --git a/dbm-ui/backend/db_services/dbresource/views/resource.py b/dbm-ui/backend/db_services/dbresource/views/resource.py index bbde0bcc7f..d9ed0569c2 100644 --- a/dbm-ui/backend/db_services/dbresource/views/resource.py +++ b/dbm-ui/backend/db_services/dbresource/views/resource.py @@ -131,7 +131,7 @@ def _format_resource_fields(data, _cloud_info, _biz_infos): # 获取云区域信息和业务信息 cloud_info = ResourceQueryHelper.search_cc_cloud(get_cache=True) - for_biz_ids = [data["dedicated_biz"] for data in resource_data["details"]] + for_biz_ids = [data["dedicated_biz"] for data in resource_data["details"] if data["dedicated_biz"]] for_biz_infos = AppCache.batch_get_app_attr(bk_biz_ids=for_biz_ids, attr_name="bk_biz_name") # 格式化资源池字段信息 for data in resource_data.get("details") or []: diff --git a/dbm-ui/backend/db_services/plugin/bf/views.py b/dbm-ui/backend/db_services/plugin/bf/views.py index bac5ef1bf1..8a4e4f06a1 100644 --- a/dbm-ui/backend/db_services/plugin/bf/views.py +++ b/dbm-ui/backend/db_services/plugin/bf/views.py @@ -17,7 +17,8 @@ from backend import env from backend.bk_web import viewsets from backend.bk_web.swagger import common_swagger_auto_schema -from backend.configuration.models import DBAdministrator +from backend.configuration.constants import SystemSettingsEnum +from backend.configuration.models import DBAdministrator, SystemSettings from backend.db_meta.enums import ClusterType from backend.db_meta.models import Machine from backend.db_services.plugin.bf.serializers import HasBFPrivSerializer @@ -58,5 +59,7 @@ def has_host_bf_access(self, request, *args, **kwargs): @action(methods=["GET"], detail=False) def list_bf_biz_whitelist(self, request, *args, **kwargs): # 目前默认只认为默认DBM业务才能申请 - bf_biz_whitelist = [env.DBA_APP_BK_BIZ_ID] + bf_biz_whitelist = SystemSettings.get_setting_value( + SystemSettingsEnum.BF_WHITELIST_BIZS, default=[env.DBA_APP_BK_BIZ_ID] + ) return Response(bf_biz_whitelist)