Skip to content

Commit

Permalink
Merge pull request #361 from alex-smile/add_get_weixin_config
Browse files Browse the repository at this point in the history
PaaS 使用 ESB 组件API获取微信配置
  • Loading branch information
alex-smile authored Jun 4, 2021
2 parents 47b51e2 + ac4374f commit f2341c9
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 7 deletions.
2 changes: 1 addition & 1 deletion paas2/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.12.17
2.12.18
33 changes: 33 additions & 0 deletions paas2/esb/components/bk/apis/esb/get_weixin_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS
Community Edition) available.
Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
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.
"""

from common.constants import API_TYPE_Q
from components.component import Component
from esb.bkcore.models import ESBChannel

from .toolkit import configs


class GetWeixinConfig(Component):
""""""

sys_name = configs.SYSTEM_NAME
api_type = API_TYPE_Q

def handle(self):
wx_channel_path = "/cmsi/send_weixin/"
channel = ESBChannel.objects.filter(path=wx_channel_path).first()

self.response.payload = {
"result": True,
"data": channel.comp_conf_dict if channel else {},
}
7 changes: 7 additions & 0 deletions paas2/esb/components/esb_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,13 @@ def _rel_path(x):
"is_hidden": True,
},
),
(
"/esb/get_weixin_config/",
{
"comp_codename": "generic.esb.get_weixin_config",
"is_hidden": True,
},
),
# weixin
("/weixin/get_token/", {"comp_codename": "generic.weixin.get_token", "is_hidden": True}),
),
Expand Down
7 changes: 7 additions & 0 deletions paas2/esb/esb/bkcore/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ def extra_info_json(self):
except Exception:
return {}

@property
def comp_conf_dict(self):
try:
return dict(json.loads(self.comp_conf))
except Exception:
return {}


class FunctionController(models.Model):
"""功能开关控制器"""
Expand Down
6 changes: 6 additions & 0 deletions paas2/paas/blueking/component/apis/esb.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def __init__(self, client):
path="/api/c/compapi/esb/add_app_component_perm/",
description="Add component permission for app",
)
self.get_weixin_config = ComponentAPI(
client=self.client,
method="GET",
path="/api/c/compapi/esb/get_weixin_config/",
description="Get wechat config",
)
self.get_weixin_access_token = ComponentAPI(
client=self.client,
method="GET",
Expand Down
12 changes: 6 additions & 6 deletions paas2/paas/user_center/wx_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@

from components import usermgr
from common.log import logger
from esb.bkcore.models import ESBChannel
from user_center.constants import WxTypeEnum
from user_center.models import WxBkUserTmpRecord
from blueking.component.shortcuts import get_client_by_user


def get_wx_config():
"""
获取微信相关配置
"""
wx_comp_path = "/cmsi/send_weixin/"
# 检查是否配置了微信通知组件
if not ESBChannel.objects.filter(path=wx_comp_path).exists():
client = get_client_by_user("admin")
result = client.esb.get_weixin_config()
if not result.get("result", False):
logger.error("Get weixin config from esb fail, result=%s", result)
return None

esb_channel = ESBChannel.objects.get(path=wx_comp_path)
comp_conf = esb_channel.comp_conf_dict
comp_conf = result.get("data", {})
# 检查微信配置的完整性
if not comp_conf or not isinstance(comp_conf, dict):
logger.error("WeChat notification component configuration is empty")
Expand Down
4 changes: 4 additions & 0 deletions paas2/release.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Release Log
===============================
# 2.12.18
- esb: add get_weixin_config
- paas: use get_weixin_config to fetch weixin config

# 2.12.17
- esb: update esb cc confapis
- esb: esb management display component frequency configuration
Expand Down

0 comments on commit f2341c9

Please sign in to comment.