Skip to content

Commit dba1c23

Browse files
author
Xinkai Yi
committed
fix: 移除django-environ 导入
1 parent a5def3b commit dba1c23

2 files changed

Lines changed: 73 additions & 11 deletions

File tree

  • runtime/bk-plugin-runtime/bk_plugin_runtime/config
  • template/{{cookiecutter.project_name}}

runtime/bk-plugin-runtime/bk_plugin_runtime/config/default.py

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,42 @@
1212
import json
1313
import os
1414
import urllib
15+
from urllib.parse import urlparse
16+
1517

1618
from blueapps.conf.default_settings import * # noqa
1719
from blueapps.conf.log import get_logging_config_dict
1820

21+
1922
BKPAAS_ENVIRONMENT = os.getenv("BKPAAS_ENVIRONMENT", "dev")
20-
# 默认关闭可观侧性
23+
# 默认关闭可观测性
2124
ENABLE_OTEL_METRICS = os.getenv("ENABLE_METRICS", False)
2225

2326
# 请在这里加入你的自定义 APP
2427
INSTALLED_APPS += ( # noqa
25-
"rest_framework",
26-
"drf_yasg",
28+
2729
"bk_plugin_framework.runtime.loghub",
2830
"bk_plugin_framework.runtime.schedule",
2931
"bk_plugin_framework.runtime.callback",
3032
"bk_plugin_framework.services.bpf_service",
31-
"apigw_manager.apigw",
33+
"rest_framework",
34+
"drf_spectacular",
3235
"django_dbconn_retry",
36+
"apigw_manager.drf",
37+
"apigw_manager.apigw",
3338
)
3439
if ENABLE_OTEL_METRICS:
3540
INSTALLED_APPS += ("blueapps.opentelemetry.instrument_app",) # noqa
3641

3742
if BKPAAS_ENVIRONMENT == "dev":
3843
INSTALLED_APPS += ("bk_plugin_framework.services.debug_panel",) # noqa
3944

40-
from bk_plugin_framework.runtime.callback.celery import queues as callback_queues # noqa
41-
from bk_plugin_framework.runtime.schedule.celery import queues as schedule_queues # noqa
45+
from bk_plugin_framework.runtime.callback.celery import ( # noqa
46+
queues as callback_queues,
47+
)
48+
from bk_plugin_framework.runtime.schedule.celery import ( # noqa
49+
queues as schedule_queues,
50+
)
4251

4352
CELERY_QUEUES = schedule_queues.CELERY_QUEUES
4453
CELERY_QUEUES.extend(callback_queues.CELERY_QUEUES)
@@ -75,8 +84,6 @@
7584
"apigw_manager.apigw.authentication.ApiGatewayJWTUserMiddleware", # JWT 透传的用户信息
7685
)
7786

78-
# 用户认证
79-
AUTHENTICATION_BACKENDS += ("bk_plugin_runtime.packages.apigw.backends.APIGWUserModelBackend",) # noqa
8087

8188
# 所有环境的日志级别可以在这里配置
8289
# LOG_LEVEL = 'INFO'
@@ -170,9 +177,8 @@
170177

171178
ROOT_URLCONF = "bk_plugin_runtime.urls"
172179

173-
from blueapps.core.celery import celery_app # noqa
174-
175180
from bk_plugin_framework.runtime.schedule.celery.beat import SCHEDULE # noqa
181+
from blueapps.core.celery import celery_app # noqa
176182

177183
celery_app.conf.beat_schedule = SCHEDULE
178184

@@ -217,7 +223,60 @@ def logging_addition_settings(logging_dict):
217223
{"format": logging_dict["formatters"]["verbose"][kw].strip() + " [trace_id]: %(trace_id)s"}
218224
)
219225
break
220-
226+
# drf settings
227+
REST_FRAMEWORK = {
228+
"DEFAULT_AUTHENTICATION_CLASSES": [
229+
"apigw_manager.drf.authentication.ApiGatewayJWTAuthentication",
230+
],
231+
"DEFAULT_PERMISSION_CLASSES": [
232+
"apigw_manager.drf.permission.ApiGatewayPermission",
233+
],
234+
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
235+
}
236+
237+
238+
# 网关是否公开,公开则其他开发者可见/可申请权限
239+
BK_APIGW_IS_PUBLIC = os.getenv("BK_APIGW_IS_PUBLIC", "true").lower()
240+
# if BK_APIGW_IS_OFFICIAL is True, the BK_APIGW_NAME should be start with `bk-`
241+
BK_APIGW_IS_OFFICIAL = 1 if os.getenv("BK_APIGW_IS_OFFICIAL", "false").lower() == "true" else 10
242+
# 网关管理员,请将负责人加入列表中
243+
BK_APIGW_MAINTAINERS = [m.strip() for m in os.getenv("BK_APIGW_MAINTAINERS", "admin").split(",") if m.strip()]
244+
# 网关接口最大超时时间
245+
BK_APIGW_STAG_BACKEND_TIMEOUT = 60
246+
247+
248+
# analysis the app environment and address via bkpaas env vars
249+
bkpaas_default_preallocated_urls = json.loads(os.getenv("BKPAAS_DEFAULT_PREALLOCATED_URLS", "{}"))
250+
bkpaas_environment = os.getenv("BKPAAS_ENVIRONMENT", "dev")
251+
app_address = bkpaas_default_preallocated_urls.get(bkpaas_environment)
252+
parsed_url = urlparse(app_address)
253+
app_scheme = parsed_url.scheme
254+
app_domain = parsed_url.netloc
255+
app_subpath = parsed_url.path.rstrip("/")
256+
257+
BK_APIGW_STAGE_BACKEND_HOST = f"{app_scheme}://{app_domain}"
258+
BK_APIGW_STAGE_BACKEND_SUBPATH = app_subpath
259+
260+
261+
262+
# while deploy app on staging env, it would sync to the stage=stag of the gateway
263+
# while deploy app on production env, it would sync to the stage=prod of the gateway
264+
BK_APIGW_STAGE_NAME = bkpaas_environment
265+
BK_APIGW_STAGE_DESCRIPTION = "生产环境" if bkpaas_environment == "prod" else "预发布环境"
266+
BK_APIGW_STAGE_DESCRIPTION_EN = "Production Env" if bkpaas_environment == "prod" else "Staging Env"
267+
# 声明网关不同环境的环境变量
268+
stag_env_vars = {
269+
"foo": "bar"
270+
}
271+
prod_env_vars = {
272+
# "foo": "bar"
273+
}
274+
BK_APIGW_STAGE_ENV_VARS = prod_env_vars if bkpaas_environment == "prod" else stag_env_vars
275+
276+
# 网关同步 API 文档语言, zh/en, 如果配置了BK_APIGW_RESOURCE_DOCS_BASE_DIR(使用自定义文档), 那么必须将这个变量置空
277+
BK_APIGW_RELEASE_DOC_LANGUAGE = os.getenv("BK_APIGW_RELEASE_DOC_LANGUAGE", "")
278+
# 在项目 docs目录下,通过 markdown文档自动化导入中英文文档; 注意markdown文件名必须等于接口的 operation_id; 见 demo 示例
279+
# BK_APIGW_RESOURCE_DOCS_BASE_DIR = env.str("BK_APIGW_RESOURCE_DOCS_BASE_DIR", default=BASE_DIR / "docs")
221280

222281
# BK SOPS RELATE
223282
BK_SOPS_APP_CODE = os.getenv("BK_SOPS_APP_CODE")

template/{{cookiecutter.project_name}}/app_desc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ modules:
44
isDefault: true
55
language: python
66
spec:
7+
hooks:
8+
preRelease:
9+
procCommand: "bash bin/sync_apigateway.sh"
710
processes:
811
- name: web
912
procCommand: gunicorn bk_plugin_runtime.wsgi --timeout 120 -k gthread --threads 16 -w 8 --max-requests=1000 --env prometheus_multiproc_dir=/tmp/

0 commit comments

Comments
 (0)