Skip to content

Commit 47a272d

Browse files
committed
fix(backend): 优化相关cmsi、用户管理、cmdb请求相关的代码 TencentBlueKing#16093
# Reviewed, transaction id: 74098
1 parent cd9b96d commit 47a272d

File tree

7 files changed

+18
-22
lines changed

7 files changed

+18
-22
lines changed

dbm-ui/backend/components/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def _get_cached_admin_username(self):
436436
elif isinstance(data, dict) and data:
437437
bk_username = data.get("bk_username") or data.get("username")
438438
if bk_username:
439-
cache.set(cache_key, bk_username, 1) # 60 * 60 * 24)
439+
cache.set(cache_key, bk_username, 60 * 60 * 24)
440440
else:
441441
raise ValidationError(_("获取租户管理员账号失败: 未能从响应中获取用户名"))
442442
except Exception as e:

dbm-ui/backend/components/cmsi/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,27 @@ def MSG_TYPE_MAP(self):
3434
def __init__(self):
3535
self.get_msg_type = self.generate_data_api(
3636
method="GET",
37-
url="v1/channels/",
37+
url="channels/",
3838
description=_("查询通知类型"),
3939
)
4040
self.send_voice = self.generate_data_api(
4141
method="POST",
42-
url="v1/send_voice/",
42+
url="send_voice/",
4343
description=_("语音通知"),
4444
)
4545
self.send_sms = self.generate_data_api(
4646
method="POST",
47-
url="v1/send_sms/",
47+
url="send_sms/",
4848
description=_("短信通知"),
4949
)
5050
self.send_weixin = self.generate_data_api(
5151
method="POST",
52-
url="v1/send_weixin/",
52+
url="send_weixin/",
5353
description=_("微信通知"),
5454
)
5555
self.send_mail = self.generate_data_api(
5656
method="POST",
57-
url="v1/send_mail/",
57+
url="send_mail/",
5858
description=_("邮件通知"),
5959
)
6060

dbm-ui/backend/components/domains.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,15 @@
1515
ESB_PREFIX = "/api/c/compapi/v2/"
1616
ESB_DOMAIN_TPL = "{}{}{{}}/".format(env.BK_COMPONENT_API_URL, ESB_PREFIX)
1717

18-
# apigw
19-
APIGW_PREFIX = "/api/{}/prod/"
20-
APIGW_DOMAIN_TPL = "{}{}".format(env.BASE_APIGW_DOMAIN, APIGW_PREFIX)
2118

2219
# 优先取环境变量的配置,若未配置对应的环境变量,则取paas默认的esb地址
2320
CC_APIGW_DOMAIN = env.CC_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("cc")
2421
GSE_APIGW_DOMAIN = env.GSE_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("gse")
2522
JOB_APIGW_DOMAIN = env.JOB_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("jobv3")
2623
SOPS_APIGW_DOMAIN = env.SOPS_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("sops")
2724
ESB_APIGW_DOMAIN = env.ESB_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("esb")
28-
# 用户管理
29-
USER_MANAGE_APIGW_DOMAIN = APIGW_DOMAIN_TPL.format("bk-user") or ESB_DOMAIN_TPL.format("usermanage")
30-
# 消息通知
31-
CMSI_APIGW_DOMAIN = APIGW_DOMAIN_TPL.format("bk-cmsi") or ESB_DOMAIN_TPL.format("cmsi")
25+
USER_MANAGE_APIGW_DOMAIN = env.USER_MANAGE_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("usermanage")
26+
CMSI_APIGW_DOMAIN = env.CMSI_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("cmsi")
3227
BKCHAT_APIGW_DOMAIN = env.BKCHAT_APIGW_DOMAIN
3328
ITSM_APIGW_DOMAIN = env.ITSM_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("itsm")
3429
BKLOG_APIGW_DOMAIN = env.BKLOG_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("bk_log")

dbm-ui/backend/components/usermanage/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ def __init__(self):
2323
is_esb = self.is_esb()
2424
self.list_users = self.generate_data_api(
2525
method="GET",
26-
url="list_users/" if is_esb else "api/v3/open/tenant/users/",
26+
url="list_users/" if is_esb else "tenant/users/",
2727
description=_("获取所有用户"),
2828
cache_time=300,
2929
)
3030
self.retrieve_user = self.generate_data_api(
3131
method="GET",
32-
url="retrieve_user/" if is_esb else "api/v3/open/tenant/users/{bk_username}/",
32+
url="retrieve_user/" if is_esb else "tenant/users/{bk_username}/",
3333
description=_("获取单个用户"),
3434
)
3535
self.batch_lookup_virtual_user = self.generate_data_api(
3636
method="GET",
37-
url="api/v3/open/tenant/virtual-users/-/lookup/",
37+
url="tenant/virtual-users/-/lookup/",
3838
description=_("获取租户的管理员用户"),
3939
)
4040

dbm-ui/backend/configuration/views/system.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ def environ(self, request):
130130
if not env.ENABLE_EXTERNAL_PROXY and not env.ENABLE_OPEN_EXTERNAL_PROXY:
131131
envs.update(
132132
{
133-
"CC_IDLE_MODULE_ID": CcManage(env.DBA_APP_BK_BIZ_ID, "").get_biz_internal_module(
134-
env.DBA_APP_BK_BIZ_ID
135-
)[IDLE_HOST_MODULE]["bk_module_id"],
133+
"CC_IDLE_MODULE_ID": CcManage(env.DBA_APP_BK_BIZ_ID, "")
134+
.get_biz_internal_module(env.DBA_APP_BK_BIZ_ID)
135+
.get(IDLE_HOST_MODULE, {})
136+
.get("bk_module_id"),
136137
"BK_COMPONENT_API_URL": env.BK_COMPONENT_API_URL,
137138
"BK_CMDB_URL": env.BK_CMDB_URL,
138139
"BK_NODEMAN_URL": env.BK_NODEMAN_URL,

dbm-ui/backend/env/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@
5757
# esb 访问地址
5858
BK_COMPONENT_API_URL = get_type_env(key="BK_COMPONENT_API_URL", _type=str, default="https://bk-component.example.com")
5959

60-
# apigw 访问地址
61-
BASE_APIGW_DOMAIN = get_type_env(key="BASE_APIGW_DOMAIN", _type=str, default="https://bkapi.bk-component.example.com")
62-
6360
# 开启外部路由,供外部环境使用(DBConsole)
6461
ENABLE_EXTERNAL_PROXY = get_type_env(key="ENABLE_EXTERNAL_PROXY", _type=bool, default=False)
6562
# 开启所有路由,不屏蔽。!!这里只用在合作伙伴环境!!

dbm-ui/backend/flow/utils/cc_manage.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ def get_or_create_set_module(
140140
def get_biz_internal_module(bk_biz_id: int):
141141
"""获取业务下的内置模块"""
142142
biz_internal_module = ResourceQueryHelper.get_biz_internal_module(bk_biz_id)
143+
if not biz_internal_module or not biz_internal_module.get("module"):
144+
logger.warning(f"biz_internal_module is empty, bk_biz_id: {bk_biz_id}")
145+
return {}
143146
module_type__module = {module["default"]: module for module in biz_internal_module["module"]}
144147
return module_type__module
145148

0 commit comments

Comments
 (0)