From 5eb071d00b0688e64ab5792f8a03331804936e78 Mon Sep 17 00:00:00 2001 From: hanyajun <1581532052@qq.com> Date: Fri, 6 Sep 2024 11:49:12 +0800 Subject: [PATCH] Revert "feat: support no-pub (#182)" This reverts commit 3b99fdbe99e78abbeee68190a4a2ef98c9e00f86. --- sdks/apigw-manager/README.md | 3 - .../docs/sync-apigateway-with-django.md | 4 +- .../docs/sync-apigateway-with-docker.md | 3 - .../support-files/bin/sync-apigateway.sh | 2 - .../support-files/bin/sync-apigateway.sh | 2 - sdks/apigw-manager/pyproject.toml | 2 +- .../create_version_and_release_apigw.py | 25 ++-- .../test_create_version_and_release_apigw.py | 107 +++++++----------- 8 files changed, 53 insertions(+), 95 deletions(-) diff --git a/sdks/apigw-manager/README.md b/sdks/apigw-manager/README.md index 30b67167..21c5305c 100644 --- a/sdks/apigw-manager/README.md +++ b/sdks/apigw-manager/README.md @@ -74,6 +74,3 @@ definition.yaml 指定的环境配置适用于 `sync_apigw_stage` 命令,而 访问 `http://apigw.__bk_domain__/backend/admin42/core/apirelatedapp/`,添加应用操作网关数据的权限 -### 6. 注册网关资源时如果只想注册生成版本,不进行版本发布,该如何操作? - -`create_version_and_release_apigw` 是进行网关资源生成版本和发布的命令,可以通过指定 `--no-pub` 只进行版本生成,不进行资源发布。 \ No newline at end of file diff --git a/sdks/apigw-manager/docs/sync-apigateway-with-django.md b/sdks/apigw-manager/docs/sync-apigateway-with-django.md index a40a0628..aaa36288 100644 --- a/sdks/apigw-manager/docs/sync-apigateway-with-django.md +++ b/sdks/apigw-manager/docs/sync-apigateway-with-django.md @@ -39,8 +39,7 @@ python manage.py sync_apigw_resources --delete --gateway-name=${gateway_name} -- # 可选,同步资源文档 python manage.py sync_resource_docs_by_archive --gateway-name=${gateway_name} --file="${definition_file}" -# 创建资源版本、发布;指定参数 --generate-sdks 时,会同时生成资源版本对应的网关 SDK 指定 --stage stage1 stage2 时会发布指定环境,不设置则发布所有环境 -# 指定参数 --no-pub 则只生成版本,不发布 +# 创建资源版本并发布;指定参数 --generate-sdks 时,会同时生成资源版本对应的网关 SDK 指定 --stage stage1 stage2 时会发布指定环境,不设置则发布所有环境 python manage.py create_version_and_release_apigw --gateway-name=${gateway_name} --file="${definition_file}" # 可选,为应用主动授权 @@ -154,7 +153,6 @@ python manage.py add_related_apps --gateway-name=${gateway_name} --file="${defin python manage.py apply_apigw_permissions --gateway-name=${gateway_name} --file="${definition_file}" # 创建资源版本并发布;指定参数 --generate-sdks 时,会同时生成资源版本对应的网关 SDK 指定 --stage stage1 stage2 时会发布指定环境,不设置则发布所有环境 -# 指定参数 --no-pub 则只生成版本,不发布 python manage.py create_version_and_release_apigw --gateway-name=${gateway_name} --file="${definition_file}" # 获取网关公钥 diff --git a/sdks/apigw-manager/docs/sync-apigateway-with-docker.md b/sdks/apigw-manager/docs/sync-apigateway-with-docker.md index f17be25e..2b07e916 100644 --- a/sdks/apigw-manager/docs/sync-apigateway-with-docker.md +++ b/sdks/apigw-manager/docs/sync-apigateway-with-docker.md @@ -80,8 +80,6 @@ title "fetch apigateway public key" apigw-manager.sh fetch_apigw_public_key --gateway-name=${gateway_name} --print > "apigateway.pub" title "releasing" -# 创建资源版本并发布;指定参数 --generate-sdks 时,会同时生成资源版本对应的网关 SDK, 指定 --stage stage1 stage2 时会发布指定环境,不设置则发布所有环境 -# 指定参数 --no-pub 则只生成版本,不发布 call_definition_command_or_exit create_version_and_release_apigw "${definition_file}" --gateway-name=${gateway_name} log_info "done" @@ -276,7 +274,6 @@ call_definition_command_or_exit add_related_apps "${definition_file}" --gateway- call_definition_command_or_exit apply_apigw_permissions "${definition_file}" --gateway-name=${gateway_name} # 创建资源版本并发布;指定参数 --generate-sdks 时,会同时生成资源版本对应的网关 SDK, 指定 --stage stage1 stage2 时会发布指定环境,不设置则发布所有环境 -# 指定参数 --no-pub 则只生成版本,不发布 call_definition_command_or_exit create_version_and_release_apigw "${definition_file}" --gateway-name=${gateway_name} # 获取网关公钥,存放到文件 apigateway.pub diff --git a/sdks/apigw-manager/examples/chart/use-configmap/files/support-files/bin/sync-apigateway.sh b/sdks/apigw-manager/examples/chart/use-configmap/files/support-files/bin/sync-apigateway.sh index 507dae38..5879f32c 100755 --- a/sdks/apigw-manager/examples/chart/use-configmap/files/support-files/bin/sync-apigateway.sh +++ b/sdks/apigw-manager/examples/chart/use-configmap/files/support-files/bin/sync-apigateway.sh @@ -26,8 +26,6 @@ title "fetch apigateway public key" apigw-manager.sh fetch_apigw_public_key --gateway-name=${gateway_name} --print > "/tmp/apigateway.pub" title "releasing" -# 创建资源版本并发布;指定参数 --generate-sdks 时,会同时生成资源版本对应的网关 SDK, 指定 --stage stage1 stage2 时会发布指定环境,不设置则发布所有环境 -# 指定参数 --no-pub 则只生成版本,不发布 call_definition_command_or_exit create_version_and_release_apigw "${definition_file}" --gateway-name=${gateway_name} title "done" diff --git a/sdks/apigw-manager/examples/chart/use-custom-docker-image/my-apigw-manager/support-files/bin/sync-apigateway.sh b/sdks/apigw-manager/examples/chart/use-custom-docker-image/my-apigw-manager/support-files/bin/sync-apigateway.sh index f9c10001..eb86200d 100755 --- a/sdks/apigw-manager/examples/chart/use-custom-docker-image/my-apigw-manager/support-files/bin/sync-apigateway.sh +++ b/sdks/apigw-manager/examples/chart/use-custom-docker-image/my-apigw-manager/support-files/bin/sync-apigateway.sh @@ -26,8 +26,6 @@ title "fetch apigateway public key" apigw-manager.sh fetch_apigw_public_key --gateway-name=${gateway_name} --print > "apigateway.pub" title "releasing" -# 创建资源版本并发布;指定参数 --generate-sdks 时,会同时生成资源版本对应的网关 SDK, 指定 --stage stage1 stage2 时会发布指定环境,不设置则发布所有环境 -# 指定参数 --no-pub 则只生成版本,不发布 call_definition_command_or_exit create_version_and_release_apigw "${definition_file}" --gateway-name=${gateway_name} title "done" diff --git a/sdks/apigw-manager/pyproject.toml b/sdks/apigw-manager/pyproject.toml index 8a7f651f..a0510fee 100644 --- a/sdks/apigw-manager/pyproject.toml +++ b/sdks/apigw-manager/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "apigw-manager" -version = "3.1.1" +version = "3.1.0" description = "The SDK for managing blueking gateway resource." readme = "README.md" authors = ["blueking "] diff --git a/sdks/apigw-manager/src/apigw_manager/apigw/management/commands/create_version_and_release_apigw.py b/sdks/apigw-manager/src/apigw_manager/apigw/management/commands/create_version_and_release_apigw.py index a7dabdc7..5cc87d97 100644 --- a/sdks/apigw-manager/src/apigw_manager/apigw/management/commands/create_version_and_release_apigw.py +++ b/sdks/apigw-manager/src/apigw_manager/apigw/management/commands/create_version_and_release_apigw.py @@ -35,7 +35,6 @@ def add_arguments(self, parser): parser.add_argument("-c", "--comment", default="", help="release comment") parser.add_argument("-s", "--stage", default=[], nargs="+", help="release stages") parser.add_argument("--generate-sdks", default=False, action="store_true", help="with sdks generation") - parser.add_argument("--no-pub", default=False, action="store_true", help="only make version") def _parse_version_from_definition(self, definition): version = definition.get("version") @@ -90,7 +89,7 @@ def _generate_sdks(self, releaser, version, *args, **kwargs): except Exception as err: print("warning!! generate sdks failed: %s" % err) - def handle(self, stage, title, comment, generate_sdks, no_pub, *args, **kwargs): + def handle(self, stage, title, comment, generate_sdks, *args, **kwargs): configuration = self.get_configuration(**kwargs) definition = self.get_definition(**kwargs) defined_version = self._parse_version_from_definition(definition) @@ -122,18 +121,16 @@ def handle(self, stage, title, comment, generate_sdks, no_pub, *args, **kwargs): generate_sdks = False print("resource_version %s already exists, skip creating" % latest_version) - # 如果没有设置不发布 - if not no_pub: - result = releaser.release( - version=resource_version["version"], - title=title or resource_version.get("title", ""), - comment=comment or resource_version.get("comment", ""), - stage_names=stage, - ) - print( - "API gateway released %s, title %s, stages %s" - % (result.get("version"), result["resource_version_title"], result["stage_names"]) - ) + result = releaser.release( + version=resource_version["version"], + title=title or resource_version.get("title", ""), + comment=comment or resource_version.get("comment", ""), + stage_names=stage, + ) + print( + "API gateway released %s, title %s, stages %s" + % (result.get("version"), result["resource_version_title"], result["stage_names"]) + ) # create a sdk when released a new version if generate_sdks: diff --git a/sdks/apigw-manager/tests/apigw_manager/apigw/management/commands/test_create_version_and_release_apigw.py b/sdks/apigw-manager/tests/apigw_manager/apigw/management/commands/test_create_version_and_release_apigw.py index 1f1be184..335e6398 100644 --- a/sdks/apigw-manager/tests/apigw_manager/apigw/management/commands/test_create_version_and_release_apigw.py +++ b/sdks/apigw-manager/tests/apigw_manager/apigw/management/commands/test_create_version_and_release_apigw.py @@ -27,7 +27,6 @@ def default_command_flags(definition_file): "title": "", "comment": "", "generate_sdks": False, - "no_pub": False, } @@ -161,11 +160,11 @@ def test_should_create_resource_version(mocker, command, defined_version, latest ], ) def test_get_version_to_be_created( - command, - datetime_now, - defined_version, - resource_version_exists, - expected, + command, + datetime_now, + defined_version, + resource_version_exists, + expected, ): result = command._get_version_to_be_created( parse_version(defined_version), @@ -178,15 +177,15 @@ def test_get_version_to_be_created( class TestHandle: def test_handle_version_not_change( - self, - command, - fetcher, - releaser, - faker, - definition_file, - resource_sync_manager, - fake_resource_version, - default_command_flags, + self, + command, + fetcher, + releaser, + faker, + definition_file, + resource_sync_manager, + fake_resource_version, + default_command_flags, ): definition_file.write(yaml.dump(fake_resource_version)) stage = faker.pystr() @@ -211,15 +210,15 @@ def test_handle_version_not_change( ) def test_handle_version_not_change_but_dirty( - self, - command, - fetcher, - releaser, - faker, - definition_file, - resource_sync_manager, - fake_resource_version, - default_command_flags, + self, + command, + fetcher, + releaser, + faker, + definition_file, + resource_sync_manager, + fake_resource_version, + default_command_flags, ): definition_file.write(yaml.dump(fake_resource_version)) stage = faker.pystr() @@ -256,14 +255,14 @@ def test_handle_version_not_change_but_dirty( ) def test_handle_version_changed( - self, - command, - fetcher, - releaser, - faker, - definition_file, - fake_resource_version, - default_command_flags, + self, + command, + fetcher, + releaser, + faker, + definition_file, + fake_resource_version, + default_command_flags, ): defined_version = "1.0.0-alpha2" definition_file.write( @@ -300,15 +299,15 @@ def test_handle_version_changed( ) def test_handle_version_not_set( - self, - command, - fetcher, - releaser, - faker, - definition_file, - resource_sync_manager, - fake_resource_version, - default_command_flags, + self, + command, + fetcher, + releaser, + faker, + definition_file, + resource_sync_manager, + fake_resource_version, + default_command_flags, ): definition_file.write( yaml.dump( @@ -352,29 +351,3 @@ def test_handle_version_not_set( comment=fake_resource_version["comment"], stage_names=stage, ) - - def test_handle_without_release( - self, - command, - fetcher, - releaser, - faker, - definition_file, - resource_sync_manager, - fake_resource_version, - default_command_flags, - ): - definition_file.write(yaml.dump(fake_resource_version)) - stage = faker.pystr() - - default_command_flags["no_pub"] = True - - fetcher.latest_resource_version.return_value = fake_resource_version - - resource_sync_manager.is_dirty.return_value = False - - command.handle(stage=stage, **default_command_flags) - - releaser.create_resource_version.assert_not_called() - - releaser.releaser.release.assert_not_called()