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

fix :custom channel in CMSI will be hidden when exec sync #752

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions src/esb/esb/conf/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,7 @@ def _(s):
BK_SSM_API_URL = env.str("BK_SSM_API_URL", "")
BK_SSM_ACCESS_TOKEN_CACHE_MAXSIZE = env.int("BK_SSM_ACCESS_TOKEN_CACHE_MAXSIZE", 2000)
BK_SSM_ACCESS_TOKEN_CACHE_TTL_SECONDS = env.int("BK_SSM_ACCESS_TOKEN_CACHE_TTL_SECONDS", 300)

# 从环境变量获取同步通道数据时豁免的自定义通道列表,格式为字符串,格式为:
# [{"board": "default", "method": "get", "path": "/cmsi/send_xxxx"}]
EXCLUDE_OFFICIAL_CHANNELS_WHEN_SYNCING = env.str("BK_ESB_EXCLUDE_OFFICIAL_CHANNELS_WHEN_SYNCING", default="")
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#
import json
import logging
from django.conf import settings

from django.core.management.base import BaseCommand

Expand Down Expand Up @@ -305,4 +306,25 @@ def _get_official_channel_ids(self):
return list(ESBChannel.objects.filter(system_id__in=official_system_ids).values_list("id", flat=True))

def _hide_channels(self, channel_ids):
exclude_channels_config = settings.EXCLUDE_OFFICIAL_CHANNELS_WHEN_SYNCING
try:
# 环境变量只能传递字符串,需要先json格式化
exclude_channels_config = json.loads(exclude_channels_config)
except Exception:
logger.warning("EXCLUDE_OFFICIAL_CHANNELS_WHEN_SYNCING is not a json format!")
exclude_channels_config = []
if exclude_channels_config:
channel_ids_dict = dict.fromkeys(channel_ids, None)
for channel in exclude_channels_config:
if "board" in channel and "method" in channel and "path" in channel:
try:
exclude_channel_id = ESBChannel.objects.get(
board=channel["board"], method=channel["method"], path=channel["path"]
).id
channel_ids_dict.pop(exclude_channel_id, None)
except ESBChannel.DoesNotExist:
logger.warning("channel does not exist: board=%s, method=%s, path=%s",
channel["board"], channel["method"], channel["path"])
continue
channel_ids = channel_ids_dict.keys()
ESBChannel.objects.filter(id__in=channel_ids).update(is_public=False)
Loading