Skip to content

Commit

Permalink
Merge pull request #418 from TencentBlueKing/feat_strategy_new
Browse files Browse the repository at this point in the history
feat: 策略配置优化
  • Loading branch information
OrenZhang authored Sep 4, 2024
2 parents 36f24ea + 333a5d3 commit 06ab8ab
Show file tree
Hide file tree
Showing 116 changed files with 5,540 additions and 1,203 deletions.
13 changes: 8 additions & 5 deletions release.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
### V1.14.0 版本更新日志

- [ 新增 ] 资产拉取支持配置全量或增量拉取
- [ 新增 ] 风险列表展示风险等级
- [ 新增 ] 风险单详情增加信息展示
- [ 新增 ] 策略配置界面优化
- [ 优化 ] 资产拉取启动失败时展示异常信息
- [ 优化 ] 优化时间选择器交互体验
- [ 修复 ] 修复空间选择器标签偏移
Expand Down Expand Up @@ -63,7 +66,7 @@
- [ 新增 ] 操作日志审计切换为离线计算
- [ 新增 ] 方案参数映射配置时字段名称相同自动填充
- [ 优化 ] 增加AI策略运行周期校验
- [ 优化 ] 套餐配置参数只取标准运维全局变量中需要显示的字段
- [ 优化 ] 套餐配置参数只取标准运维全局变量中需要显示的字段
- [ 优化 ] 更新权限申请审计日志检索操作名称
- [ 优化 ] 适配新版本 BKVision 下拉菜单参数
- [ 修复 ] 修复检索页面完整日志样式异常的问题
Expand Down Expand Up @@ -197,10 +200,10 @@

### V1.1.0 版本更新日志

- [ 新增 ] 支持基于BCS的容器环境日志的采集
- [ 新增 ] 字段清洗支持正则清洗
- [ 优化 ] 支持复制应用系统负责人名单
- [ 优化 ] 应用系统接入模型中资源的操作优化为启用、停用
- [ 新增 ] 支持基于BCS的容器环境日志的采集
- [ 新增 ] 字段清洗支持正则清洗
- [ 优化 ] 支持复制应用系统负责人名单
- [ 优化 ] 应用系统接入模型中资源的操作优化为启用、停用
- [ 优化 ] 应用系统列表支持筛选数据上报状态
- [ 优化 ] 数据检索中操作人选项未输入内容时提示输入用户ID
- [ 优化 ] 数据检索中完整日志按钮显示压线
Expand Down
18 changes: 18 additions & 0 deletions src/backend/apps/notice/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
We undertake not to change the open source license (MIT license) applicable
to the current version of the project delivered to anyone in the future.
"""
from typing import List, Union

from bk_audit.log.models import AuditInstance
from bk_resource.utils.common_utils import get_md5
from django.db import models
from django.db.models import QuerySet
from django.utils.translation import gettext_lazy

from apps.notice.constants import RelateType
Expand Down Expand Up @@ -113,6 +115,22 @@ class Meta:
def audit_instance(self):
return NoticeGroupAuditInstance(self)

@property
def members(self) -> List[str]:
"""
处理组成员
"""

return list({member for member in self.group_member})

@classmethod
def parse_members(cls, groups: Union[QuerySet["NoticeGroup"], List["NoticeGroup"]]) -> List[str]:
"""
解析处理组成员
"""

return list({member for group in groups for member in group.members})


class NoticeLog(OperateRecordModel):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/backend/apps/sops/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@

class GetTemplatesRespSerializer(serializers.Serializer):
id = serializers.IntegerField()
name = serializers.CharField()
name = serializers.CharField(allow_blank=True)
url = serializers.CharField(required=False, allow_null=True, allow_blank=True)
1 change: 1 addition & 0 deletions src/backend/apps/user_manage/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
25 changes: 25 additions & 0 deletions src/backend/apps/user_manage/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making
蓝鲸智云 - 审计中心 (BlueKing - Audit Center) available.
Copyright (C) 2023 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.
We undertake not to change the open source license (MIT license) applicable
to the current version of the project delivered to anyone in the future.
"""

from django.apps import AppConfig
from django.utils.translation import gettext_lazy


