Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support no-pub #183

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions sdks/apigw-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` 只进行版本生成,不进行资源发布。
4 changes: 1 addition & 3 deletions sdks/apigw-manager/docs/sync-apigateway-with-django.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

# 可选,为应用主动授权
Expand Down Expand Up @@ -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}"

# 获取网关公钥
Expand Down
3 changes: 0 additions & 3 deletions sdks/apigw-manager/docs/sync-apigateway-with-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion sdks/apigw-manager/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def default_command_flags(definition_file):
"title": "",
"comment": "",
"generate_sdks": False,
"no_pub": False,
}


Expand Down Expand Up @@ -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),
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Loading