-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
""" | ||
|
||
"""用于提供历史遗留的接口/功能,仅供指定环境使用,收敛后逐步下架接口""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters