-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #418 from TencentBlueKing/feat_strategy_new
feat: 策略配置优化
- Loading branch information
Showing
116 changed files
with
5,540 additions
and
1,203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# -*- coding: utf-8 -*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("用户管理") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.