From cfdcd5c8a76d8357db60f3fea7aa8ab8c9eb4392 Mon Sep 17 00:00:00 2001 From: iSecloud <869820505@qq.com> Date: Wed, 13 Nov 2024 15:22:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E5=9F=9F=E5=90=8D=E9=80=9A?= =?UTF-8?q?=E8=BF=87alias=20name=E6=B8=B2=E6=9F=93=20#7938?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/backend/db_meta/api/db_module/apis.py | 7 +++---- dbm-ui/backend/db_services/cmdb/biz.py | 1 + dbm-ui/backend/db_services/cmdb/serializers.py | 1 + dbm-ui/backend/db_services/cmdb/views.py | 3 ++- dbm-ui/backend/db_services/mysql/sqlparse/handlers.py | 2 +- dbm-ui/backend/flow/consts.py | 1 + dbm-ui/backend/iam_app/views/cluster_provider.py | 5 +++-- dbm-ui/backend/ticket/builders/riak/riak_apply.py | 2 +- dbm-ui/backend/ticket/builders/tendbcluster/tendb_apply.py | 2 +- dbm-ui/backend/ticket/contexts.py | 2 +- 10 files changed, 15 insertions(+), 11 deletions(-) diff --git a/dbm-ui/backend/db_meta/api/db_module/apis.py b/dbm-ui/backend/db_meta/api/db_module/apis.py index fb78209574..90947148e7 100644 --- a/dbm-ui/backend/db_meta/api/db_module/apis.py +++ b/dbm-ui/backend/db_meta/api/db_module/apis.py @@ -21,19 +21,18 @@ @transaction.atomic -def create(bk_biz_id: int, name: str, cluster_type: str, creator: str = ""): +def create(bk_biz_id: int, name: str, cluster_type: str, alias: str = "", creator: str = ""): """创建DB模块 说明:这里的模块与cc无任何关系,仅用于关联配置文件,相当于场景化配置模板,比如gamedb,logdb等 """ bk_biz_id = request_validator.validated_integer(bk_biz_id, min_value=0) name = request_validator.validated_str(name) + alias_name = alias or name cluster_type = request_validator.validated_str(cluster_type) try: db_module = DBModule.objects.create( - bk_biz_id=bk_biz_id, - cluster_type=cluster_type, - db_module_name=name, + bk_biz_id=bk_biz_id, cluster_type=cluster_type, db_module_name=name, alias_name=alias_name ) except IntegrityError: raise DbModuleExistException(db_module_name=name) diff --git a/dbm-ui/backend/db_services/cmdb/biz.py b/dbm-ui/backend/db_services/cmdb/biz.py index 33845aeee6..5daffdc72b 100644 --- a/dbm-ui/backend/db_services/cmdb/biz.py +++ b/dbm-ui/backend/db_services/cmdb/biz.py @@ -83,6 +83,7 @@ def list_modules_by_biz(bk_biz_id: int, cluster_type: str) -> List[Dict]: "bk_biz_id": module.bk_biz_id, "db_module_id": module.db_module_id, "name": module.db_module_name, + "alias_name": module.alias_name, "db_module_info": module_infos[index][1], } for index, module in enumerate(modules) diff --git a/dbm-ui/backend/db_services/cmdb/serializers.py b/dbm-ui/backend/db_services/cmdb/serializers.py index aa9e6a078d..95598e7a31 100644 --- a/dbm-ui/backend/db_services/cmdb/serializers.py +++ b/dbm-ui/backend/db_services/cmdb/serializers.py @@ -51,6 +51,7 @@ class ListModulesSLZ(serializers.Serializer): class CreateModuleSLZ(serializers.Serializer): db_module_name = serializers.CharField(help_text=_("DB模块名")) + alias_name = serializers.CharField(help_text=_("DB模块别名"), required=False, default="") cluster_type = serializers.ChoiceField(help_text=_("集群类型"), choices=ClusterType.get_choices()) def validate(self, attrs): diff --git a/dbm-ui/backend/db_services/cmdb/views.py b/dbm-ui/backend/db_services/cmdb/views.py index d56b0f90ed..796e27fed4 100644 --- a/dbm-ui/backend/db_services/cmdb/views.py +++ b/dbm-ui/backend/db_services/cmdb/views.py @@ -81,7 +81,8 @@ def create_module(self, request, bk_biz_id): validated_data = self.params_validate(self.get_serializer_class()) cluster_type = validated_data["cluster_type"] db_module_name = validated_data["db_module_name"] - return Response(db_module.apis.create(bk_biz_id, db_module_name, cluster_type)) + alias_name = validated_data["alias_name"] + return Response(db_module.apis.create(bk_biz_id, db_module_name, cluster_type, alias_name)) @common_swagger_auto_schema( operation_summary=_("设置业务英文缩写"), diff --git a/dbm-ui/backend/db_services/mysql/sqlparse/handlers.py b/dbm-ui/backend/db_services/mysql/sqlparse/handlers.py index 239d081fa5..1023e38b30 100644 --- a/dbm-ui/backend/db_services/mysql/sqlparse/handlers.py +++ b/dbm-ui/backend/db_services/mysql/sqlparse/handlers.py @@ -107,7 +107,6 @@ def parse_show_desc_tokens(tokens): """允许特殊SQL语句""" # sql语句白名单 allowed_statements = [ - "status", "desc", "describe", "use", @@ -118,6 +117,7 @@ def parse_show_desc_tokens(tokens): "show create table", "show index", "show variables", + "explain", ] tokens = [token.value.lower() for token in tokens if not token.is_whitespace] for allowed in allowed_statements: diff --git a/dbm-ui/backend/flow/consts.py b/dbm-ui/backend/flow/consts.py index 55744c5861..6792f47f8f 100644 --- a/dbm-ui/backend/flow/consts.py +++ b/dbm-ui/backend/flow/consts.py @@ -271,6 +271,7 @@ class MediumEnum(str, StructuredEnum): Pulsar = EnumField("pulsar", _("pulsar")) Influxdb = EnumField("influxdb", _("influxdb")) DbMon = EnumField("dbmon", _("dbmon")) + DBTools = EnumField("dbtools", _("db工具包")) MySQLChecksum = EnumField("mysql-checksum", _("mysql-checksum")) MySQLRotateBinlog = EnumField("rotate-binlog", _("Binlog 滚动备份工具")) MySQLToolKit = EnumField("dba-toolkit", _("DBA 工具集")) diff --git a/dbm-ui/backend/iam_app/views/cluster_provider.py b/dbm-ui/backend/iam_app/views/cluster_provider.py index 7f4409933a..662713f330 100644 --- a/dbm-ui/backend/iam_app/views/cluster_provider.py +++ b/dbm-ui/backend/iam_app/views/cluster_provider.py @@ -82,8 +82,9 @@ def _list_instance_with_cluster_type( queryset = data_source.objects.filter(**condition)[page.slice_from : page.slice_to] results = [] for cluster in queryset: - cluster_type_label = cluster_type__label.get(cluster.cluster_type, cluster.cluster_type) - results.append({"id": cluster.id, "display_name": f"[{cluster_type_label}]{cluster.immute_domain}"}) + # cluster_type_label = cluster_type__label.get(cluster.cluster_type, cluster.cluster_type) + # 暂时去掉对label的渲染,iam这里会有名字校验 + results.append({"id": cluster.id, "display_name": f"{cluster.immute_domain}"}) return ListResult(results=results, count=len(results)) diff --git a/dbm-ui/backend/ticket/builders/riak/riak_apply.py b/dbm-ui/backend/ticket/builders/riak/riak_apply.py index ea35b9e012..02df4ad87e 100644 --- a/dbm-ui/backend/ticket/builders/riak/riak_apply.py +++ b/dbm-ui/backend/ticket/builders/riak/riak_apply.py @@ -29,7 +29,7 @@ class RiakApplyDetailSerializer(BigDataApplyDetailsSerializer): # display fields bk_cloud_name = serializers.SerializerMethodField(help_text=_("云区域")) - db_module_name = serializers.SerializerMethodField(help_text=_("DB模块名")) + db_module_name = serializers.SerializerMethodField(help_text=_("DB模块名(别名)")) city_name = serializers.SerializerMethodField(help_text=_("城市名")) def get_bk_cloud_name(self, obj): diff --git a/dbm-ui/backend/ticket/builders/tendbcluster/tendb_apply.py b/dbm-ui/backend/ticket/builders/tendbcluster/tendb_apply.py index 2fafa8bf47..bbca8f5882 100644 --- a/dbm-ui/backend/ticket/builders/tendbcluster/tendb_apply.py +++ b/dbm-ui/backend/ticket/builders/tendbcluster/tendb_apply.py @@ -49,7 +49,7 @@ class TenDBClusterApplyDetailSerializer(serializers.Serializer): bk_cloud_name = serializers.SerializerMethodField(help_text=_("云区域")) charset = serializers.SerializerMethodField(help_text=_("字符集")) version = serializers.SerializerMethodField(help_text=_("数据库版本")) - db_module_name = serializers.SerializerMethodField(help_text=_("DB模块名")) + db_module_name = serializers.SerializerMethodField(help_text=_("DB模块名(别名)")) city_name = serializers.SerializerMethodField(help_text=_("城市名")) machine_pair_cnt = serializers.SerializerMethodField(help_text=_("机器组数")) diff --git a/dbm-ui/backend/ticket/contexts.py b/dbm-ui/backend/ticket/contexts.py index 2920240a2f..391170d660 100644 --- a/dbm-ui/backend/ticket/contexts.py +++ b/dbm-ui/backend/ticket/contexts.py @@ -27,5 +27,5 @@ def __init__( self.app_abbr_map = {biz.bk_biz_id: biz.db_app_abbr for biz in bizs} db_modules = list(DBModule.objects.all()) - self.db_module_map = {module.db_module_id: module.db_module_name for module in db_modules} + self.db_module_map = {module.db_module_id: module.alias_name for module in db_modules} self.db_module_id__biz_id_map = {module.db_module_id: module.bk_biz_id for module in db_modules}