Skip to content

Commit 3a5cc46

Browse files
authored
feat(apigw_manager/drf): add grant resource permission and import docs (TencentBlueKing#219)
1 parent a349a6b commit 3a5cc46

5 files changed

Lines changed: 47 additions & 10 deletions

File tree

.github/workflows/apigw-manager.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
- name: Install dependencies
3434
run: |
35-
python -m pip install --upgrade pip
35+
python -m pip install pip -U
3636
python -m pip install . 'tox-gh-actions==3.2.0' -r requirements_tox.txt
3737
python -m pip uninstall -y tox-pyenv-redux
3838
working-directory: sdks/apigw-manager

sdks/apigw-manager/pyproject.toml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "apigw-manager"
3-
version = "4.0.1"
3+
version = "4.0.2"
44
description = "The SDK for managing blueking gateway resource."
55
readme = "README.md"
66
authors = ["blueking <blueking@tencent.com>"]
@@ -10,11 +10,26 @@ classifiers = [
1010
"License :: OSI Approved :: MIT License",
1111
]
1212

13+
[project]
14+
name = "apigw-manager"
15+
description = "The SDK for managing blueking gateway resource."
16+
license = "MIT"
17+
dynamic = ["version", "classifiers", "dependencies"]
18+
readme = "README.md"
19+
authors = [{name = "blueking", email = "blueking@tencent.com"}]
20+
requires-python = '>=3.8,<3.13'
21+
1322

1423
[project.urls]
1524
Homepage = "https://github.com/TencentBlueKing/bkpaas-python-sdk/"
1625
Repository = "https://github.com/TencentBlueKing/bkpaas-python-sdk/"
1726

27+
[project.optional-dependencies]
28+
cryptography = ['cryptography (>=3.1.1)', 'pyjwt (>=2.0.0)']
29+
drf = ["django", 'cryptography', 'pyjwt', 'djangorestframework (>=3.10.3)', 'drf-spectacular (<=0.27.2)']
30+
django = ["django", 'pyjwt']
31+
demo = ['django-environ (>=0.8.1)', "django", 'PyMySQL (>=1.0.2,<2.0.0)', 'pyjwt']
32+
kubernetes = ['kubernetes']
1833
[tool.poetry.dependencies]
1934
python = ">=3.8,<3.13"
2035
setuptools = ">=21.0.0"

sdks/apigw-manager/src/apigw_manager/drf/management/commands/data/definition.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,24 @@ stages:
4747
{% endfor %}
4848
{% endif %}
4949

50-
{% if settings.BK_APIGW_GRANT_PERMISSION_DIMENSION_GATEWAY_APP_CODES %}
50+
{% if settings.BK_APIGW_GRANT_PERMISSION_DIMENSION_GATEWAY_APP_CODES or settings.BK_APIGW_GRANT_PERMISSION_DIMENSION_RESOURCE_APP_CODES %}
5151
grant_permissions:
5252
{% for app_code in settings.BK_APIGW_GRANT_PERMISSION_DIMENSION_GATEWAY_APP_CODES %}
5353
- bk_app_code: "{{ app_code }}"
5454
grant_dimension: "gateway"
5555
{% endfor %}
56+
{% for app_code, resource_names in settings.BK_APIGW_GRANT_PERMISSION_DIMENSION_RESOURCE_APP_CODES.items %}
57+
- bk_app_code: "{{ app_code }}"
58+
grant_dimension: "resource"
59+
resource_names:
60+
{% for resource_name in resource_names %}
61+
- "{{ resource_name }}"
62+
{% endfor %}
63+
{% endfor %}
5664
{% endif %}
5765

5866
related_apps:
5967
- "{{ settings.BK_APP_CODE }}"
68+
69+
resource_docs:
70+
basedir: "{{ settings.BK_APIGW_RESOURCE_DOCS_BASE_DIR }}"

sdks/apigw-manager/src/apigw_manager/drf/management/commands/sync_drf_apigateway.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,31 @@ def handle(self, *args, **kwargs):
6060
f"--doc_language={settings.BK_APIGW_RELEASE_DOC_LANGUAGE}",
6161
)
6262

63-
self.stdout.write(
64-
f"call create_version_and_release_apigw with definition: {definition_file_path}, stage: {settings.BK_APIGW_STAGE_NAME}"
65-
)
63+
# if BK_APIGW_RESOURCE_DOCS_BASE_DIR is not empty, then sync the resource docs
64+
if hasattr(settings, "BK_APIGW_RESOURCE_DOCS_BASE_DIR") and settings.BK_APIGW_RESOURCE_DOCS_BASE_DIR:
65+
self.stdout.write(f"call sync_resource_docs_by_archive with definition: {definition_file_path}")
66+
call_command(
67+
"sync_resource_docs_by_archive",
68+
f"--gateway-name={gateway_name}",
69+
f"--file={definition_file_path}",
70+
"--safe-mode",
71+
)
72+
73+
self.stdout.write(f"call grant_apigw_permissions with definition: {definition_file_path}")
6674
call_command(
67-
"create_version_and_release_apigw",
75+
"grant_apigw_permissions",
6876
f"--gateway-name={gateway_name}",
6977
f"--file={definition_file_path}",
70-
f"--stage={settings.BK_APIGW_STAGE_NAME}",
7178
)
7279

73-
self.stdout.write(f"call grant_apigw_permissions with definition: {definition_file_path}")
80+
self.stdout.write(
81+
f"call create_version_and_release_apigw with definition: {definition_file_path}, stage: {settings.BK_APIGW_STAGE_NAME}"
82+
)
7483
call_command(
75-
"grant_apigw_permissions",
84+
"create_version_and_release_apigw",
7685
f"--gateway-name={gateway_name}",
7786
f"--file={definition_file_path}",
87+
f"--stage={settings.BK_APIGW_STAGE_NAME}",
7888
)
7989

8090
self.stdout.write(f"call fetch_apigw_public_key {gateway_name}")

sdks/apigw-manager/tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ minversion = 3.23.0
33
isolated_build = True
44
envlist = py{38,39,310,311,312}-django{3,4,5}-pyjwt{2}
55

6+
67
[gh-actions]
78
python =
89
3.8: py38

0 commit comments

Comments
 (0)