From c79223186b2b0340eb488479beed2d4625977062 Mon Sep 17 00:00:00 2001 From: wklken Date: Mon, 6 May 2024 11:51:08 +0800 Subject: [PATCH 1/2] refactor(legacy_esb): remove support for legacy_esb and bk-esb-buffet --- .../apigateway/apigateway/conf/celery_conf.py | 1 - .../apigateway/apigateway/conf/default.py | 28 - .../apigateway/apigateway/conf/log_utils.py | 5 - .../apigateway/apigateway/conf/unittest_env | 7 - .../bk-esb-buffet-definition.yaml | 22 - .../bk-esb-buffet-resources.yaml | 8 - .../editions/ee/legacy_esb/README.md | 75 --- .../editions/ee/legacy_esb/__init__.pyi | 0 .../apigateway/editions/ee/legacy_esb/apps.py | 22 - .../editions/ee/legacy_esb/constants.py | 48 -- .../ee/legacy_esb/management/__init__.pyi | 0 .../management/commands/__init__.pyi | 0 .../management/commands/assert_core_data.py | 37 -- .../management/commands/clear_ng_core_data.py | 87 --- .../management/commands/fix_legacy_data.py | 46 -- .../commands/pre_check_buffet_data.py | 76 --- .../commands/pre_check_core_data.py | 62 -- .../commands/sync_buffet_definitions.py | 77 --- .../management/commands/sync_core_data.py | 45 -- .../commands/sync_legacy_esb_reusable_data.py | 35 - .../editions/ee/legacy_esb/managers.py | 45 -- .../editions/ee/legacy_esb/models.py | 619 ------------------ .../editions/ee/legacy_esb/paas2/__init__.pyi | 0 .../editions/ee/legacy_esb/paas2/constants.py | 25 - .../editions/ee/legacy_esb/paas2/models.py | 76 --- .../apigateway/editions/ee/legacy_esb/sync.py | 352 ---------- .../editions/ee/legacy_esb/tasks.py | 135 ---- .../editions/ee/tests/legacy_esb/__init__.pyi | 0 .../editions/ee/tests/legacy_esb/conftest.py | 25 - .../tests/legacy_esb/management/__init__.pyi | 0 .../management/commands/__init__.pyi | 0 .../ee/tests/legacy_esb/test_managers.py | 61 -- .../ee/tests/legacy_esb/test_models.py | 512 --------------- .../editions/ee/tests/legacy_esb/test_sync.py | 339 ---------- .../apigateway/legacy_esb/__init__.py | 17 - .../legacy_esb/management/__init__.py | 17 - .../management/commands/__init__.py | 17 - .../apigateway/legacy_esb/paas2/__init__.py | 17 - .../apigateway/legacy_esb/paas2/apps.py | 22 - .../apigateway/tests/legacy_esb/__init__.py | 17 - .../tests/legacy_esb/management/__init__.py | 17 - .../management/commands/__init__.py | 17 - .../apigateway/apigateway/utils/db_router.py | 2 - src/dashboard/bin/post_migrate | 8 - src/esb/esb/conf/default.py | 20 - src/esb/esb/conf/unittest_env | 3 - src/esb/esb/esb/bkapp/helpers.py | 7 - src/esb/esb/esb/paas2/__init__.py | 17 - src/esb/esb/esb/paas2/apps.py | 23 - src/esb/esb/esb/paas2/models.py | 36 - src/esb/esb/esb/utils/db_router.py | 53 -- 51 files changed, 3180 deletions(-) delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-esb-buffet-definition.yaml delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-esb-buffet-resources.yaml delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/README.md delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/__init__.pyi delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/apps.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/constants.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/__init__.pyi delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/__init__.pyi delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/assert_core_data.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/clear_ng_core_data.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/fix_legacy_data.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/pre_check_buffet_data.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/pre_check_core_data.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/sync_buffet_definitions.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/sync_core_data.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/sync_legacy_esb_reusable_data.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/managers.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/models.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/paas2/__init__.pyi delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/paas2/constants.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/paas2/models.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/sync.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/tasks.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/__init__.pyi delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/conftest.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/management/__init__.pyi delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/management/commands/__init__.pyi delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/test_managers.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/test_models.py delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/test_sync.py delete mode 100644 src/dashboard/apigateway/apigateway/legacy_esb/__init__.py delete mode 100644 src/dashboard/apigateway/apigateway/legacy_esb/management/__init__.py delete mode 100644 src/dashboard/apigateway/apigateway/legacy_esb/management/commands/__init__.py delete mode 100644 src/dashboard/apigateway/apigateway/legacy_esb/paas2/__init__.py delete mode 100644 src/dashboard/apigateway/apigateway/legacy_esb/paas2/apps.py delete mode 100644 src/dashboard/apigateway/apigateway/tests/legacy_esb/__init__.py delete mode 100644 src/dashboard/apigateway/apigateway/tests/legacy_esb/management/__init__.py delete mode 100644 src/dashboard/apigateway/apigateway/tests/legacy_esb/management/commands/__init__.py delete mode 100644 src/esb/esb/esb/paas2/__init__.py delete mode 100644 src/esb/esb/esb/paas2/apps.py delete mode 100644 src/esb/esb/esb/paas2/models.py delete mode 100644 src/esb/esb/esb/utils/db_router.py diff --git a/src/dashboard/apigateway/apigateway/conf/celery_conf.py b/src/dashboard/apigateway/apigateway/conf/celery_conf.py index ca6aa7167..bceb371d3 100644 --- a/src/dashboard/apigateway/apigateway/conf/celery_conf.py +++ b/src/dashboard/apigateway/apigateway/conf/celery_conf.py @@ -32,7 +32,6 @@ "apigateway.apps.monitor.tasks", "apigateway.apps.metrics.tasks", "apigateway.apps.permission.tasks", - "apigateway.legacy_esb.tasks", "apigateway.apps.esb.component.tasks", "apigateway.controller.tasks", ) diff --git a/src/dashboard/apigateway/apigateway/conf/default.py b/src/dashboard/apigateway/apigateway/conf/default.py index 3d75806e8..7804c5ed1 100644 --- a/src/dashboard/apigateway/apigateway/conf/default.py +++ b/src/dashboard/apigateway/apigateway/conf/default.py @@ -130,9 +130,6 @@ # "iam.contrib.iam_migration", # 蓝鲸通知中心 "bk_notice_sdk", - # 开源版旧版 ESB 数据 - "apigateway.legacy_esb", - "apigateway.legacy_esb.paas2", ] MIDDLEWARE = [ @@ -326,24 +323,8 @@ "isolation_level": env.str("BK_ESB_DATABASE_ISOLATION_LEVEL", "READ COMMITTED"), }, }, - "paas2": { - "ENGINE": env.str("BK_PAAS2_DATABASE_ENGINE", "django.db.backends.mysql"), - "NAME": env.str("BK_PAAS2_DATABASE_NAME", ""), - "USER": env.str("BK_PAAS2_DATABASE_USER", ""), - "PASSWORD": env.str("BK_PAAS2_DATABASE_PASSWORD", ""), - "HOST": env.str("BK_PAAS2_DATABASE_HOST", ""), - "PORT": env.int("BK_PAAS2_DATABASE_PORT", 3306), - "OPTIONS": { - "isolation_level": env.str("BK_PAAS2_DATABASE_ISOLATION_LEVEL", "READ COMMITTED"), - }, - }, } -# 如果 paas2 database 未配置,则去除 -BK_PAAS2_ENABLED = all([DATABASES["paas2"]["NAME"], DATABASES["paas2"]["USER"], DATABASES["paas2"]["HOST"]]) -if not BK_PAAS2_ENABLED: - DATABASES.pop("paas2", None) - # redis 配置 REDIS_HOST = env.str("BK_APIGW_REDIS_HOST", "localhost") REDIS_PORT = env.int("BK_APIGW_REDIS_PORT", 6379) @@ -438,15 +419,6 @@ "BK_APIGW_CELERY_TASK_DEFAULT_QUEUE", f"{REDIS_PREFIX}bk_apigateway_dashboard_celery" ) -CELERY_BEAT_SCHEDULE.update( - { - "apigateway.legacy_esb.tasks.sync_legacy_esb_reusable_data": { - "task": "apigateway.legacy_esb.tasks.sync_legacy_esb_reusable_data", - "schedule": crontab(minute="*/5"), - }, - } -) - if env.bool("FEATURE_FLAG_ENABLE_RUN_DATA_METRICS", True): CELERY_BEAT_SCHEDULE.update( { diff --git a/src/dashboard/apigateway/apigateway/conf/log_utils.py b/src/dashboard/apigateway/apigateway/conf/log_utils.py index 39acc1699..65f2b657f 100644 --- a/src/dashboard/apigateway/apigateway/conf/log_utils.py +++ b/src/dashboard/apigateway/apigateway/conf/log_utils.py @@ -125,11 +125,6 @@ def get_logging_config(log_level: str, is_local: bool, log_dir: str, log_to_file "level": "INFO", "propagate": True, }, - "apigateway.legacy_esb.management": { - "handlers": ["console_simple"], - "level": "INFO", - "propagate": True, - }, }, } diff --git a/src/dashboard/apigateway/apigateway/conf/unittest_env b/src/dashboard/apigateway/apigateway/conf/unittest_env index b1314c3ca..d19d39c10 100644 --- a/src/dashboard/apigateway/apigateway/conf/unittest_env +++ b/src/dashboard/apigateway/apigateway/conf/unittest_env @@ -16,13 +16,6 @@ export BK_ESB_DATABASE_PASSWORD="" export BK_ESB_DATABASE_HOST="" export BK_ESB_DATABASE_PORT="3306" export BK_ESB_DATABASE_ISOLATION_LEVEL="" -export BK_PAAS2_DATABASE_ENGINE="django.db.backends.sqlite3" -export BK_PAAS2_DATABASE_NAME="paas2_unittest.sqlite3" -export BK_PAAS2_DATABASE_USER="paas2" -export BK_PAAS2_DATABASE_PASSWORD="" -export BK_PAAS2_DATABASE_HOST="localhost" -export BK_PAAS2_DATABASE_PORT="3306" -export BK_PAAS2_DATABASE_ISOLATION_LEVEL="" export BK_APIGW_REDIS_HOST="dev.service" export BK_APIGW_REDIS_PORT="6378" export BK_APIGW_REDIS_PASSWORD="" diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-esb-buffet-definition.yaml b/src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-esb-buffet-definition.yaml deleted file mode 100644 index 9ed48b7f4..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-esb-buffet-definition.yaml +++ /dev/null @@ -1,22 +0,0 @@ -release: - version: 1.2.0 - comment: "comment: 网关升级1.13" - - -apigateway: - description: "蓝鲸 ESB 自助接入组件(BUFFET),迁移自蓝鲸旧版 ESB" - description_en: "BlueKing ESB self-service component (BUFFET), migrated from the legacy ESB" - is_public: false - api_type: 1 - maintainers: - - "admin" - -stage: - name: "prod" - vars: {} - proxy_http: - timeout: 600 - upstreams: - loadbalance: "roundrobin" - hosts: - - host: "http://1.1.1.1" diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-esb-buffet-resources.yaml b/src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-esb-buffet-resources.yaml deleted file mode 100644 index 7fcc5bd7e..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-esb-buffet-resources.yaml +++ /dev/null @@ -1,8 +0,0 @@ -swagger: '2.0' -basePath: / -info: - version: '0.1' - title: API Gateway Resources -schemes: -- http -paths: {} diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/README.md b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/README.md deleted file mode 100644 index 442fe6603..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/README.md +++ /dev/null @@ -1,75 +0,0 @@ -# README.md - -> 注意:PaaS2/ESB 迁移数据至新版 BK-ESB,全部在包 legacy_esb 中处理,禁止其他模块依赖此包,待数据迁移完毕,可直接去除此包 - -## 迁移 PaaS2/ESB 核心数据至新版 BK-ESB - -进入服务 `bk-apigateway-dashboard-web` 的容器,然后执行以下指令: - -``` -检查数据 -- python manager.py pre_check_core_data - -检查数据成功,则执行以下指令同步数据 -- python manage.py fix_legacy_data -- python manage.py clear_ng_core_data -- python manage.py sync_core_data -- python manage.py assert_core_data -``` - - -## 迁移 PaaS2/ESB 自助接入组件至 API Gateway - -进入服务 `bk-apigateway-dashboard-web` 的容器,然后执行以下指令: -``` -检查数据 -- python manage.py pre_check_buffet_data - -检查数据成功,则执行以下指令同步数据 -- python manage.py sync_buffet_definitions -``` - -迁移后,还需要更新旧版接入层 nginx 的配置,添加以下 location -``` -location ~ ^/api/c/self-service-api/(.*) { - rewrite /api/c/self-service-api/(.*)$ /api/bk-esb-buffet/prod/$1 break; - proxy_pass http://BKAPI_HOST; - - proxy_pass_header Server; - proxy_set_header X-Request-Uri $request_uri; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Scheme $scheme; - proxy_set_header Host $http_host; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_set_header X-Forwarded-Host $http_host; - proxy_redirect off; - proxy_read_timeout 600; -} -``` - -## 迁移数据的指令列表 - -python manage.py assert_core_data -- 迁移完成后,校验迁移前后数据是否一致 - -python manage.py clear_ng_core_data -- 删除新版 BK-ESB 中的数据,主要包括:ComponentSystem、DocCategory、SystemDocCategory、ESBChannel、ComponentDoc、AppComponentPermission -- 迁移数据时,会保持新旧版数据ID一致,因此如果新版中已生成数据,需将生成的数据删除,再进行迁移,以防止数据冲突 - -python manage.py fix_legacy_data -- 修复旧版数据,如旧版文档分类名称,可能重复,迁移前,需去除重复的数据 - -python manage.py pre_check_core_data -- 迁移前,预检数据,校验数据是否满足迁移条件,如文档分类名称成否有重复 - -python manage.py sync_core_data -- 迁移 PaaS2/ESB 至新版 BK-ESB - -python manage.py sync_buffet_definitions -- 迁移 PaaS2/ESB 自助接入组件至 API Gateway -- 最大超时时间调整为 600 秒 -- 如果自助接入组件配置 extra_headers 中,包含不符合要求(^[a-zA-Z0-9-_]{1,100}$)的请求头,需要调整请求头后才能迁移,如果请求头包含下划线(_),迁移时,将被转为中折线(-) - -python manage.py export_buffet_to_resources -- 将 PaaS2/ESB 中自定义组件配置,导出为网关 Swagger 资源配置文件 diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/__init__.pyi b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/__init__.pyi deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/apps.py b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/apps.py deleted file mode 100644 index 116f25382..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/apps.py +++ /dev/null @@ -1,22 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -from django.apps import AppConfig - - -class LegacyEsbConfig(AppConfig): - name = "apigateway.legacy_esb" diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/constants.py b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/constants.py deleted file mode 100644 index ab6ee5c74..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/constants.py +++ /dev/null @@ -1,48 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -from blue_krill.data_types.enum import EnumField, StructuredEnum - - -class SystemDocCategoryEnum(StructuredEnum): - DEFAULT = EnumField("默认分类") - USER_BASE_SERVICE = EnumField("基础用户服务") - CONFIG_SERVICE = EnumField("配置管理") - HOST_MANAGEMENT = EnumField("主机管控") - MANAGEMENT_TOOLS = EnumField("管理工具") - - -BK_SYSTEMS = [ - "BK_LOGIN", - "BK_PAAS", - "CC", - "GSE", - "JOB", - "JOBV3", - "CMSI", - "SOPS", - "MONITOR", - "MONITOR_V3", - "USERMANAGE", - "ESB", - "ITSM", - "LOG_SEARCH", - "IAM", - "BK_DOCS_CENTER", - "DATA", - "BSCP", -] diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/__init__.pyi b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/__init__.pyi deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/__init__.pyi b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/__init__.pyi deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/assert_core_data.py b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/assert_core_data.py deleted file mode 100644 index e9ab061d3..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/assert_core_data.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- coding: utf-8 -*- -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -"""PaaS2/ESB 核心数据迁移完成后,校验迁移前后数据是否一致""" - -from django.core.management.base import BaseCommand - -from apigateway.legacy_esb import sync - - -class Command(BaseCommand): - def handle(self, *args, **options): - synchronizer_classes = [ - sync.DocCategorySynchronizer, - sync.ComponentSystemSynchronizer, - sync.SystemDocCategorySynchronizer, - sync.ESBChannelSynchronizer, - sync.ComponentDocSynchronizer, - sync.AppComponentPermissionSynchronizer, - ] - for synchronizer_cls in synchronizer_classes: - synchronizer_cls().assert_data() diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/clear_ng_core_data.py b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/clear_ng_core_data.py deleted file mode 100644 index aa8f0c2fe..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/clear_ng_core_data.py +++ /dev/null @@ -1,87 +0,0 @@ -# -*- coding: utf-8 -*- -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -"""删除新版 BK-ESB 中的部分核心数据,防止迁移旧版 PaaS2/ESB 时数据冲突""" - -import logging - -from django.core.management.base import BaseCommand - -from apigateway.apps.esb.bkcore.models import ( - AppComponentPermission, - AppPermissionApplyRecord, - ComponentDoc, - ComponentResourceBinding, - ComponentSystem, - DocCategory, - ESBChannel, - SystemDocCategory, -) - -logger = logging.getLogger(__name__) - - -class Command(BaseCommand): - def add_arguments(self, parser): - parser.add_argument("--dry-run", dest="dry_run", action="store_true", default=False) - - def handle(self, dry_run: bool, *args, **options): - self._clear_ng_core_data(dry_run) - - def _clear_ng_core_data(self, dry_run: bool): - if dry_run: - logger.info("delete all system doc-category relations") - logger.info("delete all doc-categories") - logger.info("delete all component-docs") - logger.info("delete all app-component-permissions") - logger.info("delete all component-resource-binding") - logger.info("delete all components") - logger.info("delete all systems") - return - - if self._is_confirmed_clear_ng_core_data(): - self._delete_ng_core_data() - logger.info("clear ng core data done") - - def _delete_ng_core_data(self): - SystemDocCategory.objects.all().delete() - DocCategory.objects.all().delete() - ComponentDoc.objects.all().delete() - AppComponentPermission.objects.all().delete() - ComponentResourceBinding.objects.all().delete() - AppPermissionApplyRecord.objects.all().delete() - ESBChannel.objects.all().delete() - ComponentSystem.objects.all().delete() - - def _is_confirmed_clear_ng_core_data(self) -> bool: - tips = "{}\n确认是否删除新版中以上模型的所有数据,可能导致新版组件 API 无法访问,请谨慎操作".format( - "\n".join( - [ - "ComponentSystem", - "DocCategory", - "SystemDocCategory", - "ESBChannel", - "ComponentDoc", - "AppComponentPermission", - "AppPermissionApplyRecord", - "ComponentResourceBinding", - ] - ) - ) - confirm = input(f"{tips}:yes/no?") - return confirm == "yes" diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/fix_legacy_data.py b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/fix_legacy_data.py deleted file mode 100644 index fd98bcba3..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/fix_legacy_data.py +++ /dev/null @@ -1,46 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -"""修复 PaaS2/ESB 中的部分数据""" - -import logging -from typing import List - -from django.core.management.base import BaseCommand - -from apigateway.legacy_esb import models as legacy_models - -logger = logging.getLogger(__name__) - - -class Command(BaseCommand): - def handle(self, *args, **options): - self._fix_legacy_doc_category() - - def _fix_legacy_doc_category(self): - duplicate_names = legacy_models.SystemDocCategory.objects.get_duplicate_names() - if not duplicate_names: - return - - if self._is_confirmed_fix_legacy_doc_category(duplicate_names): - legacy_models.SystemDocCategory.objects.delete_duplicate_names() - - def _is_confirmed_fix_legacy_doc_category(self, duplicate_names: List[str]) -> bool: - confirm = input( - f"旧版文档分类 `name={', '.join(duplicate_names)}` 重复,请确认是否更新组件系统所属的文档分类,并删除重复的文档分类:yes/no?" - ) - return confirm == "yes" diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/pre_check_buffet_data.py b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/pre_check_buffet_data.py deleted file mode 100644 index 4273e8c6e..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/pre_check_buffet_data.py +++ /dev/null @@ -1,76 +0,0 @@ -# -*- coding: utf-8 -*- -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -"""检查 PaaS2/ESB 自助接入组件配置是否满足迁移需求""" - -import logging -import re -import sys -from collections import defaultdict - -from django.core.management.base import BaseCommand - -from apigateway.legacy_esb import models as legacy_models - -logger = logging.getLogger(__name__) - - -class Command(BaseCommand): - def handle(self, *args, **options): - self.check_extra_headers() - - logger.info("check ok") - - def check_extra_headers(self): - usable_header_key_pattern = re.compile(r"^[a-zA-Z0-9-_]{1,100}$") - id_to_invalid_header_keys = defaultdict(list) - id_to_underscore_header_keys = defaultdict(list) - - buffet_components = legacy_models.ESBBuffetComponent.objects.all() - for component in buffet_components: - for key in component.extra_headers_dict: - if not usable_header_key_pattern.match(key): - id_to_invalid_header_keys[component.id].append(key) - continue - - if "_" in key: - id_to_underscore_header_keys[component.id].append(key) - - if id_to_invalid_header_keys: - logger.error( - "以下自助接入组件的 extra_headers 中包含不符合规则的请求头,请修复后再迁移\n%s", - "\n".join( - [ - f"id={id_}, invalid_header_keys: {', '.join(header_keys)}" - for id_, header_keys in id_to_invalid_header_keys.items() - ] - ), - ) - sys.exit(1) - - if id_to_underscore_header_keys: - logger.error( - "以下自助接入组件的 extra_headers 中存在包含下划线(_)的请求头,迁移时,会将下划线自动转换为中折线(-),迁移前请确认可否默认转换\n%s", - "\n".join( - [ - f"id={id_}, invalid_header_keys: {', '.join(header_keys)}" - for id_, header_keys in id_to_underscore_header_keys.items() - ] - ), - ) - sys.exit(1) diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/pre_check_core_data.py b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/pre_check_core_data.py deleted file mode 100644 index 18a69cbf8..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/pre_check_core_data.py +++ /dev/null @@ -1,62 +0,0 @@ -# -*- coding: utf-8 -*- -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -"""检查 PaaS2/ESB 中的数据,是否满足迁移条件,如果不满足,则无法直接迁移""" - -import logging -import sys - -from django.core.management.base import BaseCommand - -from apigateway.legacy_esb import models as legacy_models -from apigateway.legacy_esb import sync - -logger = logging.getLogger(__name__) - - -class Command(BaseCommand): - def handle(self, *args, **options): - self.check_legacy_doc_category() - self.check_field_values() - - logger.info("check ok") - - def check_legacy_doc_category(self): - duplicate_names = legacy_models.SystemDocCategory.objects.get_duplicate_names() - if duplicate_names: - logger.error( - "旧版文档分类中,name=%s 重复,请手动删除重复数据,或调用 `python manage.py fix_legacy_data` 删除重复数据", - ", ".join(duplicate_names), - ) - sys.exit(1) - - def check_field_values(self): - pre_check_synchronizeres = [ - sync.DocCategorySynchronizer(), - sync.ComponentSystemSynchronizer(), - sync.ESBChannelSynchronizer(), - sync.AppComponentPermissionSynchronizer(), - ] - for synchronizer in pre_check_synchronizeres: - result, message = synchronizer.pre_check_data() - if not result: - logger.error(message) - logger.error( - "新版与旧版核心数据有差异,需调用指令 `python manage.py clear_ng_core_data` 删除新版数据后,再同步" - ) - sys.exit(1) diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/sync_buffet_definitions.py b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/sync_buffet_definitions.py deleted file mode 100644 index 9a9cc6f05..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/sync_buffet_definitions.py +++ /dev/null @@ -1,77 +0,0 @@ -# -*- coding: utf-8 -*- -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -"""迁移 PaaS2/ESB 自助接入组件至 API Gateway""" - -import logging -import os - -from django.conf import settings -from django.core.management import call_command -from django.core.management.base import BaseCommand - -from apigateway.legacy_esb import models as legacy_models -from apigateway.legacy_esb.management.commands import pre_check_buffet_data - -logger = logging.getLogger(__name__) - -_BUFFET_API_NAME = "bk-esb-buffet" -_DASHBOARD_INNER_URL = os.environ.get("DASHBOARD_INNER_URL", "http://apigw-dashboard.service.consul:6000") -_APIGW_DEFINITIONS_DIR = os.path.join(settings.BASE_DIR, "data/apigw-definitions") - - -class Command(BaseCommand): - def handle(self, *args, **options): - if not legacy_models.ESBBuffetComponent.objects.all(): - logger.info("不存在自助接入的组件,跳过自助接入组件的迁移步骤") - return - - # 预检数据,如果数据不符合预期,将不会继续同步数据 - pre_check_buffet_data.Command().handle() - - call_command( - "export_buffet_to_resources", - f"--file-path={_APIGW_DEFINITIONS_DIR}/bk-esb-buffet-resources.yaml", - ) - self._sync_buffet_definitions() - - def _sync_buffet_definitions(self): - call_command( - "sync_apigw_config", - f"--api-name={_BUFFET_API_NAME}", - f"--host={_DASHBOARD_INNER_URL}/backend", - f"--file={_APIGW_DEFINITIONS_DIR}/bk-esb-buffet-definition.yaml", - ) - call_command( - "sync_apigw_stage", - f"--api-name={_BUFFET_API_NAME}", - f"--host={_DASHBOARD_INNER_URL}/backend", - f"--file={_APIGW_DEFINITIONS_DIR}/bk-esb-buffet-definition.yaml", - ) - call_command( - "sync_apigw_resources", - f"--api-name={_BUFFET_API_NAME}", - f"--host={_DASHBOARD_INNER_URL}/backend", - f"--file={_APIGW_DEFINITIONS_DIR}/bk-esb-buffet-resources.yaml", - ) - call_command( - "create_version_and_release_apigw", - f"--api-name={_BUFFET_API_NAME}", - f"--host={_DASHBOARD_INNER_URL}/backend", - f"--file={_APIGW_DEFINITIONS_DIR}/bk-esb-buffet-definition.yaml", - ) diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/sync_core_data.py b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/sync_core_data.py deleted file mode 100644 index b6a4b8b58..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/sync_core_data.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -"""迁移 PaaS2/ESB 核心数据至新版 BK-ESB""" - -from django.core.management.base import BaseCommand - -from apigateway.legacy_esb import sync -from apigateway.legacy_esb.management.commands import pre_check_core_data - - -class Command(BaseCommand): - def add_arguments(self, parser): - parser.add_argument("--dry-run", dest="dry_run", action="store_true", default=False) - parser.add_argument("--force", dest="force", action="store_true", default=False) - - def handle(self, dry_run: bool, force: bool, *args, **options): - # 预检数据,如果数据不符合预期,将不会继续同步数据 - pre_check_core_data.Command().handle() - - synchronizer_classes = [ - sync.DocCategorySynchronizer, - sync.ComponentSystemSynchronizer, - sync.SystemDocCategorySynchronizer, - sync.ESBChannelSynchronizer, - sync.ComponentDocSynchronizer, - sync.AppComponentPermissionSynchronizer, - ] - for synchronizer_cls in synchronizer_classes: - synchronizer_cls().sync_legacy_to_ng(dry_run, force) diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/sync_legacy_esb_reusable_data.py b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/sync_legacy_esb_reusable_data.py deleted file mode 100644 index e4784fe64..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/management/commands/sync_legacy_esb_reusable_data.py +++ /dev/null @@ -1,35 +0,0 @@ -# -*- coding: utf-8 -*- -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -""" -同步 Legacy ESB 的可复用数据到新版 ESB -此部分数据,可重复同步 -""" - -from django.core.management.base import BaseCommand - -from apigateway.legacy_esb.tasks import LegacyESBSynchronizer - - -class Command(BaseCommand): - def add_arguments(self, parser): - parser.add_argument("--dry-run", dest="dry_run", action="store_true", help="dry run") - - def handle(self, dry_run: bool, *args, **options): - synchronizer = LegacyESBSynchronizer() - synchronizer.sync(dry_run) diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/managers.py b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/managers.py deleted file mode 100644 index 5ce8aeb23..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/managers.py +++ /dev/null @@ -1,45 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -import itertools -import operator -from collections import Counter -from typing import List - -from django.db import models - - -class SystemDocCategoryManager(models.Manager): - def get_duplicate_names(self) -> List[str]: - names = list(self.values_list("name", flat=True)) - return [name for name, count in Counter(names).items() if count > 1] - - def delete_duplicate_names(self): - from apigateway.legacy_esb.models import ComponentSystem - - duplicate_names = self.get_duplicate_names() - fields = self.filter(name__in=duplicate_names).values("name", "id").order_by("name", "id") - for _, group in itertools.groupby(fields, key=operator.itemgetter("name")): - ids = [field["id"] for field in group] - - assert len(ids) >= 2 - - reserved_id = ids[0] - deleted_ids = ids[1:] - - ComponentSystem.objects.filter(doc_category_id__in=deleted_ids).update(doc_category_id=reserved_id) - self.filter(id__in=deleted_ids).delete() diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/models.py b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/models.py deleted file mode 100644 index 3e496cf82..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/models.py +++ /dev/null @@ -1,619 +0,0 @@ -# -*- coding: utf-8 -*- -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -import abc -import datetime -import hashlib -import json -import re -import urllib -from typing import Any, Dict, List, Optional - -from django.db import models -from django.utils import timezone -from django.utils.encoding import force_bytes - -from apigateway.apps.esb.constants import DataTypeEnum -from apigateway.apps.permission.constants import PermissionLevelEnum -from apigateway.core.constants import HTTP_METHOD_ANY -from apigateway.legacy_esb.constants import BK_SYSTEMS, SystemDocCategoryEnum -from apigateway.legacy_esb.managers import SystemDocCategoryManager - -# NOTE: 旧版本模型定义,仅支持旧版数据迁移,禁止其它包依赖此模块 - - -_MAX_DOC_CATEGORY_PRIORITY = 9000 -_MAX_APIGATEWAY_TIMEOUT = 600 - - -# 需与 django Model 共用,因 metaclass 冲突,不能指定 metaclass=abc.ABCMeta -class LegacyModelMigrator: - @abc.abstractmethod - def clone_to_ng_obj(self) -> models.Model: - """根据旧版对象克隆一个新版对象""" - raise NotImplementedError - - @abc.abstractmethod - def update_ng_obj_fields(self, ng_obj: models.Model) -> models.Model: - """根据旧版对象更新新版对象""" - raise NotImplementedError - - @abc.abstractmethod - def is_changed(self, ng_obj: models.Model) -> bool: - """新、旧版本对比,检查数据是否更新""" - raise NotImplementedError - - def has_different_field_value(self, src_obj: Any, dst_obj: Any, fields: List[str]) -> bool: - return any(getattr(src_obj, field) != getattr(dst_obj, field) for field in fields) - - -def _convert_is_official_to_data_type(is_official: bool) -> int: - """将配置 is_official 转换为 data_type""" - # 此转换策略,仅针对数据迁移,不具有普适性,因此未放到 DataTypeEnum 定义中 - if is_official: - return DataTypeEnum.OFFICIAL_PUBLIC.value - return DataTypeEnum.CUSTOM.value - - -class ComponentSystem(LegacyModelMigrator, models.Model): - """组件系统""" - - name = models.CharField("系统名称", max_length=64) - description = models.CharField("系统标签", db_column="label", max_length=128, help_text="系统简要说明") - component_admin = models.CharField("组件开发负责人", max_length=128, default="", blank=True) - interface_admin = models.CharField("系统接口负责人", max_length=128, default="", blank=True) - system_link = models.CharField( - "系统链接", max_length=1024, default="", blank=True, help_text="标准的HTTP链接,多个以分号分隔" - ) - belong_to = models.CharField("系统所属组织", max_length=128, default="", blank=True) - comment = models.TextField("备注", db_column="remark", default="", blank=True) - execute_timeout = models.IntegerField( - "执行类超时时长", null=True, blank=True, help_text="单位秒,未设置时超时时长为30秒" - ) - query_timeout = models.IntegerField( - "查询类超时时长", null=True, blank=True, help_text="单位秒,未设置时超时时长为30秒" - ) - doc_category_id = models.IntegerField("文档分类ID", null=True, blank=True) - - class Meta: - db_table = "esb_component_system" - - def __str__(self): - return self.name - - def clone_to_ng_obj(self): - from apigateway.apps.esb.bkcore.models import ComponentSystem as NGComponentSystem - - return NGComponentSystem( - id=self.id, - name=self.name, - description=self.description, - comment=self.comment, - timeout=self.timeout, - data_type=self.data_type, - _maintainers=";".join(self.maintainers), - ) - - def update_ng_obj_fields(self, ng_obj): - ng_obj.__dict__.update( - { - "name": self.name, - "description": self.description, - "comment": self.comment, - "timeout": self.timeout, - "data_type": self.data_type, - "_maintainers": ";".join(self.maintainers), - } - ) - return ng_obj - - def is_changed(self, ng_obj): - return self.has_different_field_value( - self, - ng_obj, - fields=[ - "name", - "description", - "comment", - "timeout", - "maintainers", - ], - ) - - @property - def is_official(self): - return self.name in BK_SYSTEMS - - @property - def data_type(self) -> int: - return _convert_is_official_to_data_type(self.is_official) - - @property - def timeout(self) -> Optional[int]: - if self.query_timeout and self.execute_timeout: - return max(self.query_timeout, self.execute_timeout) - - return None - - @property - def maintainers(self): - maintainers = re.findall(r"[^,; ]+", f"{self.component_admin};{self.interface_admin}") - return sorted(set(maintainers), key=maintainers.index) - - -class ESBChannel(LegacyModelMigrator, models.Model): - """Channel for ESB - - One channel links a path to a component - """ - - TYPE_CHOICE = ( - (1, "执行API"), - (2, "查询API"), - ) - PERM_LEVEL_CHOICE = ( - (0, "无限制"), - (1, "普通权限"), - (2, "敏感权限"), - (3, "特殊权限"), - ) - - description = models.CharField( - "通道名称", db_column="name", max_length=64, help_text='通道名称,长度限制为64字符,例如"查询服务器列表"' - ) - path = models.CharField("通道路径", max_length=255, help_text='通道请求路径,例如"/host/get_host_list/"') - method = models.CharField("请求类型", max_length=32, null=True, default="", blank=True) - component_system = models.ForeignKey( - ComponentSystem, verbose_name="所属组件系统", null=True, on_delete=models.PROTECT - ) - component_codename = models.CharField( - "对应组件代号", max_length=255, help_text='组件代号,例如 "generic.host.get_host_list"' - ) - name = models.CharField("组件英文名", db_column="component_name", max_length=64, default="", blank=True, null=True) - is_active = models.BooleanField("是否开启", default=True) - last_modified_time = models.DateTimeField("最后更新", auto_now=True) - created_time = models.DateTimeField("创建时间", auto_now_add=True) - timeout = models.IntegerField("超时时长", db_column="timeout_time", blank=True, null=True) - type = models.IntegerField("组件类型", choices=TYPE_CHOICE, default=2) - comp_conf = models.TextField("组件配置", default="", null=True, blank=True) - perm_level = models.IntegerField("权限级别", choices=PERM_LEVEL_CHOICE, default=0) - is_hidden = models.BooleanField("组件是否隐藏", default=False, help_text="是否显示文档,及是否在权限申请中展示") - rate_limit_required = models.BooleanField("是否校验访问频率", default=False) - rate_limit_conf = models.TextField( - "请求频率配置", - null=True, - blank=True, - help_text=( - "限制访问频率,允许多种规则,例如" - '{"app_ratelimit": {"__default": {"token":1000, "minute": 1}, "gcloud": {"token":1000, "minute": 1}}}' - ), - ) - extra_info = models.TextField("额外信息", default="", blank=True, help_text="存储组件额外信息,用于文档展示等") - - class Meta: - db_table = "esb_channel" - unique_together = ("path", "method") - - def __str__(self): - return self.name - - def clone_to_ng_obj(self): - from apigateway.apps.esb.bkcore.models import ESBChannel as NGESBChannel - - assert self.ng_system, "ng_system can't be none" - - return NGESBChannel( - id=self.id, - system=self.ng_system, - method=self.method, - path=self.path, - name=self.name, - description=self.description, - component_codename=self.component_codename, - permission_level=self.permission_level, - timeout=self.timeout, - config=self.config, - is_active=self.is_active, - is_public=self.is_public, - data_type=self.ng_system.data_type, - ) - - def update_ng_obj_fields(self, ng_obj): - assert self.ng_system, "ng_system can't be none" - - ng_obj.__dict__.update( - { - "system": self.ng_system, - "method": self.method, - "path": self.path, - "name": self.name, - "description": self.description, - "component_codename": self.component_codename, - "permission_level": self.permission_level, - "timeout": self.timeout, - "config": self.config, - "is_active": self.is_active, - "is_public": self.is_public, - "data_type": self.ng_system.data_type, - } - ) - return ng_obj - - def is_changed(self, ng_obj): - return self.has_different_field_value( - self, - ng_obj, - fields=[ - "method", - "path", - "name", - "description", - "component_codename", - "permission_level", - "timeout", - "config", - "is_active", - "is_public", - ], - ) - - @property - def system_id(self): - return self.component_system_id - - @property - def permission_level(self) -> str: - legacy_to_new = { - 0: PermissionLevelEnum.UNLIMITED.value, - 1: PermissionLevelEnum.NORMAL.value, - 2: PermissionLevelEnum.SENSITIVE.value, - 3: PermissionLevelEnum.SPECIAL.value, - } - return legacy_to_new[self.perm_level] - - @property - def is_public(self) -> bool: - return not self.is_hidden - - @property - def config(self) -> Dict[str, Any]: - try: - return dict(json.loads(self.comp_conf)) - except Exception: - return {} - - -class UserAuthToken(models.Model): - """AuthToken""" - - app_code = models.CharField("蓝鲸智云应用编码", max_length=128) - username = models.CharField("用户名", max_length=64) - auth_token = models.CharField("token内容", max_length=255) - expires = models.DateTimeField("token过期时间") - last_accessed_time = models.DateTimeField("最后访问时间", auto_now_add=True) - created_time = models.DateTimeField("创建时间", auto_now_add=True) - - def __str__(self): - return self.auth_token - - class Meta: - db_table = "esb_user_auth_token" - - -class ESBBuffetComponent(models.Model): - """ESB 组件自助接入""" - - HTTP_METHOD_CHOICES = [ - ("GET", "GET"), - ("POST", "POST"), - ("_ORIG", "[所有] 透传原始请求类型(不建议使用)"), - ] - FAVOR_CTYPE_CHOICES = [ - ("json", "json"), - ("form", "form"), - ] - TYPE_CHOICE = ( - (1, "执行API"), - (2, "查询API"), - ) - - description = models.CharField("名称", db_column="name", max_length=256) - system = models.ForeignKey( - ComponentSystem, verbose_name="所属系统", null=True, blank=True, on_delete=models.PROTECT - ) - - dest_url = models.CharField("目标接口地址", max_length=2048) - dest_http_method = models.CharField("HTTP请求类型", max_length=8, choices=HTTP_METHOD_CHOICES) - favor_post_ctype = models.CharField("编码POST参数方式", max_length=64, default="json", choices=FAVOR_CTYPE_CHOICES) - extra_headers = models.CharField("额外请求头信息", max_length=2048, default="", blank=True) - extra_params = models.CharField("额外请求参数", max_length=2048, default="", blank=True) - - registed_path = models.CharField("注册到的组件路径", max_length=255) - registed_http_method = models.CharField("注册到的请求类型", max_length=8, choices=HTTP_METHOD_CHOICES) - - submitter = models.CharField(max_length=256, null=True, default="", blank=True) - approver = models.CharField(max_length=256, null=True, default="", blank=True) - approver_message = models.CharField(max_length=1024, null=True, default="", blank=True) - status = models.IntegerField("状态", default=0) - - mappings_input = models.CharField( - "输入Mappings", null=True, default="", blank=True, max_length=1024, help_text="JSON格式数据" - ) - mappings_output = models.CharField( - "输出Mappings", null=True, default="", blank=True, max_length=1024, help_text="JSON格式数据" - ) - last_modified_time = models.DateTimeField(auto_now=True) - created_time = models.DateTimeField(auto_now_add=True) - timeout_time = models.IntegerField( - "超时时长", blank=True, null=True, help_text="单位秒,未设置时以所属组件系统超时时长为准" - ) - type = models.IntegerField("组件类型", choices=TYPE_CHOICE, default=2) - - def __str__(self): - return self.description - - class Meta: - db_table = "esb_buffet_component" - - @property - def _name(self) -> str: - name = "_".join(re.findall(r"[a-zA-Z0-9]+", self.registed_path)) - return f"{self._convert_method(self.registed_http_method)}_{name}".lower() - - @property - def _timeout(self) -> Optional[int]: - system_timeout = None - if self.system: - system_timeout = self.system.timeout - - if system_timeout and self.timeout_time: - return max(system_timeout, self.timeout_time) - - return _MAX_APIGATEWAY_TIMEOUT - - def _convert_method(self, method: str) -> str: - if method == "_ORIG": - return HTTP_METHOD_ANY - return method - - @property - def _backend_host(self): - parsed_url = urllib.parse.urlparse(self.dest_url) - return f"{parsed_url.scheme}://{parsed_url.netloc}" - - @property - def _backend_path(self): - parsed_url = urllib.parse.urlparse(self.dest_url) - return parsed_url.path - - def _enrich_extra_headers(self) -> Dict[str, str]: - headers = self._canonical_extra_headers - if self.dest_http_method != "POST" or "content-type" in [key.lower() for key in headers]: - return headers - - if self.favor_post_ctype == "form": - headers.update({"Content-Type": "application/x-www-form-urlencoded"}) - else: - headers.update({"Content-Type": "application/json"}) - - return headers - - @property - def _canonical_extra_headers(self) -> Dict[str, str]: - return {key.replace("_", "-"): value for key, value in self.extra_headers_dict.items()} - - @property - def extra_headers_dict(self): - try: - return dict(json.loads(self.extra_headers)) - except Exception: - return {} - - -class ESBBuffetMapping(models.Model): - """ESB 组件自助接入,参数mapping""" - - name = models.CharField("名称", max_length=40, unique=True) - type = models.IntegerField("类型", null=True, blank=True) - source_type = models.IntegerField("源码类型") - source = models.TextField("源码", null=True, default="", blank=True) - owner = models.CharField(max_length=256, null=True, default="", blank=True) - is_active = models.BooleanField(default=True) - last_modified_time = models.DateTimeField(auto_now=True) - created_time = models.DateTimeField(auto_now_add=True) - - def __str__(self): - return self.name - - class Meta: - db_table = "esb_buffet_component_mapping" - - -class ModelWithBoard(models.Model): - """标记组件所属的board""" - - board = models.CharField(max_length=64, null=True, blank=True, db_index=True) - - class Meta: - abstract = True - - -class ComponentAPIDoc(ModelWithBoard): - """ - @summary: 组件API文档 - """ - - component_id = models.IntegerField("组件ID", unique=True, help_text="对应 ESBChannel 中的组件ID") - doc_md = models.TextField("组件文档(MD格式)", blank=True, null=True) - doc_html = models.TextField("组件文档(HTML格式)", blank=True, null=True) - doc_md_md5 = models.CharField(max_length=128, default="", blank=True) - created_time = models.DateTimeField("创建时间", auto_now_add=True) - updated_time = models.DateTimeField("创建时间", auto_now=True) - - def __str__(self): - return "%s" % self.component_id - - class Meta: - verbose_name = "组件接口文档" - verbose_name_plural = "组件接口文档" - db_table = "esb_api_doc" - - def split_doc_by_language(self) -> List[dict]: - return [ - { - "component_id": self.component_id, - "language": language, - "content": content, - "content_md5": hashlib.md5(force_bytes(content)).hexdigest(), - } - for language, content in self.doc_markdowns.items() - ] - - @property - def doc_markdowns(self): - try: - return json.loads(self.doc_md) - except Exception: - return {} - - -def init_app_comp_perm_expires(): - return timezone.now() + datetime.timedelta(days=180) - - -class AppComponentPerm(LegacyModelMigrator, models.Model): - """APP申请的组件权限""" - - bk_app_code = models.CharField("蓝鲸应用编码", db_column="app_code", max_length=64) - component_id = models.IntegerField("组件ID") - expires = models.DateTimeField("APP访问组件过期时间", default=init_app_comp_perm_expires) - created_time = models.DateTimeField("创建时间", auto_now_add=True) - last_accessed_time = models.DateTimeField("APP最后访问组件时间", default=timezone.now) - - def __str__(self): - return "" % (self.bk_app_code, self.component_id) - - class Meta: - verbose_name = "APP组件权限" - verbose_name_plural = "APP组件权限" - db_table = "esb_app_component_perm" - unique_together = ("bk_app_code", "component_id") - - def clone_to_ng_obj(self): - from apigateway.apps.esb.bkcore.models import AppComponentPermission as NGAppComponentPermission - - return NGAppComponentPermission( - id=self.id, - bk_app_code=self.bk_app_code, - component_id=self.component_id, - expires=self.expires, - ) - - def update_ng_obj_fields(self, ng_obj): - ng_obj.__dict__.update( - { - "bk_app_code": self.bk_app_code, - "component_id": self.component_id, - "expires": self.expires, - } - ) - return ng_obj - - def is_changed(self, ng_obj): - return self.has_different_field_value( - self, - ng_obj, - fields=[ - "bk_app_code", - "component_id", - "expires", - ], - ) - - -class WxmpAccessToken(models.Model): - """保存微信开放平台业务的 AccessToken""" - - wx_app_id = models.CharField("微信APPID", max_length=128) - access_token = models.CharField("凭证", max_length=1024) - expires = models.DateTimeField("凭证过期时间") - last_updated_time = models.DateTimeField("最后访问时间", default=timezone.now) - - class Meta: - db_table = "esb_wxmp_access_token" - verbose_name = "微信公众号AccessToken" - verbose_name_plural = "微信公众号AccessToken" - - def __str__(self): - return self.wx_app_id - - -class SystemDocCategory(LegacyModelMigrator, models.Model): - """系统文档分类""" - - name = models.CharField("分类名称", max_length=32, db_index=True) - priority = models.IntegerField("优先级", default=1000, help_text="展示时,数字小的展示在前面") - created_time = models.DateTimeField("创建时间", auto_now_add=True) - - objects = SystemDocCategoryManager() - - def __str__(self): - return self.name - - class Meta: - verbose_name = "系统文档分类" - verbose_name_plural = "系统文档分类" - db_table = "esb_system_doc_category" - - @property - def is_official(self): - return self.name in dict(SystemDocCategoryEnum.get_django_choices()) - - def clone_to_ng_obj(self): - from apigateway.apps.esb.bkcore.models import DocCategory as NGDocCategory - - return NGDocCategory( - id=self.id, - name=self.name, - priority=self._ng_priority, - data_type=self.data_type, - ) - - def update_ng_obj_fields(self, ng_obj): - ng_obj.__dict__.update( - { - "name": self.name, - "priority": self._ng_priority, - "data_type": self.data_type, - } - ) - return ng_obj - - @property - def data_type(self) -> int: - return _convert_is_official_to_data_type(self.is_official) - - @property - def _ng_priority(self) -> int: - # 旧版 priority 值越小优先级越高 - # 新版 priority 值越大优先级越高 - # 迁移时,为保障优先级顺序,设置 priority 最大值减去旧版值 - return _MAX_DOC_CATEGORY_PRIORITY - self.priority - - def is_changed(self, ng_obj) -> bool: - return self.name != ng_obj.name diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/paas2/__init__.pyi b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/paas2/__init__.pyi deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/paas2/constants.py b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/paas2/constants.py deleted file mode 100644 index d431a1b67..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/paas2/constants.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -from blue_krill.data_types.enum import EnumField, StructuredEnum - - -class PaaS2ApplyStatusEnum(StructuredEnum): - PENDING = EnumField("applying", "申请中") - APPROVED = EnumField("pass", "审批通过") - REJECTED = EnumField("reject", "驳回") diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/paas2/models.py b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/paas2/models.py deleted file mode 100644 index 5dcccb991..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/paas2/models.py +++ /dev/null @@ -1,76 +0,0 @@ -# -*- coding: utf-8 -*- -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -from django.db import models - - -class FunctionController(models.Model): - """功能开关控制器""" - - func_code = models.CharField("功能code", max_length=64, unique=True) - func_name = models.CharField("功能名称", max_length=64) - switch_status = models.BooleanField("是否开启该功能", default=True) - wlist = models.TextField("功能测试白名单", null=True, default="", blank=True) - func_desc = models.TextField("功能描述", null=True, default="", blank=True) - created_time = models.DateTimeField("创建时间", auto_now_add=True) - - class Meta(object): - db_table = "esb_function_controller" - - def __str__(self): - return self.func_code - - -class AppAccount(models.Model): - """应用账号""" - - app_code = models.CharField("应用编码", max_length=30, unique=True) - app_token = models.CharField("应用Token", max_length=128) - introduction = models.TextField("应用简介", default="", blank=True) - created_time = models.DateTimeField("创建时间", auto_now_add=True) - - class Meta(object): - db_table = "esb_app_account" - - def __str__(self): - return self.app_code - - -class ESBAppPermissionApplyRecord(models.Model): - """ - 应用访问组件 API 权限申请记录 - """ - - bk_app_code = models.CharField(db_column="app_code", max_length=32) - system_name = models.CharField(db_column="sys_name", max_length=128) - component_id = models.IntegerField(db_column="api_id") - component_name = models.CharField(db_column="api_name", max_length=128) - status = models.CharField(db_column="approval_result", max_length=32, default="applying") - applied_by = models.CharField(db_column="operator", max_length=32) - applied_time = models.DateTimeField(db_column="create_time", auto_now_add=True, blank=True, null=True) - handled_by = models.CharField(db_column="approver", max_length=32, blank=True, null=True) - handled_time = models.DateTimeField(db_column="approval_time", null=True, blank=True) - - class Meta: - verbose_name = "PaaS2 应用访问组件 API 权限申请记录" - verbose_name_plural = "PaaS2 应用访问组件 API 权限申请记录" - db_table = "paas_app_esb_auth_apply_record" - managed = False - - def __str__(self): - return f"{self.applied_by}({self.bk_app_code})" diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/sync.py b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/sync.py deleted file mode 100644 index 5cc812a06..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/sync.py +++ /dev/null @@ -1,352 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -"""将 PaaS2/ESB 数据迁移至 BK-ESB""" - -import logging -from typing import Any, Dict, List, Optional, Tuple, Union - -from django.db import models -from pydantic import BaseModel - -from apigateway.apps.esb.bkcore.models import ( - AppComponentPermission, - ComponentDoc, - ComponentSystem, - DocCategory, - ESBChannel, - SystemDocCategory, -) -from apigateway.legacy_esb.models import AppComponentPerm as LegacyAppComponentPermission -from apigateway.legacy_esb.models import ComponentAPIDoc as LegacyComponentDoc -from apigateway.legacy_esb.models import ComponentSystem as LegacyComponentSystem -from apigateway.legacy_esb.models import ESBChannel as LegacyESBChannel -from apigateway.legacy_esb.models import LegacyModelMigrator -from apigateway.legacy_esb.models import SystemDocCategory as LegacyDocCategory - -logger = logging.getLogger(__name__) - -_BULK_CREATE_BATCH_SIZE = 50 - - -class BaseSynchronizer: - legacy_model: Optional[models.Model] - ng_model: models.Model - default_display_fields: List[str] - pre_check_fields: List[str] - assert_fields: List[str] - - def sync_legacy_to_ng(self, dry_run: bool, force: bool): - create_ng_objs, update_ng_objs = self._prepare_sync_data(force) - self._save_objs(create_ng_objs, update_ng_objs, dry_run) - - def assert_data(self): - self._assert_count_and_fields() - - def pre_check_data(self) -> Tuple[bool, str]: - """预检数据,如果预检失败,则不能执行数据同步操作""" - legacy_key_to_obj = self._get_legacy_key_to_obj() - ng_key_to_obj = self._get_ng_key_to_obj() - - for l_key, l_obj in legacy_key_to_obj.items(): - ng_obj = ng_key_to_obj.pop(l_key, None) - if not ng_obj: - continue - - different_fields = self._compare_field_value(l_obj, ng_obj, self.pre_check_fields) - if different_fields: - message = "%s[id/key=%s] has different fields, legacy: %s, ng: %s" % ( - self.ng_model.__name__, - l_key, - self._stringify_obj_fields(l_obj, different_fields), - self._stringify_obj_fields(ng_obj, different_fields), - ) - return False, message - - return True, "" - - def _prepare_sync_data(self, force: bool) -> Tuple[List[models.Model], List[models.Model]]: - create_objs = [] - update_objs = [] - - ng_key_to_obj = self._get_ng_key_to_obj() - for l_obj_key, l_obj in self._get_legacy_key_to_obj().items(): - ng_obj = ng_key_to_obj.pop(l_obj_key, None) - if not ng_obj: - ng_obj = l_obj.clone_to_ng_obj() - create_objs.append(ng_obj) - continue - - if force or l_obj.is_changed(ng_obj): - ng_obj = l_obj.update_ng_obj_fields(ng_obj) - update_objs.append(ng_obj) - - return create_objs, update_objs - - def _get_legacy_key_to_obj(self) -> Dict[Union[str, int], LegacyModelMigrator]: - if not self.legacy_model: - raise ValueError("legacy_model can not be empty") - return {obj.id: obj for obj in self.legacy_model.objects.all()} - - def _get_ng_key_to_obj(self) -> Dict[Union[str, int], models.Model]: - return {obj.id: obj for obj in self.ng_model.objects.all()} - - def _save_objs(self, create_objs: List[models.Model], update_objs: List[models.Model], dry_run: bool): - self._create_objs(create_objs, dry_run) - self._update_objs(update_objs, dry_run) - - def _create_objs(self, objs: List[models.Model], dry_run: bool): - if not objs: - return - - if not dry_run: - self.ng_model.objects.bulk_create(objs, batch_size=_BULK_CREATE_BATCH_SIZE) - return - - for obj in objs: - logger.info( - "add %s: %s", - self.ng_model.__name__, - self._stringify_obj_fields(obj, self.default_display_fields), - ) - - def _update_objs(self, objs: List[models.Model], dry_run: bool): - if not objs: - return - - if not dry_run: - for obj in objs: - obj.save() - return - - for obj in objs: - logger.info( - "update %s: %s", - self.ng_model.__name__, - self._stringify_obj_fields(obj, self.default_display_fields), - ) - - def _stringify_obj_fields(self, obj: Any, fields: List[str]) -> str: - return ", ".join([f"{field}={getattr(obj, field)}" for field in fields]) - - def _assert_count_and_fields(self): - legacy_key_to_obj = self._get_legacy_key_to_obj() - ng_key_to_obj = self._get_ng_key_to_obj() - - if len(legacy_key_to_obj) != len(ng_key_to_obj): - logger.error( - "%s count not equal: legacy count=%s, ng count=%s", - self.ng_model.__name__, - len(legacy_key_to_obj), - len(ng_key_to_obj), - ) - - for l_key, l_obj in legacy_key_to_obj.items(): - ng_obj = ng_key_to_obj.pop(l_key, None) - if not ng_obj: - logger.error("ng %s not exist: id/key=%s", self.ng_model.__name__, l_key) - continue - - different_fields = self._compare_field_value(l_obj, ng_obj, self.assert_fields) - if different_fields: - logger.error( - "%s[id/key=%s] has different fields, legacy: %s, ng: %s", - self.ng_model.__name__, - l_key, - self._stringify_obj_fields(l_obj, different_fields), - self._stringify_obj_fields(ng_obj, different_fields), - ) - - def _compare_field_value(self, src_obj: Any, dst_obj: Any, fields: List[str]) -> List[str]: - """对比对象字段值的差异,返回有差异的字段""" - different_fields = [] - for field in fields: - if getattr(src_obj, field) == getattr(dst_obj, field): - continue - different_fields.append(field) - - return different_fields - - -class DocCategorySynchronizer(BaseSynchronizer): - """同步文档分类""" - - legacy_model = LegacyDocCategory - ng_model = DocCategory - default_display_fields = ["id", "name"] - pre_check_fields = ["name"] - assert_fields = ["name"] - - -class ComponentSystemSynchronizer(BaseSynchronizer): - """同步组件系统""" - - legacy_model = LegacyComponentSystem - ng_model = ComponentSystem - default_display_fields = ["id", "name"] - pre_check_fields = ["name"] - assert_fields = ["name", "description", "timeout"] - - -class SystemDocCategorySynchronizer(BaseSynchronizer): - """同步系统-文档分类的对应关系""" - - legacy_model = None - ng_model = SystemDocCategory - default_display_fields = ["id", "system_id", "doc_category_id"] - pre_check_fields: List[str] = [] - assert_fields = ["system_id", "doc_category_id"] - - # 旧版 System 和 DocCategory 对应关系,存储在 ComponentSystem 表中, - # 定义一个新的 Model,与新版 Model 对应 - class LegacySystemDocCategoryInnerMigrator(LegacyModelMigrator, BaseModel): - id: int - system_id: int - doc_category_id: int - - def clone_to_ng_obj(self): - return SystemDocCategory( - id=self.id, - system_id=self.system_id, - doc_category_id=self.doc_category_id, - ) - - def update_ng_obj_fields(self, ng_obj): - ng_obj.__dict__.update( - { - "doc_category_id": self.doc_category_id, - } - ) - return ng_obj - - def is_changed(self, ng_obj): - return self.doc_category_id != ng_obj.doc_category_id - - def _get_legacy_key_to_obj(self) -> Dict[Union[str, int], LegacyModelMigrator]: - legacy_system_id_to_category_id = dict(LegacyComponentSystem.objects.values_list("id", "doc_category_id")) - legacy_category_ids = set(LegacyDocCategory.objects.values_list("id", flat=True)) - - legacy_key_to_obj: Dict[Union[str, int], LegacyModelMigrator] = {} - for l_system_id, l_category_id in legacy_system_id_to_category_id.items(): - if not l_category_id or l_category_id not in legacy_category_ids: - continue - - legacy_key_to_obj[l_system_id] = SystemDocCategorySynchronizer.LegacySystemDocCategoryInnerMigrator( - id=l_system_id, - system_id=l_system_id, - doc_category_id=l_category_id, - ) - - return legacy_key_to_obj - - -class ESBChannelSynchronizer(BaseSynchronizer): - """同步组件""" - - legacy_model = LegacyESBChannel - ng_model = ESBChannel - default_display_fields = ["id", "method", "path"] - pre_check_fields = ["name", "method", "path"] - assert_fields = [ - "name", - "path", - "method", - "system_id", - "component_codename", - "is_active", - "timeout", - "config", - "permission_level", - ] - - def _get_legacy_key_to_obj(self) -> Dict[Union[str, int], LegacyModelMigrator]: - system_id_to_obj = {obj.id: obj for obj in ComponentSystem.objects.all()} - legacy_key_to_obj = {obj.id: obj for obj in LegacyESBChannel.objects.all()} - - for l_obj in legacy_key_to_obj.values(): - l_obj.ng_system = system_id_to_obj.get(l_obj.component_system_id) - - return legacy_key_to_obj - - -class ComponentDocSynchronizer(BaseSynchronizer): - """同步组件文档""" - - legacy_model = LegacyComponentDoc - ng_model = ComponentDoc - default_display_fields = ["component_id", "language", "content_md5"] - pre_check_fields: List[str] = [] - assert_fields = ["component_id", "language", "content_md5"] - - # 旧版组件文档中,一个文档包含了中文、英文两种文档,新版中每个语言有单独一份文档 - # 需对旧版文档拆分,与新版文档一一对应 - class LegacyComponentDocInnerMigrator(LegacyModelMigrator, BaseModel): - component_id: int - language: str - content: str - content_md5: str - - def clone_to_ng_obj(self) -> ComponentDoc: - return ComponentDoc( - component_id=self.component_id, - language=self.language, - content=self.content, - content_md5=self.content_md5, - ) - - def update_ng_obj_fields(self, ng_obj: ComponentDoc) -> ComponentDoc: - ng_obj.__dict__.update( - { - "content": self.content, - "content_md5": self.content_md5, - } - ) - return ng_obj - - def is_changed(self, ng_obj: ComponentDoc) -> bool: - return self.content_md5 != ng_obj.content_md5 - - def _get_legacy_key_to_obj(self) -> Dict[Union[str, int], LegacyModelMigrator]: - legacy_component_ids = set(LegacyESBChannel.objects.values_list("id", flat=True)) - - legacy_key_to_obj: Dict[Union[str, int], models.Model] = {} - for l_doc in LegacyComponentDoc.objects.all(): - # 旧版文档对应的组件不存在 - if l_doc.component_id not in legacy_component_ids: - continue - - for doc in l_doc.split_doc_by_language(): - key = self._generate_doc_key(doc) - legacy_key_to_obj[key] = ComponentDocSynchronizer.LegacyComponentDocInnerMigrator.parse_obj(doc) - - return legacy_key_to_obj - - def _get_ng_key_to_obj(self) -> Dict[Union[str, int], models.Model]: - return {self._generate_doc_key(obj.__dict__): obj for obj in ComponentDoc.objects.all()} - - def _generate_doc_key(self, doc: Dict[str, Any]) -> str: - return f"{doc['component_id']}:{doc['language']}" - - -class AppComponentPermissionSynchronizer(BaseSynchronizer): - """同步组件权限""" - - legacy_model = LegacyAppComponentPermission - ng_model = AppComponentPermission - default_display_fields = ["id", "bk_app_code", "component_id"] - pre_check_fields = ["bk_app_code", "component_id"] - assert_fields = ["bk_app_code", "component_id", "expires"] diff --git a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/tasks.py b/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/tasks.py deleted file mode 100644 index dc11a247e..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/legacy_esb/tasks.py +++ /dev/null @@ -1,135 +0,0 @@ -# -*- coding: utf-8 -*- -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -""" -同步 Legacy ESB 的可复用数据到新版 ESB -此部分数据,可重复同步 -""" - -import logging -import re -from typing import Optional, Tuple - -from celery import shared_task -from django.conf import settings - -from apigateway.apps.esb.bkcore.models import AppAccount, FunctionController -from apigateway.apps.esb.constants import FunctionControllerCodeEnum -from apigateway.legacy_esb.paas2.models import AppAccount as LegacyAppAccount -from apigateway.legacy_esb.paas2.models import FunctionController as LegacyFunctionController - -logger = logging.getLogger(__name__) - - -@shared_task(name="apigateway.legacy_esb.tasks.sync_legacy_esb_reusable_data", ignore_result=True) -def sync_legacy_esb_reusable_data(): - """""" - synchronizer = LegacyESBSynchronizer() - synchronizer.sync(dry_run=False) - - -class LegacyESBSynchronizer: - def sync(self, dry_run: bool): - if not getattr(settings, "BK_PAAS2_ENABLED", False): - logger.warning("paas2 disabled, no need to sync data from it") - return - - # self._sync_legacy_esb_app_account(dry_run) - self._sync_legacy_function_controller(dry_run) - - def _sync_legacy_esb_app_account(self, dry_run: bool): - legacy_app_accounts = {app.app_code: app for app in LegacyAppAccount.objects.all()} - new_app_accounts = {app.app_code: app for app in AppAccount.objects.all()} - - for legacy_app_code, legacy_app in legacy_app_accounts.items(): - new_app = new_app_accounts.get(legacy_app_code) - if new_app and legacy_app.app_token == new_app.app_token: - continue - - if dry_run: - logger.info("create or update app: %s", legacy_app_code) - continue - - AppAccount.objects.update_or_create( - app_code=legacy_app_code, - defaults={ - "app_token": legacy_app.app_token, - "introduction": legacy_app.introduction, - }, - ) - - def _sync_legacy_function_controller(self, dry_run: bool): - self._sync_skip_user_auth(dry_run) - self._sync_jwt_key(dry_run) - - def _sync_skip_user_auth(self, dry_run: bool): - legacy_obj, new_obj, has_diff = self._add_legacy_function_controller_to_new( - FunctionControllerCodeEnum.SKIP_USER_AUTH.value, # type: ignore - dry_run, - ) - - if dry_run or not (legacy_obj and new_obj and has_diff): - return - - delimiter = re.compile(r"[^,;]+") - wlist = set() - wlist.update(delimiter.findall(legacy_obj.wlist)) - wlist.update(delimiter.findall(new_obj.wlist)) - new_obj.wlist = ",".join(sorted(wlist)) - new_obj.save(update_fields=["wlist"]) - - def _sync_jwt_key(self, dry_run: bool): - legacy_obj, new_obj, has_diff = self._add_legacy_function_controller_to_new( - FunctionControllerCodeEnum.JWT_KEY.value, # type: ignore - dry_run, - ) - - if dry_run or not (legacy_obj and new_obj and has_diff): - return - - new_obj.wlist = legacy_obj.wlist - new_obj.save(update_fields=["wlist"]) - - def _add_legacy_function_controller_to_new( - self, - func_code: str, - dry_run: bool, - ) -> Tuple[Optional[LegacyFunctionController], Optional[FunctionController], bool]: - legacy_obj = LegacyFunctionController.objects.filter(func_code=func_code).first() - if not legacy_obj: - return None, None, False - - if dry_run: - new_obj = FunctionController.objects.filter(func_code=legacy_obj.func_code).first() - if not (new_obj and legacy_obj.wlist == new_obj.wlist): - logger.info("create or update function_controller: %s", legacy_obj.func_code) - return legacy_obj, new_obj, True - - new_obj, created = FunctionController.objects.get_or_create( - func_code=legacy_obj.func_code, - defaults={ - "func_name": legacy_obj.func_name, - "func_desc": legacy_obj.func_desc, - "switch_status": legacy_obj.switch_status, - "wlist": legacy_obj.wlist, - }, - ) - if created or legacy_obj.wlist == new_obj.wlist: - return legacy_obj, new_obj, False - - return legacy_obj, new_obj, True diff --git a/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/__init__.pyi b/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/__init__.pyi deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/conftest.py b/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/conftest.py deleted file mode 100644 index 5f83d7b0a..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/conftest.py +++ /dev/null @@ -1,25 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -import uuid - -import pytest - - -@pytest.fixture -def unique_id(): - return uuid.uuid4().hex diff --git a/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/management/__init__.pyi b/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/management/__init__.pyi deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/management/commands/__init__.pyi b/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/management/commands/__init__.pyi deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/test_managers.py b/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/test_managers.py deleted file mode 100644 index 6a3734b1a..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/test_managers.py +++ /dev/null @@ -1,61 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -import pytest -from ddf import G - -from apigateway.legacy_esb import models as legacy_models - -pytestmark = pytest.mark.django_db - - -class TestSystemDocCategory: - @pytest.mark.parametrize( - "mock_values, expected", - [ - (["test", "test1", "test2"], []), - (["test", "test1", "test"], ["test"]), - ], - ) - def test_get_duplicate_names(self, mocker, mock_values, expected): - mocker.patch( - "apigateway.legacy_esb.managers.SystemDocCategoryManager.values_list", - return_value=mock_values, - ) - result = legacy_models.SystemDocCategory.objects.get_duplicate_names() - assert result == expected - - def test_delete_duplicate_names(self, mocker, unique_id): - category1 = G(legacy_models.SystemDocCategory, name=unique_id) - category2 = G(legacy_models.SystemDocCategory, name=unique_id) - system1 = G(legacy_models.ComponentSystem, doc_category_id=category1.id) - system2 = G(legacy_models.ComponentSystem, doc_category_id=category2.id) - system3 = G(legacy_models.ComponentSystem, doc_category_id=category2.id) - - mocker.patch( - "apigateway.legacy_esb.managers.SystemDocCategoryManager.get_duplicate_names", - return_value=[unique_id], - ) - - legacy_models.SystemDocCategory.objects.delete_duplicate_names() - - assert legacy_models.ComponentSystem.objects.get(id=system1.id).doc_category_id == category1.id - assert legacy_models.ComponentSystem.objects.get(id=system2.id).doc_category_id == category1.id - assert legacy_models.ComponentSystem.objects.get(id=system3.id).doc_category_id == category1.id - - assert legacy_models.SystemDocCategory.objects.filter(id=category1.id).exists() is True - assert legacy_models.SystemDocCategory.objects.filter(id=category2.id).exists() is False diff --git a/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/test_models.py b/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/test_models.py deleted file mode 100644 index 8bb9374eb..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/test_models.py +++ /dev/null @@ -1,512 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -import datetime -import json -import operator -from unittest import mock - -import pytest -from ddf import G -from pydantic import BaseModel - -from apigateway.apps.esb.bkcore import models -from apigateway.legacy_esb import models as legacy_models - -pytestmark = pytest.mark.django_db - - -class TestLegacyModelMigrator: - class LegacyModel(BaseModel): - id: int - name: str - description: str - - class NGModel(BaseModel): - id: int - name: str - description: str - - @pytest.mark.parametrize( - "src, dst, expected", - [ - ( - {"id": 1, "name": "fake-name", "description": "test"}, - {"id": 1, "name": "fake-name", "description": "test"}, - False, - ), - ( - {"id": 1, "name": "name", "description": "test"}, - {"id": 1, "name": "other-name", "description": "test"}, - True, - ), - ], - ) - def test_has_different_field_value(self, src, dst, expected): - result = legacy_models.LegacyModelMigrator().has_different_field_value( - TestLegacyModelMigrator.LegacyModel.parse_obj(src), - TestLegacyModelMigrator.NGModel.parse_obj(dst), - ["id", "name", "description"], - ) - assert result is expected - - -def test_convert_is_official_to_data_type(): - assert legacy_models._convert_is_official_to_data_type(True) == 1 - assert legacy_models._convert_is_official_to_data_type(False) == 3 - - -class TestComponentSystem: - @pytest.fixture - def fake_legacy_system(self, faker, unique_id): - return G( - legacy_models.ComponentSystem, - name=unique_id, - description=faker.word(), - component_admin="admin1", - interface_admin="admin2", - comment=faker.text(), - execute_timeout=30, - query_timeout=10, - ) - - def test_clone_to_ng_obj(self, fake_legacy_system): - expected = models.ComponentSystem( - id=fake_legacy_system.id, - name=fake_legacy_system.name, - description=fake_legacy_system.description, - comment=fake_legacy_system.comment, - timeout=30, - data_type=3, - _maintainers="admin1;admin2", - ) - - assert fake_legacy_system.clone_to_ng_obj() == expected - - def test_update_ng_obj_fields(self, fake_legacy_system): - ng_obj = G(models.ComponentSystem, id=fake_legacy_system.id, name=fake_legacy_system.name) - expected = models.ComponentSystem( - id=fake_legacy_system.id, - name=fake_legacy_system.name, - description=fake_legacy_system.description, - comment=fake_legacy_system.comment, - timeout=30, - data_type=3, - _maintainers="admin1;admin2", - ) - - result = fake_legacy_system.update_ng_obj_fields(ng_obj) - assert result == expected - - def test_is_changed(self, fake_legacy_system): - ng_obj = models.ComponentSystem( - id=fake_legacy_system.id, - name=fake_legacy_system.name, - description=fake_legacy_system.description, - comment=fake_legacy_system.comment, - timeout=30, - data_type=3, - _maintainers="admin1;admin2", - ) - assert fake_legacy_system.is_changed(ng_obj) is False - - ng_obj = models.ComponentSystem( - id=fake_legacy_system.id, - name=fake_legacy_system.name, - description=fake_legacy_system.description, - comment=fake_legacy_system.comment, - timeout=10, - data_type=3, - _maintainers="admin1;admin2", - ) - assert fake_legacy_system.is_changed(ng_obj) is True - - def test_is_official(self, fake_legacy_system): - assert fake_legacy_system.is_official is False - - def test_data_type(self, fake_legacy_system): - assert fake_legacy_system.data_type == 3 - - @pytest.mark.parametrize( - "query_timeout, execute_timeout, expected", - [ - (None, None, None), - (None, 10, None), - (10, None, None), - (10, 30, 30), - (30, 10, 30), - (0, 10, None), - ], - ) - def test_timeout(self, fake_legacy_system, query_timeout, execute_timeout, expected): - fake_legacy_system.query_timeout = query_timeout - fake_legacy_system.execute_timeout = execute_timeout - - assert fake_legacy_system.timeout == expected - - @pytest.mark.parametrize( - "component_admin, interface_admin, expected", - [ - ("admin1", "admin2", ["admin1", "admin2"]), - ("admin1;admin2", "", ["admin1", "admin2"]), - ("admin1", "admin1", ["admin1"]), - ("admin2", "admin1", ["admin2", "admin1"]), - ], - ) - def test_maintainers(self, fake_legacy_system, component_admin, interface_admin, expected): - fake_legacy_system.component_admin = component_admin - fake_legacy_system.interface_admin = interface_admin - - assert fake_legacy_system.maintainers == expected - - -class TestESBChannel: - @pytest.fixture - def fake_legacy_system(self): - return G(legacy_models.ComponentSystem) - - @pytest.fixture - def fake_ng_system(self, fake_legacy_system): - return fake_legacy_system.clone_to_ng_obj() - - @pytest.fixture - def fake_legacy_channel(self, faker, unique_id, fake_legacy_system, fake_ng_system): - legacy_channel = G( - legacy_models.ESBChannel, - description=faker.sentence(), - path=f"/{unique_id}/", - method="GET", - component_system=fake_legacy_system, - component_codename=faker.sentence(), - name=faker.word(), - is_active=True, - timeout=30, - comp_conf='{"a": "b"}', - perm_level=1, - is_hidden=False, - ) - legacy_channel.ng_system = fake_ng_system - return legacy_channel - - def test_clone_to_ng_obj(self, fake_legacy_channel): - expected = models.ESBChannel( - id=fake_legacy_channel.id, - system=fake_legacy_channel.ng_system, - method=fake_legacy_channel.method, - path=fake_legacy_channel.path, - name=fake_legacy_channel.name, - description=fake_legacy_channel.description, - component_codename=fake_legacy_channel.component_codename, - permission_level="normal", - timeout=30, - config={"a": "b"}, - is_active=True, - is_public=True, - data_type=fake_legacy_channel.ng_system.data_type, - ) - assert fake_legacy_channel.clone_to_ng_obj() == expected - - def test_update_ng_obj_fields(self, fake_legacy_channel): - expected = models.ESBChannel( - id=fake_legacy_channel.id, - system=fake_legacy_channel.ng_system, - method=fake_legacy_channel.method, - path=fake_legacy_channel.path, - name=fake_legacy_channel.name, - description=fake_legacy_channel.description, - component_codename=fake_legacy_channel.component_codename, - permission_level="normal", - timeout=30, - config={"a": "b"}, - is_active=True, - is_public=True, - data_type=fake_legacy_channel.ng_system.data_type, - ) - - ng_obj = models.ESBChannel(id=fake_legacy_channel.id) - result = fake_legacy_channel.update_ng_obj_fields(ng_obj) - assert result == expected - - def test_is_changed(self, fake_legacy_channel): - ng_obj = fake_legacy_channel.clone_to_ng_obj() - assert fake_legacy_channel.is_changed(ng_obj) is False - - ng_obj.__dict__.update( - { - "method": "POST", - } - ) - assert fake_legacy_channel.is_changed(ng_obj) is True - - @pytest.mark.parametrize( - "perm_level, expected", - [ - (0, "unlimited"), - (1, "normal"), - (2, "sensitive"), - (3, "special"), - ], - ) - def test_permission_level(self, fake_legacy_channel, perm_level, expected): - fake_legacy_channel.perm_level = perm_level - assert fake_legacy_channel.permission_level == expected - - @pytest.mark.parametrize( - "comp_conf, expected", - [ - (None, {}), - ("", {}), - ('{"a": "b"}', {"a": "b"}), - ('[["a", "b"]]', {"a": "b"}), - ], - ) - def test_config(self, fake_legacy_channel, comp_conf, expected): - fake_legacy_channel.comp_conf = comp_conf - assert fake_legacy_channel.config == expected - - -class TestESBBuffetComponent: - @pytest.fixture - def fake_buffet_component(self): - return G( - legacy_models.ESBBuffetComponent, - description="test", - dest_url="http://1.1.1.1/echo/", - dest_http_method="POST", - favor_post_ctype="json", - extra_headers=json.dumps({"a": "b"}), - registed_path="/echo/", - registed_http_method="POST", - timeout_time=30, - ) - - @pytest.mark.parametrize( - "method, path, expected", - [ - ("GET", "/echo/", "get_echo"), - ("POST", "/echo/", "post_echo"), - ("get", "/echo/234/test/", "get_echo_234_test"), - ("get", "/echo/{username}/test", "get_echo_username_test"), - ], - ) - def test_name(self, fake_buffet_component, method, path, expected): - fake_buffet_component.registed_http_method = method - fake_buffet_component.registed_path = path - assert fake_buffet_component._name == expected - - @pytest.mark.parametrize( - "system_timeout, buffet_timeout, expected", - [ - (None, 10, 600), - (None, None, 600), - (10, 20, 20), - (30, 10, 30), - (30, None, 600), - ], - ) - def test_timeout(self, mocker, fake_buffet_component, system_timeout, buffet_timeout, expected): - fake_buffet_component.system = G( - legacy_models.ComponentSystem, query_timeout=system_timeout, execute_timeout=system_timeout - ) - fake_buffet_component.timeout_time = buffet_timeout - - assert fake_buffet_component._timeout == expected - - @pytest.mark.parametrize( - "method, expected", - [ - ("GET", "GET"), - ("POST", "POST"), - ("_ORIG", "ANY"), - ], - ) - def test_convert_method(self, fake_buffet_component, method, expected): - assert fake_buffet_component._convert_method(method) == expected - - @pytest.mark.parametrize( - "dest_url, expected", - [ - ("http://1.1.1.1/", "http://1.1.1.1"), - ("https://1.1.1.1/", "https://1.1.1.1"), - ("http://1.1.1.1/echo/test", "http://1.1.1.1"), - ], - ) - def test_backend_host(self, fake_buffet_component, dest_url, expected): - fake_buffet_component.dest_url = dest_url - assert fake_buffet_component._backend_host == expected - - @pytest.mark.parametrize( - "dest_url, expected", - [ - ("http://1.1.1.1/echo", "/echo"), - ("https://1.1.1.1/echo/{username}", "/echo/{username}"), - ], - ) - def test_backend_path(self, fake_buffet_component, dest_url, expected): - fake_buffet_component.dest_url = dest_url - assert fake_buffet_component._backend_path == expected - - @pytest.mark.parametrize( - "dest_http_method, mock_extra_headers, favor_post_ctype, expected", - [ - ("GET", {"A": "b"}, "json", {"A": "b"}), - ("POST", {"A": "b", "Content-Type": "test"}, "json", {"A": "b", "Content-Type": "test"}), - ("POST", {"A": "b", "content-type": "test"}, "json", {"A": "b", "content-type": "test"}), - ("POST", {"A": "b"}, "json", {"A": "b", "Content-Type": "application/json"}), - ("POST", {"A": "b"}, "form", {"A": "b", "Content-Type": "application/x-www-form-urlencoded"}), - ], - ) - def test_enrich_extra_headers( - self, mocker, fake_buffet_component, dest_http_method, mock_extra_headers, favor_post_ctype, expected - ): - mocker.patch( - "apigateway.legacy_esb.models.ESBBuffetComponent._canonical_extra_headers", - new_callable=mock.PropertyMock(return_value=mock_extra_headers), - ) - fake_buffet_component.dest_http_method = dest_http_method - fake_buffet_component.favor_post_ctype = favor_post_ctype - - assert fake_buffet_component._enrich_extra_headers() == expected - - @pytest.mark.parametrize( - "extra_headers, expected", - [ - (None, {}), - ("", {}), - (json.dumps({"a": "b"}), {"a": "b"}), - (json.dumps({"a-345": "b"}), {"a-345": "b"}), - (json.dumps({"content_type": "application/json"}), {"content-type": "application/json"}), - (json.dumps({"content-type": "application/json"}), {"content-type": "application/json"}), - (json.dumps({"Content-Type": "application/json"}), {"Content-Type": "application/json"}), - (json.dumps({"Content_Type": "application/json"}), {"Content-Type": "application/json"}), - ], - ) - def test_canonical_extra_headers(self, fake_buffet_component, extra_headers, expected): - fake_buffet_component.extra_headers = extra_headers - assert fake_buffet_component._canonical_extra_headers == expected - - -class TestComponentAPIDoc: - @pytest.fixture - def fake_legacy_doc(self, faker, unique_id): - channel = G(legacy_models.ESBChannel, path=f"/{unique_id}/") - return G( - legacy_models.ComponentAPIDoc, - component_id=channel.id, - doc_md=json.dumps( - { - "zh-hans": "中文文档", - "en": "english document", - } - ), - ) - - def test_split_doc_by_language(self, fake_legacy_doc): - result = fake_legacy_doc.split_doc_by_language() - assert sorted(result, key=operator.itemgetter("language")) == [ - { - "component_id": fake_legacy_doc.component_id, - "language": "en", - "content": "english document", - "content_md5": "378807031f9afc4a23b176d617af2a81", - }, - { - "component_id": fake_legacy_doc.component_id, - "language": "zh-hans", - "content": "中文文档", - "content_md5": "f6d3aaa4e3aa9cf7674f8a2331190d64", - }, - ] - - -class TestAppComponentPerm: - @pytest.fixture - def fake_legacy_permission(self, faker, unique_id): - return G( - legacy_models.AppComponentPerm, - bk_app_code=unique_id, - component_id=faker.pyint(), - ) - - def test_clone_to_ng_obj(self, fake_legacy_permission): - assert fake_legacy_permission.clone_to_ng_obj() == models.AppComponentPermission( - id=fake_legacy_permission.id, - bk_app_code=fake_legacy_permission.bk_app_code, - component_id=fake_legacy_permission.component_id, - expires=fake_legacy_permission.expires, - ) - - def test_update_ng_obj_fields(self, fake_legacy_permission): - ng_permission = models.AppComponentPermission(id=fake_legacy_permission.id) - result = fake_legacy_permission.update_ng_obj_fields(ng_permission) - assert result == models.AppComponentPermission( - id=fake_legacy_permission.id, - bk_app_code=fake_legacy_permission.bk_app_code, - component_id=fake_legacy_permission.component_id, - expires=fake_legacy_permission.expires, - ) - - def test_is_changed(self, fake_legacy_permission): - ng_obj = fake_legacy_permission.clone_to_ng_obj() - assert fake_legacy_permission.is_changed(ng_obj) is False - - ng_obj.__dict__.update( - { - "expires": datetime.datetime.now(), - } - ) - assert fake_legacy_permission.is_changed(ng_obj) is True - - -class TestDocCategory: - @pytest.fixture - def fake_category(self, faker, unique_id): - return G(legacy_models.SystemDocCategory, name=unique_id) - - def test_is_official(self, fake_category): - assert fake_category.is_official is False - - fake_category.name = "默认分类" - assert fake_category.is_official is True - - def test_clone_to_ng_obj(self, fake_category): - assert fake_category.clone_to_ng_obj() == models.DocCategory( - id=fake_category.id, - name=fake_category.name, - priority=fake_category._ng_priority, - data_type=3, - ) - - def test_update_ng_obj_fields(self, fake_category): - ng_category = models.DocCategory(id=fake_category.id) - result = fake_category.update_ng_obj_fields(ng_category) - assert result == models.DocCategory( - id=fake_category.id, - name=fake_category.name, - priority=fake_category._ng_priority, - data_type=3, - ) - - def test_is_changed(self, fake_category): - ng_category = fake_category.clone_to_ng_obj() - assert fake_category.is_changed(ng_category) is False - - ng_category.name = "test" - assert fake_category.is_changed(ng_category) is True - - def test_data_type(self, fake_category): - assert fake_category.data_type == 3 diff --git a/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/test_sync.py b/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/test_sync.py deleted file mode 100644 index 4af14839d..000000000 --- a/src/dashboard/apigateway/apigateway/editions/ee/tests/legacy_esb/test_sync.py +++ /dev/null @@ -1,339 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -import json - -import pytest -from ddf import G -from pydantic import BaseModel - -from apigateway.apps.esb.bkcore import models -from apigateway.legacy_esb import models as legacy_models -from apigateway.legacy_esb import sync - -pytestmark = pytest.mark.django_db - - -class TestDocCategorySynchronizer: - @pytest.mark.parametrize( - "mock_legacy_key_to_obj, mock_ng_key_to_obj, expected", - [ - ( - { - 1: legacy_models.SystemDocCategory(id=1, name="test"), - 2: legacy_models.SystemDocCategory(id=2, name="test"), - }, - { - 1: models.DocCategory(id=1, name="test"), - }, - True, - ), - ( - { - 1: legacy_models.SystemDocCategory(id=1, name="test"), - }, - { - 1: models.DocCategory(id=1, name="test-new"), - }, - False, - ), - ], - ) - def test_pre_check_data(self, mocker, mock_legacy_key_to_obj, mock_ng_key_to_obj, expected): - mocker.patch( - "apigateway.legacy_esb.sync.DocCategorySynchronizer._get_legacy_key_to_obj", - return_value=mock_legacy_key_to_obj, - ) - mocker.patch( - "apigateway.legacy_esb.sync.DocCategorySynchronizer._get_ng_key_to_obj", - return_value=mock_ng_key_to_obj, - ) - - synchronizer = sync.DocCategorySynchronizer() - result, _ = synchronizer.pre_check_data() - assert result is expected - - def test_prepare_sync_data(self, mocker): - legacy_category1 = G(legacy_models.SystemDocCategory) - legacy_category2 = G(legacy_models.SystemDocCategory) - mocker.patch( - "apigateway.legacy_esb.sync.DocCategorySynchronizer._get_legacy_key_to_obj", - return_value={ - legacy_category1.id: legacy_category1, - legacy_category2.id: legacy_category2, - }, - ) - - ng_category = models.DocCategory(id=legacy_category1.id) - mocker.patch( - "apigateway.legacy_esb.sync.DocCategorySynchronizer._get_ng_key_to_obj", - return_value={ - legacy_category1.id: ng_category, - }, - ) - - create_objs, update_objs = sync.DocCategorySynchronizer()._prepare_sync_data(True) - assert len(create_objs) == 1 - assert len(update_objs) == 1 - assert create_objs[0].id == legacy_category2.id - assert update_objs[0].id == legacy_category1.id - - def test_get_legacy_key_to_obj(self, mocker): - legacy_category = G(legacy_models.SystemDocCategory) - mocker.patch("apigateway.legacy_esb.sync.LegacyDocCategory.objects.all", return_value=[legacy_category]) - result = sync.DocCategorySynchronizer()._get_legacy_key_to_obj() - assert result == {legacy_category.id: legacy_category} - - def test_get_ng_key_to_obj(self, mocker, unique_id): - ng_category = G(models.DocCategory, name=unique_id) - mocker.patch( - "apigateway.legacy_esb.sync.DocCategory.objects.all", - return_value=[ng_category], - ) - result = sync.DocCategorySynchronizer()._get_ng_key_to_obj() - assert result == {ng_category.id: ng_category} - - def test_create_objs(self, unique_id): - synchronizer = sync.DocCategorySynchronizer() - assert synchronizer._create_objs([], dry_run=False) is None - - ng_categories = [models.DocCategory(name=unique_id)] - assert synchronizer._create_objs(ng_categories, dry_run=True) is None - assert models.DocCategory.objects.filter(name=unique_id).exists() is False - - assert synchronizer._create_objs(ng_categories, dry_run=False) is None - assert models.DocCategory.objects.filter(name=unique_id).exists() is True - - def test_update_objs(self, unique_id): - ng_categories = [G(models.DocCategory, name=unique_id)] - synchronizer = sync.DocCategorySynchronizer() - - assert synchronizer._update_objs([], dry_run=False) is None - - assert synchronizer._update_objs(ng_categories, dry_run=True) is None - assert models.DocCategory.objects.filter(name=unique_id).exists() is True - - assert synchronizer._update_objs(ng_categories, dry_run=False) is None - assert models.DocCategory.objects.filter(name=unique_id).exists() is True - - def test_stringify_obj_fields(self): - synchronizer = sync.DocCategorySynchronizer() - - category = models.DocCategory(id=1, name="test") - assert synchronizer._stringify_obj_fields(category, ["id", "name"]) == "id=1, name=test" - - def test_assert_count_and_fields(self, mocker): - legacy_category = legacy_models.SystemDocCategory(id=1, name="test") - ng_category = models.DocCategory(id=1, name="test2") - - mocker.patch( - "apigateway.legacy_esb.sync.DocCategorySynchronizer._get_legacy_key_to_obj", - return_value={legacy_category.id: legacy_category}, - ) - mocker.patch( - "apigateway.legacy_esb.sync.DocCategorySynchronizer._get_ng_key_to_obj", - return_value={ng_category.id: ng_category}, - ) - - synchronizer = sync.DocCategorySynchronizer() - assert synchronizer._assert_count_and_fields() is None - - @pytest.mark.parametrize( - "src_obj, dst_obj, fields, expected", - [ - ( - {"name": "n1", "address": "a1"}, - {"name": "n1", "address": "a1"}, - ["name", "address"], - [], - ), - ( - {"name": "n1", "address": "a1"}, - {"name": "n2", "address": "a2"}, - ["name", "address"], - ["name", "address"], - ), - ( - {"name": "n1", "address": "a1"}, - {"name": "n2", "address": "a2"}, - ["name"], - ["name"], - ), - ], - ) - def test_compare_field_value(self, src_obj, dst_obj, fields, expected): - class Company(BaseModel): - name: str = "" - address: str = "" - - synchronizer = sync.DocCategorySynchronizer() - assert synchronizer._compare_field_value(Company(**src_obj), Company(**dst_obj), fields) == expected - - -class TestSystemDocCategorySynchronizer: - @pytest.fixture - def fake_legacy_system_doc_category(self, faker, unique_id): - return sync.SystemDocCategorySynchronizer.LegacySystemDocCategoryInnerMigrator( - id=1, - system_id=1, - doc_category_id=1, - ) - - def test_clone_to_ng_obj(self, fake_legacy_system_doc_category): - assert fake_legacy_system_doc_category.clone_to_ng_obj() == models.SystemDocCategory( - id=fake_legacy_system_doc_category.id, - system_id=fake_legacy_system_doc_category.system_id, - doc_category_id=fake_legacy_system_doc_category.doc_category_id, - ) - - def test_update_ng_obj_fields(self, fake_legacy_system_doc_category): - ng_system_doc_category = models.SystemDocCategory(id=1) - result = fake_legacy_system_doc_category.update_ng_obj_fields(ng_system_doc_category) - assert result == models.SystemDocCategory( - id=fake_legacy_system_doc_category.id, - system_id=fake_legacy_system_doc_category.system_id, - doc_category_id=fake_legacy_system_doc_category.doc_category_id, - ) - - def test_is_changed(self, fake_legacy_system_doc_category): - ng_obj = fake_legacy_system_doc_category.clone_to_ng_obj() - assert fake_legacy_system_doc_category.is_changed(ng_obj) is False - - ng_obj.__dict__.update( - { - "doc_category_id": 2, - } - ) - assert fake_legacy_system_doc_category.is_changed(ng_obj) is True - - def test_get_legacy_key_to_obj(self, mocker): - mocker.patch( - "apigateway.legacy_esb.sync.LegacyComponentSystem.objects.values_list", - return_value={1: 2}, - ) - mocker.patch( - "apigateway.legacy_esb.sync.LegacyDocCategory.objects.values_list", - return_value=[2], - ) - - synchronizer = sync.SystemDocCategorySynchronizer() - assert synchronizer._get_legacy_key_to_obj() == { - 1: sync.SystemDocCategorySynchronizer.LegacySystemDocCategoryInnerMigrator( - id=1, - system_id=1, - doc_category_id=2, - ) - } - - -class TestESBChannelSynchronizer: - def test_get_legacy_key_to_obj(self, mocker, unique_id): - legacy_system = G(legacy_models.ComponentSystem) - ng_system = models.ComponentSystem(id=legacy_system.id) - legacy_channel = G(legacy_models.ESBChannel, component_system=legacy_system, path=unique_id) - - mocker.patch("apigateway.legacy_esb.sync.ComponentSystem.objects.all", return_value=[ng_system]) - mocker.patch("apigateway.legacy_esb.sync.LegacyESBChannel.objects.all", return_value=[legacy_channel]) - - synchronizer = sync.ESBChannelSynchronizer() - assert synchronizer._get_legacy_key_to_obj()[legacy_channel.id].ng_system == ng_system - - -class ComponentDocSynchronizer: - @pytest.fixture - def fake_component_doc(self, faker, unique_id): - return sync.ComponentDocSynchronizer.LegacyComponentDocInnerMigrator( - component_id=1, - language="en", - content="test", - content_md5="a1e9bdcb475b92b59261b145f881015e", - ) - - def test_clone_to_ng_obj(self, fake_component_doc): - assert fake_component_doc.clone_to_ng_obj() == models.ComponentDoc( - component_id=fake_component_doc.component_id, - language=fake_component_doc.language, - content=fake_component_doc.content, - content_md5=fake_component_doc.content_md5, - ) - - def test_update_ng_obj_fields(self, fake_component_doc): - ng_component_doc = models.ComponentDoc(component_id=1) - result = fake_component_doc.update_ng_obj_fields(ng_component_doc) - assert result == models.ComponentDoc( - component_id=fake_component_doc.component_id, - language=fake_component_doc.language, - content=fake_component_doc.content, - content_md5=fake_component_doc.content_md5, - ) - - def test_is_changed(self, fake_component_doc): - ng_obj = fake_component_doc.clone_to_ng_obj() - assert fake_component_doc.is_changed(ng_obj) is False - - ng_obj.__dict__.update( - { - "content_md5": "test", - } - ) - assert fake_component_doc.is_changed(ng_obj) is True - - def test_get_legacy_key_to_obj(self, mocker, unique_id): - legacy_channel = G(legacy_models.ESBChannel, path=unique_id) - legacy_doc = G( - legacy_models.ComponentAPIDoc, - component_id=legacy_channel.id, - doc_md=json.dumps( - { - "zh-hans": "中文文档", - "en": "english document", - } - ), - ) - - mocker.patch( - "apigateway.legacy_esb.sync.LegacyESBChannel.objects.values_list", - return_value=[legacy_channel.id], - ) - mocker.patch("apigateway.legacy_esb.sync.LegacyComponentDoc.objects.all", return_value=[legacy_doc]) - - synchronizer = sync.ComponentDocSynchronizer() - assert synchronizer._get_legacy_key_to_obj() == { - f"{legacy_channel.id}:en": sync.ComponentDocSynchronizer.LegacyComponentDocInnerMigrator( - component_id=legacy_channel.id, - language="en", - content="english document", - content_md5="378807031f9afc4a23b176d617af2a81", - ), - f"{legacy_channel.id}:zh-hans": sync.ComponentDocSynchronizer.LegacyComponentDocInnerMigrator( - component_id=legacy_channel.id, - language="zh-hans", - content="中文文档", - content_md5="f6d3aaa4e3aa9cf7674f8a2331190d64", - ), - } - - def test_get_ng_key_to_obj(self, mocker): - ng_doc = models.ComponentDoc(component_id=1, language="en") - mocker.patch( - "apigateway.legacy_esb.sync.ComponentDocSynchronizer.ComponentDoc.objects.all", return_value=[ng_doc] - ) - - synchronizer = sync.ComponentDocSynchronizer() - assert synchronizer._get_ng_key_to_obj() == { - "1:en": ng_doc, - } diff --git a/src/dashboard/apigateway/apigateway/legacy_esb/__init__.py b/src/dashboard/apigateway/apigateway/legacy_esb/__init__.py deleted file mode 100644 index 2941673fe..000000000 --- a/src/dashboard/apigateway/apigateway/legacy_esb/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# diff --git a/src/dashboard/apigateway/apigateway/legacy_esb/management/__init__.py b/src/dashboard/apigateway/apigateway/legacy_esb/management/__init__.py deleted file mode 100644 index 2941673fe..000000000 --- a/src/dashboard/apigateway/apigateway/legacy_esb/management/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# diff --git a/src/dashboard/apigateway/apigateway/legacy_esb/management/commands/__init__.py b/src/dashboard/apigateway/apigateway/legacy_esb/management/commands/__init__.py deleted file mode 100644 index 2941673fe..000000000 --- a/src/dashboard/apigateway/apigateway/legacy_esb/management/commands/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# diff --git a/src/dashboard/apigateway/apigateway/legacy_esb/paas2/__init__.py b/src/dashboard/apigateway/apigateway/legacy_esb/paas2/__init__.py deleted file mode 100644 index 2941673fe..000000000 --- a/src/dashboard/apigateway/apigateway/legacy_esb/paas2/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# diff --git a/src/dashboard/apigateway/apigateway/legacy_esb/paas2/apps.py b/src/dashboard/apigateway/apigateway/legacy_esb/paas2/apps.py deleted file mode 100644 index afc879ef0..000000000 --- a/src/dashboard/apigateway/apigateway/legacy_esb/paas2/apps.py +++ /dev/null @@ -1,22 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# -from django.apps import AppConfig - - -class Paas2Config(AppConfig): - name = "apigateway.legacy_esb.paas2" diff --git a/src/dashboard/apigateway/apigateway/tests/legacy_esb/__init__.py b/src/dashboard/apigateway/apigateway/tests/legacy_esb/__init__.py deleted file mode 100644 index 2941673fe..000000000 --- a/src/dashboard/apigateway/apigateway/tests/legacy_esb/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# diff --git a/src/dashboard/apigateway/apigateway/tests/legacy_esb/management/__init__.py b/src/dashboard/apigateway/apigateway/tests/legacy_esb/management/__init__.py deleted file mode 100644 index 2941673fe..000000000 --- a/src/dashboard/apigateway/apigateway/tests/legacy_esb/management/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# diff --git a/src/dashboard/apigateway/apigateway/tests/legacy_esb/management/commands/__init__.py b/src/dashboard/apigateway/apigateway/tests/legacy_esb/management/commands/__init__.py deleted file mode 100644 index 2941673fe..000000000 --- a/src/dashboard/apigateway/apigateway/tests/legacy_esb/management/commands/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# diff --git a/src/dashboard/apigateway/apigateway/utils/db_router.py b/src/dashboard/apigateway/apigateway/utils/db_router.py index 538f051ea..d1e220b98 100644 --- a/src/dashboard/apigateway/apigateway/utils/db_router.py +++ b/src/dashboard/apigateway/apigateway/utils/db_router.py @@ -25,9 +25,7 @@ class DBRouter: APP_LABEL_TO_DB = { "bkcore": "bkcore", - "paas2": "paas2", "apigateway": "legacy", - "legacy_esb": "paas2", } def db_for_read(self, model, **hints): diff --git a/src/dashboard/bin/post_migrate b/src/dashboard/bin/post_migrate index c4206d85a..ffe1fdd6d 100755 --- a/src/dashboard/bin/post_migrate +++ b/src/dashboard/bin/post_migrate @@ -51,13 +51,6 @@ sync_bk_esb() { echo "API gateway bk-esb sync definition end" } -sync_bk_esb_buffet() { - # sync gateway bk-esb-buffet - echo "API gateway bk-esb-buffet sync definition start ..." - python manage.py sync_apigw_config --api-name=bk-esb-buffet --host=${DASHBOARD_INNER_URL}/backend --file="${APIGW_DEFINITIONS_DIR}/bk-esb-buffet-definition.yaml" - echo "API gateway bk-esb-buffet sync definition end ..." -} - sync_bk_default() { # sync gateway bk-default echo "API gateway ${DEFAULT_MICRO_GATEWAY_API_NAME} sync definition start ..." @@ -73,7 +66,6 @@ sync_bk_default() { sync_bk_default sync_bk_apigateway sync_bk_esb -sync_bk_esb_buffet sync_bk_apigateway_inner diff --git a/src/esb/esb/conf/default.py b/src/esb/esb/conf/default.py index 1873bdbba..bd971cd9b 100644 --- a/src/esb/esb/conf/default.py +++ b/src/esb/esb/conf/default.py @@ -47,7 +47,6 @@ "django.contrib.staticfiles", "esb", "esb.bkcore", - "esb.paas2", "django_prometheus", ) @@ -99,8 +98,6 @@ ] -DATABASE_ROUTERS = ["esb.utils.db_router.DBRouter"] - # mysql pool options DJ_POOL_OPTIONS = {"pool_size": 10, "max_overflow": 100, "recycle": 600} @@ -159,25 +156,8 @@ def _(s): "utf8_general_ci", ), }, - "paas2": { - "ENGINE": env.str("BK_PAAS2_DATABASE_ENGINE", "django.db.backends.mysql"), - "NAME": env.str("BK_PAAS2_DATABASE_NAME", "open_paas"), - "USER": env.str("BK_PAAS2_DATABASE_USER", ""), - "PASSWORD": env.str("BK_PAAS2_DATABASE_PASSWORD", ""), - "HOST": env.str("BK_PAAS2_DATABASE_HOST", ""), - "PORT": env.int("BK_PAAS2_DATABASE_PORT", 3306), - "TEST_CHARSET": env.str("DATABASE_TEST_CHARSET", "utf8"), - "TEST_COLLATION": env.str( - "DATABASE_TEST_COLLATION", - "utf8_general_ci", - ), - }, } -BK_PAAS2_ENABLED = all([DATABASES["paas2"]["NAME"], DATABASES["paas2"]["USER"], DATABASES["paas2"]["HOST"]]) -# 如果 paas2 database 未配置,则去除 -if not BK_PAAS2_ENABLED: - DATABASES.pop("paas2", None) # log 配置 LOG_DIR = env.str("BK_ESB_LOG_PATH", "") diff --git a/src/esb/esb/conf/unittest_env b/src/esb/esb/conf/unittest_env index 0caae1925..604f69cc8 100644 --- a/src/esb/esb/conf/unittest_env +++ b/src/esb/esb/conf/unittest_env @@ -1,5 +1,4 @@ unset BK_ESB_DATABASE_PASSWORD -unset BK_PAAS2_DATABASE_PASSWORD export BKPAAS_ENVIRONMENT="dev" export BK_APP_CODE="bk_apigateway" @@ -9,5 +8,3 @@ export SECRET_KEY="H4lkkFMyTT/Aymft8Z96YLHX4E24DK3LB74tQXiztms3vOdTCXcHcJYiV2btc export ESB_TOKEN="H4lkkFMyTT/Aymft8Z96YLHX4E24DK3LB74tQXiztms3vOdTCXcHcJYiV2btc2PuOzG4Pk5ERn9H8tehpJFB3Q==" export BK_ESB_DATABASE_ENGINE="django.db.backends.sqlite3" export BK_ESB_DATABASE_NAME="esb_unittest.sqlite3" -export BK_PAAS2_DATABASE_ENGINE="django.db.backends.sqlite3" -export BK_PAAS2_DATABASE_NAME="paas2_unittest.sqlite3" diff --git a/src/esb/esb/esb/bkapp/helpers.py b/src/esb/esb/esb/bkapp/helpers.py index 6369fb759..244c6d1b4 100644 --- a/src/esb/esb/esb/bkapp/helpers.py +++ b/src/esb/esb/esb/bkapp/helpers.py @@ -22,7 +22,6 @@ from django.conf import settings from esb.bkcore.models import AppAccount -from esb.paas2.models import App class AppSecureInfo: @@ -35,12 +34,6 @@ class AppSecureInfo: def get_by_app_code(cls, app_code: str) -> Optional[dict]: secure_key_list = [] - # get secret from paas - if settings.BK_PAAS2_ENABLED: - app = App.objects.filter(code=app_code).first() - if app: - secure_key_list.append(app.auth_token) - # get secret from esb app = AppAccount.objects.filter(app_code=app_code).first() if app: diff --git a/src/esb/esb/esb/paas2/__init__.py b/src/esb/esb/esb/paas2/__init__.py deleted file mode 100644 index 2941673fe..000000000 --- a/src/esb/esb/esb/paas2/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# diff --git a/src/esb/esb/esb/paas2/apps.py b/src/esb/esb/esb/paas2/apps.py deleted file mode 100644 index 76367b166..000000000 --- a/src/esb/esb/esb/paas2/apps.py +++ /dev/null @@ -1,23 +0,0 @@ -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# - -from django.apps import AppConfig - - -class PaaS2CoreAppConfig(AppConfig): - name = "esb.paas2" diff --git a/src/esb/esb/esb/paas2/models.py b/src/esb/esb/esb/paas2/models.py deleted file mode 100644 index 548819a5c..000000000 --- a/src/esb/esb/esb/paas2/models.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding: utf-8 -*- -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# - -from django.db import models - - -class App(models.Model): - """ - 应用基本信息表 - """ - - name = models.CharField("name", max_length=20, unique=True) - code = models.CharField("code", max_length=30, unique=True) - auth_token = models.CharField("Token", max_length=36, blank=True, null=True) - - def __str__(self): - return self.code - - class Meta: - db_table = "paas_app" diff --git a/src/esb/esb/esb/utils/db_router.py b/src/esb/esb/esb/utils/db_router.py deleted file mode 100644 index 0ee8596da..000000000 --- a/src/esb/esb/esb/utils/db_router.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. -# Copyright (C) 2017 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 -# -# http://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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. -# - - -class DBRouter: - """ - A router to control all database operations on models in the auth application. - """ - - APP_LABEL_TO_DB = { - "paas2": "paas2", - } - - def db_for_read(self, model, **hints): - """ - Attempts to read auth models go to auth_db. - """ - return self.APP_LABEL_TO_DB.get(model._meta.app_label, "default") - - def db_for_write(self, model, **hints): - """ - Attempts to write auth models go to auth_db. - """ - return self.APP_LABEL_TO_DB.get(model._meta.app_label, "default") - - def allow_relation(self, obj1, obj2, **hints): - """ - Allow relations if a model in the auth app is involved. - """ - return self.APP_LABEL_TO_DB.get(obj1._meta.app_label) == self.APP_LABEL_TO_DB.get(obj2._meta.app_label) - - def allow_migrate(self, db, app_label, model_name=None, **hints): - """ - Make sure the auth app only appears in the 'auth_db' - database. - """ - return self.APP_LABEL_TO_DB.get(app_label, "default") == db From 33ad04175f9a478691ddce55ab52bb44ce1b0227 Mon Sep 17 00:00:00 2001 From: wklken Date: Mon, 6 May 2024 14:43:07 +0800 Subject: [PATCH 2/2] refactor(ee/data): move the edition ee/data into target dir --- .../{editions/ee/conf => data/apidocs/zh}/__init__.pyi | 0 .../{editions/ee => }/data/apidocs/zh/add_related_apps.md | 0 .../{editions/ee => }/data/apidocs/zh/apply_permissions.md | 0 .../{editions/ee => }/data/apidocs/zh/create_resource_version.md | 0 .../apigateway/{editions/ee => }/data/apidocs/zh/generate_sdk.md | 0 .../{editions/ee => }/data/apidocs/zh/get_apigw_public_key.md | 0 .../apigateway/{editions/ee => }/data/apidocs/zh/get_apis.md | 0 .../ee => }/data/apidocs/zh/get_latest_resource_version.md | 0 .../{editions/ee => }/data/apidocs/zh/get_released_resources.md | 0 .../apigateway/{editions/ee => }/data/apidocs/zh/get_stages.md | 0 .../ee => }/data/apidocs/zh/get_stages_with_resource_version.md | 0 .../{editions/ee => }/data/apidocs/zh/grant_permissions.md | 0 .../ee => }/data/apidocs/zh/import_resource_docs_by_archive.md | 0 .../ee => }/data/apidocs/zh/import_resource_docs_by_swagger.md | 0 .../{editions/ee => }/data/apidocs/zh/list_resource_versions.md | 0 .../apigateway/{editions/ee => }/data/apidocs/zh/release.md | 0 .../{editions/ee => }/data/apidocs/zh/revoke_permissions.md | 0 .../apigateway/{editions/ee => }/data/apidocs/zh/sync_api.md | 0 .../{editions/ee => }/data/apidocs/zh/sync_resources.md | 0 .../apigateway/{editions/ee => }/data/apidocs/zh/sync_stage.md | 0 .../{editions/ee => }/data/apidocs/zh/update_gateway_status.md | 0 .../ee => }/data/apigw-definitions/bk-apigateway-definition.yaml | 0 .../data/apigw-definitions/bk-apigateway-inner-definition.yaml | 0 .../data/apigw-definitions/bk-apigateway-inner-resources.yaml | 0 .../ee => }/data/apigw-definitions/bk-apigateway-resources.yaml | 0 .../ee => }/data/apigw-definitions/bk-default-definition.yaml | 0 .../ee => }/data/apigw-definitions/bk-default-resources.yaml | 0 .../ee => }/data/apigw-definitions/bk-esb-definition.yaml | 0 .../ee => }/data/apigw-definitions/bk-esb-resources.yaml | 0 .../apigateway/apigateway/editions/ee/data/__init__.pyi | 0 .../apigateway/apigateway/editions/ee/data/apidocs/__init__.pyi | 0 .../apigateway/editions/ee/data/apidocs/zh/__init__.pyi | 0 .../apigateway/apigateway/editions/ee/tests/support/__init__.pyi | 0 .../apigateway/editions/ee/tests/support/api_sdk/__init__.pyi | 0 .../editions/ee/tests/support/api_sdk/generators/__init__.pyi | 0 src/dashboard/bin/on_migrate | 1 - 36 files changed, 1 deletion(-) rename src/dashboard/apigateway/apigateway/{editions/ee/conf => data/apidocs/zh}/__init__.pyi (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/add_related_apps.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/apply_permissions.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/create_resource_version.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/generate_sdk.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/get_apigw_public_key.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/get_apis.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/get_latest_resource_version.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/get_released_resources.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/get_stages.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/get_stages_with_resource_version.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/grant_permissions.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/import_resource_docs_by_archive.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/import_resource_docs_by_swagger.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/list_resource_versions.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/release.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/revoke_permissions.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/sync_api.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/sync_resources.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/sync_stage.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apidocs/zh/update_gateway_status.md (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apigw-definitions/bk-apigateway-definition.yaml (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apigw-definitions/bk-apigateway-inner-definition.yaml (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apigw-definitions/bk-apigateway-inner-resources.yaml (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apigw-definitions/bk-apigateway-resources.yaml (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apigw-definitions/bk-default-definition.yaml (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apigw-definitions/bk-default-resources.yaml (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apigw-definitions/bk-esb-definition.yaml (100%) rename src/dashboard/apigateway/apigateway/{editions/ee => }/data/apigw-definitions/bk-esb-resources.yaml (100%) delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/data/__init__.pyi delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/__init__.pyi delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/__init__.pyi delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/tests/support/__init__.pyi delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/tests/support/api_sdk/__init__.pyi delete mode 100644 src/dashboard/apigateway/apigateway/editions/ee/tests/support/api_sdk/generators/__init__.pyi diff --git a/src/dashboard/apigateway/apigateway/editions/ee/conf/__init__.pyi b/src/dashboard/apigateway/apigateway/data/apidocs/zh/__init__.pyi similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/conf/__init__.pyi rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/__init__.pyi diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/add_related_apps.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/add_related_apps.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/add_related_apps.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/add_related_apps.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/apply_permissions.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/apply_permissions.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/apply_permissions.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/apply_permissions.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/create_resource_version.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/create_resource_version.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/create_resource_version.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/create_resource_version.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/generate_sdk.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/generate_sdk.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/generate_sdk.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/generate_sdk.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/get_apigw_public_key.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/get_apigw_public_key.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/get_apigw_public_key.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/get_apigw_public_key.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/get_apis.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/get_apis.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/get_apis.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/get_apis.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/get_latest_resource_version.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/get_latest_resource_version.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/get_latest_resource_version.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/get_latest_resource_version.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/get_released_resources.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/get_released_resources.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/get_released_resources.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/get_released_resources.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/get_stages.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/get_stages.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/get_stages.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/get_stages.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/get_stages_with_resource_version.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/get_stages_with_resource_version.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/get_stages_with_resource_version.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/get_stages_with_resource_version.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/grant_permissions.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/grant_permissions.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/grant_permissions.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/grant_permissions.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/import_resource_docs_by_archive.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/import_resource_docs_by_archive.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/import_resource_docs_by_archive.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/import_resource_docs_by_archive.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/import_resource_docs_by_swagger.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/import_resource_docs_by_swagger.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/import_resource_docs_by_swagger.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/import_resource_docs_by_swagger.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/list_resource_versions.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/list_resource_versions.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/list_resource_versions.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/list_resource_versions.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/release.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/release.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/release.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/release.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/revoke_permissions.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/revoke_permissions.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/revoke_permissions.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/revoke_permissions.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/sync_api.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/sync_api.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/sync_api.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/sync_api.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/sync_resources.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/sync_resources.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/sync_resources.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/sync_resources.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/sync_stage.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/sync_stage.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/sync_stage.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/sync_stage.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/update_gateway_status.md b/src/dashboard/apigateway/apigateway/data/apidocs/zh/update_gateway_status.md similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/update_gateway_status.md rename to src/dashboard/apigateway/apigateway/data/apidocs/zh/update_gateway_status.md diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-apigateway-definition.yaml b/src/dashboard/apigateway/apigateway/data/apigw-definitions/bk-apigateway-definition.yaml similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-apigateway-definition.yaml rename to src/dashboard/apigateway/apigateway/data/apigw-definitions/bk-apigateway-definition.yaml diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-apigateway-inner-definition.yaml b/src/dashboard/apigateway/apigateway/data/apigw-definitions/bk-apigateway-inner-definition.yaml similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-apigateway-inner-definition.yaml rename to src/dashboard/apigateway/apigateway/data/apigw-definitions/bk-apigateway-inner-definition.yaml diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-apigateway-inner-resources.yaml b/src/dashboard/apigateway/apigateway/data/apigw-definitions/bk-apigateway-inner-resources.yaml similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-apigateway-inner-resources.yaml rename to src/dashboard/apigateway/apigateway/data/apigw-definitions/bk-apigateway-inner-resources.yaml diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-apigateway-resources.yaml b/src/dashboard/apigateway/apigateway/data/apigw-definitions/bk-apigateway-resources.yaml similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-apigateway-resources.yaml rename to src/dashboard/apigateway/apigateway/data/apigw-definitions/bk-apigateway-resources.yaml diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-default-definition.yaml b/src/dashboard/apigateway/apigateway/data/apigw-definitions/bk-default-definition.yaml similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-default-definition.yaml rename to src/dashboard/apigateway/apigateway/data/apigw-definitions/bk-default-definition.yaml diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-default-resources.yaml b/src/dashboard/apigateway/apigateway/data/apigw-definitions/bk-default-resources.yaml similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-default-resources.yaml rename to src/dashboard/apigateway/apigateway/data/apigw-definitions/bk-default-resources.yaml diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-esb-definition.yaml b/src/dashboard/apigateway/apigateway/data/apigw-definitions/bk-esb-definition.yaml similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-esb-definition.yaml rename to src/dashboard/apigateway/apigateway/data/apigw-definitions/bk-esb-definition.yaml diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-esb-resources.yaml b/src/dashboard/apigateway/apigateway/data/apigw-definitions/bk-esb-resources.yaml similarity index 100% rename from src/dashboard/apigateway/apigateway/editions/ee/data/apigw-definitions/bk-esb-resources.yaml rename to src/dashboard/apigateway/apigateway/data/apigw-definitions/bk-esb-resources.yaml diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/__init__.pyi b/src/dashboard/apigateway/apigateway/editions/ee/data/__init__.pyi deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/__init__.pyi b/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/__init__.pyi deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/__init__.pyi b/src/dashboard/apigateway/apigateway/editions/ee/data/apidocs/zh/__init__.pyi deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/dashboard/apigateway/apigateway/editions/ee/tests/support/__init__.pyi b/src/dashboard/apigateway/apigateway/editions/ee/tests/support/__init__.pyi deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/dashboard/apigateway/apigateway/editions/ee/tests/support/api_sdk/__init__.pyi b/src/dashboard/apigateway/apigateway/editions/ee/tests/support/api_sdk/__init__.pyi deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/dashboard/apigateway/apigateway/editions/ee/tests/support/api_sdk/generators/__init__.pyi b/src/dashboard/apigateway/apigateway/editions/ee/tests/support/api_sdk/generators/__init__.pyi deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/dashboard/bin/on_migrate b/src/dashboard/bin/on_migrate index 70d66e96e..e61162f72 100755 --- a/src/dashboard/bin/on_migrate +++ b/src/dashboard/bin/on_migrate @@ -39,7 +39,6 @@ python manage.py sync_default_micro_gateway \ # ESB 相关 python manage.py create_esb_jwt_key -python manage.py sync_legacy_esb_reusable_data python manage.py create_esb_gateway python manage.py sync_esb_jwt_key_to_gateway python manage.py update_esb_user_verified_unrequired_apps ${esb_verified_user_exempted_apps}