Skip to content

Commit

Permalink
feat(backend): 提供 dns 操作 api TencentBlueKing#7695
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhw8 committed Oct 31, 2024
1 parent dd03280 commit bd05a3d
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 0 deletions.
12 changes: 12 additions & 0 deletions dbm-ui/backend/legacy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
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.
"""

"""用于提供历史遗留的接口/功能,仅供指定环境使用,收敛后逐步下架接口"""
46 changes: 46 additions & 0 deletions dbm-ui/backend/legacy/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
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 as _
from rest_framework import serializers

from backend.db_meta.models import Cluster
from backend.exceptions import ValidationError


class CreateDNSSerializer(serializers.Serializer):
class CreateDomainSerializer(serializers.Serializer):
domain_name = serializers.CharField(help_text=_("域名"))
instances = serializers.ListField(help_text=_("实例列表"), child=serializers.CharField(), allow_empty=False)
manager = serializers.CharField(help_text=_("管理者"), required=False, allow_blank=True)
remark = serializers.CharField(help_text=_("域名备注信息"), required=False, allow_blank=True)
domain_type = serializers.CharField(help_text=_("域名类型"), required=False, allow_blank=True)
extends = serializers.CharField(help_text=_("域名自定义扩张字段"), required=False, allow_blank=True)

app = serializers.CharField(help_text=_("GCS业务英文缩写"))
bk_cloud_id = serializers.IntegerField(help_text=_("云区域 ID"))
domains = serializers.ListField(help_text=_("域名列表"), child=CreateDomainSerializer(), allow_empty=False)

def validate(self, attrs):
domains = attrs.get("domains", [])
domains = [domain["domain_name"] for domain in domains]
if Cluster.objects.filter(immute_domain__in=domains).exists():
raise ValidationError(_("域名存在于 DBM 中,不允许通过此接口修改,请联系管理员"))
return attrs


class DeleteDNSSerializer(CreateDNSSerializer):
class DeleteDomainSerializer(CreateDNSSerializer.CreateDomainSerializer):
instances = serializers.ListField(
help_text=_("实例列表"), child=serializers.IntegerField(), allow_empty=True, required=False, default=[]
)

domains = serializers.ListField(help_text=_("域名列表"), child=DeleteDomainSerializer(), allow_empty=False)
18 changes: 18 additions & 0 deletions dbm-ui/backend/legacy/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
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 rest_framework.routers import DefaultRouter

from .views import DnsViewSet

routers = DefaultRouter(trailing_slash=True)
routers.register(r"dns", DnsViewSet, basename="dns")

urlpatterns = routers.urls
40 changes: 40 additions & 0 deletions dbm-ui/backend/legacy/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
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 _
from rest_framework.decorators import action
from rest_framework.response import Response

from backend.bk_web import viewsets
from backend.bk_web.swagger import common_swagger_auto_schema
from backend.components import DnsApi
from backend.iam_app.dataclass.actions import ActionEnum
from backend.iam_app.handlers.drf_perm.base import ResourceActionPermission
from backend.legacy.serializers import CreateDNSSerializer, DeleteDNSSerializer

SWAGGER_TAG = ["legacy"]


class DnsViewSet(viewsets.SystemViewSet):
def get_default_permission_class(self) -> list:
return [ResourceActionPermission([ActionEnum.GLOBAL_MANAGE])]

@common_swagger_auto_schema(operation_summary=_("创建 DNS"), tags=SWAGGER_TAG, request_body=CreateDNSSerializer())
@action(methods=["PUT"], detail=False, serializer_class=CreateDNSSerializer)
def create_domain(self, request, *args, **kwargs):
data = self.params_validate(self.get_serializer_class())
return Response(DnsApi.create_domain(data))

@common_swagger_auto_schema(operation_summary=_("删除 DNS"), tags=SWAGGER_TAG, request_body=CreateDNSSerializer())
@action(methods=["DELETE"], detail=False, serializer_class=DeleteDNSSerializer)
def delete_domain(self, request, *args, **kwargs):
data = self.params_validate(self.get_serializer_class())
return Response(DnsApi.delete_domain(data))
1 change: 1 addition & 0 deletions dbm-ui/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
path("dbbase/", include("backend.db_services.dbbase.urls")),
path("quick_search/", include("backend.db_services.quick_search.urls")),
path("plugin/", include("backend.db_services.plugin.urls")),
path("legacy/", include("backend.legacy.urls")),
]

urlpatterns = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:

name: db-nginx-configmap
labels: {{- include "common.labels.standard" . | nindent 4 }}
{{- if .Values.commonLabels }}
Expand Down

0 comments on commit bd05a3d

Please sign in to comment.