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(apigw_manager/drf): update to support multiple stages #196

Merged
merged 6 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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.2"
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 @@ -21,28 +21,26 @@ apigateway:
{% endif %}

stages:
- name: "{{ settings.BK_APIGW_DEFAULT_STAGE_NAME }}"
description: "{{ settings.BK_APIGW_DEFAULT_STAGE_DESCRIPTION }}"
description_en: "{{ settings.BK_APIGW_DEFAULT_STAGE_DESCRIPTION_EN }}"
{% if settings.BK_APIGW_DEFAULT_STAGE_BACKEND_SUBPATH %}
- name: "{{ settings.BK_APIGW_STAGE_NAME }}"
description: "{{ settings.BK_APIGW_STAGE_DESCRIPTION }}"
description_en: "{{ settings.BK_APIGW_STAGE_DESCRIPTION_EN }}"
{% if settings.BK_APIGW_STAGE_BACKEND_SUBPATH %}
vars:
api_sub_path: {{ settings.BK_APIGW_DEFAULT_STAGE_BACKEND_SUBPATH }}
api_sub_path: {{ settings.BK_APIGW_STAGE_BACKEND_SUBPATH }}
{% else %}
vars: {}
{% endif %}
backends:
- name: "default"
config:
timeout: 60
timeout: {{ settings.BK_APIGW_STAG_BACKEND_TIMEOUT }}
loadbalance: "roundrobin"
hosts:
# 网关调用后端服务的默认域名或IP,不包含Path,比如:http://api.example.com
- host: "{{ settings.BK_APIGW_DEFAULT_STAGE_BACKEND_HOST }}"
- host: "{{ settings.BK_APIGW_STAGE_BACKEND_HOST }}"
weight: 100
# TODO: support plugin_configs
{% if settings.BK_APIGW_DEFAULT_STAGE_PLUGIN_CONFIGS %}
{% if settings.BK_APIGW_STAGE_PLUGIN_CONFIGS %}
plugin_configs:
{% for plugin_config in settings.BK_APIGW_DEFAULT_STAGE_PLUGIN_CONFIGS %}
{% for plugin_config in settings.BK_APIGW_STAGE_PLUGIN_CONFIGS %}
- type: {{ plugin_config.type }}
yaml: |-
{{ plugin_config.yaml }}
Expand All @@ -58,4 +56,4 @@ grant_permissions:
{% endif %}

related_apps:
- "{{ settings.BK_APP_CODE }}"
- "{{ settings.BK_APP_CODE }}"
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
2. call this command with tag, e.g. `python manage.py generate_resource_yaml.py --tag=foo --tag=bar`
"""

from pathlib import Path
from typing import List

from django.conf import settings
Expand All @@ -23,7 +24,6 @@
from drf_spectacular.renderers import OpenApiYamlRenderer
from drf_spectacular.settings import spectacular_settings
from drf_spectacular.validation import validate_schema
from pathlib import Path


def post_process_only_keep_the_apis_with_specified_tags(tags: List) -> callable:
Expand Down Expand Up @@ -51,7 +51,7 @@ def post_process_inject_method_and_path(result, generator, request, public):
paths = result.get("paths", None)
if not paths:
return result
sub_path = settings.BK_APIGW_DEFAULT_STAGE_BACKEND_SUBPATH
sub_path = settings.BK_APIGW_STAGE_BACKEND_SUBPATH

for uri, methods in paths.items():
for method, info in methods.items():
Expand Down Expand Up @@ -84,7 +84,7 @@ def handle(self, *args, **kwargs):
else:
self.stdout.write("no argument --tag, will use all apis under the project")

self.stdout.write(f"process the project sub_path={settings.BK_APIGW_DEFAULT_STAGE_BACKEND_SUBPATH}")
self.stdout.write(f"process the project sub_path={settings.BK_APIGW_STAGE_BACKEND_SUBPATH}")
spectacular_settings.POSTPROCESSING_HOOKS.append(post_process_inject_method_and_path)

generator = spectacular_settings.DEFAULT_GENERATOR_CLASS()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"""

from pathlib import Path

from django.conf import settings
from django.core.management import call_command
from django.core.management.base import BaseCommand
Expand Down Expand Up @@ -59,13 +60,13 @@ def handle(self, *args, **kwargs):
)

self.stdout.write(
f"call create_version_and_release_apigw with definition: {definition_file_path}, stage: {settings.BK_APIGW_DEFAULT_STAGE_NAME}"
f"call create_version_and_release_apigw with definition: {definition_file_path}, stage: {settings.BK_APIGW_STAGE_NAME}"
)
call_command(
"create_version_and_release_apigw",
f"--gateway-name={gateway_name}",
f"--file={definition_file_path}",
f"--stage={settings.BK_APIGW_DEFAULT_STAGE_NAME}",
f"--stage={settings.BK_APIGW_STAGE_NAME}",
)

self.stdout.write(f"call grant_apigw_permissions with definition: {definition_file_path}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

@pytest.fixture()
def django_settings_subpath_empty(settings):
settings.BK_APIGW_DEFAULT_STAGE_BACKEND_SUBPATH = ""
settings.BK_APIGW_STAGE_BACKEND_SUBPATH = ""


@pytest.fixture()
def django_settings_subpath(settings):
settings.BK_APIGW_DEFAULT_STAGE_BACKEND_SUBPATH = "/mock"
settings.BK_APIGW_STAGE_BACKEND_SUBPATH = "/mock"


class TestPostProcess:
Expand Down
Loading