Skip to content

Commit

Permalink
fix(backend): 域名通过alias name渲染 #7938
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud committed Nov 27, 2024
1 parent ec0f506 commit cfdcd5c
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 11 deletions.
7 changes: 3 additions & 4 deletions dbm-ui/backend/db_meta/api/db_module/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions dbm-ui/backend/db_services/cmdb/biz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions dbm-ui/backend/db_services/cmdb/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion dbm-ui/backend/db_services/cmdb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=_("设置业务英文缩写"),
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/db_services/mysql/sqlparse/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def parse_show_desc_tokens(tokens):
"""允许特殊SQL语句"""
# sql语句白名单
allowed_statements = [
"status",
"desc",
"describe",
"use",
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions dbm-ui/backend/flow/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 工具集"))
Expand Down
5 changes: 3 additions & 2 deletions dbm-ui/backend/iam_app/views/cluster_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/ticket/builders/riak/riak_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/ticket/builders/tendbcluster/tendb_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=_("机器组数"))

Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/ticket/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit cfdcd5c

Please sign in to comment.