class UserManageConfig(AppConfig):
name = "apps.user_manage"
verbose_name = gettext_lazy("用户管理")
35 changes: 35 additions & 0 deletions src/backend/apps/user_manage/resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making
蓝鲸智云 - 审计中心 (BlueKing - Audit Center) available.
Copyright (C) 2023 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.
We undertake not to change the open source license (MIT license) applicable
to the current version of the project delivered to anyone in the future.
"""

from bk_resource import CacheResource, api
from bk_resource.exceptions import APIRequestError
from bk_resource.utils.cache import CacheTypeItem
from django.utils.translation import gettext_lazy


class RetrieveLeader(CacheResource):
name = gettext_lazy("获取单个用户的leader信息")
cache_type = CacheTypeItem(key="retrieve_leader", timeout=60 * 60, user_related=False)

def perform_request(self, validated_request_data):
try:
# 获取用户信息&解析出leader信息
user_info = api.user_manage.retrieve_user(validated_request_data)
return user_info.get("leader", [])[0].get("username", "")
except (IndexError, APIRequestError):
return ""
1 change: 1 addition & 0 deletions src/backend/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"apps.bk_crypto",
"apps.sops",
"apps.itsm",
"apps.user_manage",
"bk_resource",
"rest_framework",
"drf_yasg",
Expand Down
43 changes: 43 additions & 0 deletions src/backend/core/render.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-

import json
import re
from typing import Dict, List, Union

from django.utils import translation
from jinja2 import Environment


def jinja2_environment(*args, **kwargs) -> Environment:
"""创建jinja2的环境执行环境 ."""
env = Environment(extensions=["jinja2.ext.i18n"], *args, **kwargs)
env.install_gettext_translations(translation, newstyle=True)
return env


class Jinja2Renderer:
"""
Jinja2渲染器
"""

def __init__(self, *args, **kwargs):
self.env = jinja2_environment(*args, **kwargs)

def _render(self, template_value: str, context: dict) -> str:
"""
只支持json和re函数
"""
return self.env.from_string(template_value).render({"json": json, "re": re, **context})

def jinja_render(self, template_value: Union[str, dict, list], context: dict) -> Union[str, Dict, List]:
"""使用jinja渲染对象 ."""
if isinstance(template_value, str):
return self._render(template_value, context) or template_value
if isinstance(template_value, dict):
render_value = {}
for key, value in template_value.items():
render_value[key] = self.jinja_render(value, context)
return render_value
if isinstance(template_value, list):
return [self.jinja_render(value, context) for value in template_value]
return template_value
Binary file modified src/backend/locale/en/LC_MESSAGES/django.mo
Binary file not shown.
90 changes: 86 additions & 4 deletions src/backend/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-23 11:58+0800\n"
"POT-Creation-Date: 2024-08-26 10:55+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -1874,6 +1874,12 @@ msgstr "Get Template Detail"
msgid "获取任务状态常量"
msgstr "List Task Status Constants"

msgid "用户管理"
msgstr "User Management"

msgid "获取单个用户的leader信息"
msgstr "Retrieve User Leader"

msgid "审计中心"
msgstr "BK Audit"

Expand Down Expand Up @@ -2934,6 +2940,9 @@ msgstr "Risk Label"
msgid "Last Operate Time"
msgstr "Last Operate Time"

msgid "Risk Title"
msgstr "Risk Title"

msgid "UUID"
msgstr "UUID"

Expand Down Expand Up @@ -3009,6 +3018,10 @@ msgstr "Authorized Time"
msgid "Ticket Permission"
msgstr "Ticket Permission"

#, python-format
msgid "(未获取到变量值:%s)"
msgstr "(Variable value not obtained:%s)"

msgid "创建事件"
msgstr "Create Event"

Expand Down Expand Up @@ -3045,6 +3058,9 @@ msgstr "Approve Build In Fields"
msgid "获取风险详情"
msgstr "Get Risk Detail"

msgid "获取风险策略信息"
msgstr "Obtain Risk Strategy Information"

msgid "获取风险列表"
msgstr "List Risk"

Expand Down Expand Up @@ -3163,6 +3179,9 @@ msgstr "Risk Type"
msgid "Event Content"
msgstr "Event Content"

msgid "Risk Level"
msgstr "Risk Level"

msgid "未配置审批流"
msgstr "Approve Service Not Set"

Expand Down Expand Up @@ -3193,6 +3212,15 @@ msgstr "New Operator"
msgid "不能转单给自己"
msgstr "Not allowed to trans to yourself"

msgid "Event Basic Field Configs"
msgstr "Event Basic Field Configs"

msgid "Event Data Field Configs"
msgstr "Event Data Field Configs"

msgid "Event Evidence Field Configs"
msgstr "Event Evidence Field Configs"

msgid "Sync BKM Alert Failed"
msgstr "Sync BKM Alert Failed"

Expand Down Expand Up @@ -3290,6 +3318,15 @@ msgstr "Public Field"
msgid "Extend Field"
msgstr "Extend Field"

msgid "高"
msgstr "High"

msgid "中"
msgstr "Middle"

msgid "低"
msgstr "Low"

msgid "Control Changed"
msgstr "Control Changed"

Expand Down Expand Up @@ -3324,6 +3361,24 @@ msgstr "Backend Data"
msgid "Notice Groups"
msgstr "Notice Groups"

msgid "Processor"
msgstr "Processor"

msgid "Risk Hazard"
msgstr "Risk Hazard"

msgid "Risk Guidance"
msgstr "Risk Guidance"

msgid "Event Field Configs"
msgstr "Event Field Configs"

msgid "Event Data Configs"
msgstr "Event Data Configs"

msgid "Event Evidence Configs"
msgstr "Event Evidence Configs"

msgid "Strategy"
msgstr "Strategy"

Expand Down Expand Up @@ -3375,6 +3430,30 @@ msgstr "Get RT Fields"
msgid "Get Strategy Status"
msgstr "Get Strategy Status"

msgid "Get Event Info Fields"
msgstr "Get Event Info Fields"

msgid "获取策略展示信息"
msgstr "Get Strategy Display Information"

msgid "Field Name"
msgstr "Field Name"

msgid "Field Display Name"
msgstr "Field Display Name"

msgid "Is Priority"
msgstr "Is Priority"

msgid "Field Description"
msgstr "Field Description"

msgid "Processor Groups"
msgstr "Processor Groups"

msgid "Processor Group"
msgstr "Processor Group"

msgid "Control Version not Exists"
msgstr "Control Version not Exists"

Expand Down Expand Up @@ -3420,9 +3499,6 @@ msgstr "Algorithms"
msgid "Detects"
msgstr "Detects"

msgid "Field Name"
msgstr "Field Name"

msgid "System ID"
msgstr "System ID"

Expand Down Expand Up @@ -3510,6 +3586,12 @@ msgstr "Strategy IDs"
msgid "Strategy ID Invalid"
msgstr "Strategy ID Invalid"

msgid "Display Name"
msgstr "Display Name"

msgid "Example"
msgstr "Example"

msgid "版本日志"
msgstr "Version Log"

Expand Down
Binary file modified src/backend/locale/zh_CN/LC_MESSAGES/django.mo
Binary file not shown.
Loading

0 comments on commit 06ab8ab

Please sign in to comment.