Skip to content

Commit

Permalink
feat: APIGW自动接入 (closed #2476)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpyoung3 committed Jan 16, 2025
1 parent ca2de73 commit 08bba57
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
18 changes: 11 additions & 7 deletions apps/node_man/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.
"""
import sys

from bk_notice_sdk.views import api_call
from blueapps.utils.esbclient import get_client_by_user
Expand Down Expand Up @@ -126,10 +127,13 @@ def init_settings(cls):
default={},
)
settings.PLUGIN_COMMON_CONSTANTS = plugin_common_constants
# 根据开关来决定是否执行 sync_apigw
if settings.SYNC_APIGATEWAY_ENABLED:
try:
call_command("sync_apigw")
logger.info("Successfully executed sync_apigw")
except Exception as e:
logger.error(f"Error executing sync_apigw: {e}")

# 执行项目启动命令时才会自动同步,避免执行其他指令也自动同步
if len(sys.argv) > 1 and (sys.argv[1] == "runserver" or sys.argv[0] == "gunicorn"):
# 根据开关来决定是否执行 sync_apigw,上云环境不开启
if settings.SYNC_APIGATEWAY_ENABLED:
try:
call_command("sync_apigw")
logger.info("Successfully executed sync_apigw")
except Exception as e:
logger.error(f"Error executing sync_apigw: {e}")
34 changes: 17 additions & 17 deletions support-files/apigw/definition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ apigateway:
- "admin"

# 定义环境信息,用于命令 `sync_apigw_stage`
stage:
name: "{{ settings.ENVIRONMENT }}"
stages:
- name: "{{ settings.ENVIRONMENT }}"
{% if settings.ENVIRONMENT == "prod" %}
description: "正式环境"
description_en: "Prod"
description: "正式环境"
description_en: "Prod"
{% elif settings.ENVIRONMENT == "stag" %}
description: "预发布环境"
description_en: "Test"
description: "预发布环境"
description_en: "Test"
{% else %}
description: "开发测试环境"
description_en: "Development"
description: "开发测试环境"
description_en: "Development"
{% endif %}
backends:
- name: "default"
config:
timeout: 180
loadbalance: "roundrobin"
hosts:
# 网关调用后端服务的默认域名或IP,不包含Path,比如: http://api.example.com
- host: "{{ settings.BK_NODEMAN_BACKEND_HOST }}"
weight: 100
backends:
- name: "default"
config:
timeout: 180
loadbalance: "roundrobin"
hosts:
# 网关调用后端服务的默认域名或IP,不包含Path,比如: http://api.example.com
- host: "{{ settings.BK_NODEMAN_BACKEND_HOST }}"
weight: 100
grant_permissions:
- bk_app_code: "{{ settings.APP_CODE }}"
# grant_dimension: "gateway"
Expand Down

0 comments on commit 08bba57

Please sign in to comment.