forked from TencentBlueKing/bk-nodeman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: 云梯安全组添加白名单功能 (closed TencentBlueKing#1760)
- Loading branch information
Showing
11 changed files
with
394 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-节点管理(BlueKing-BK-NODEMAN) available. | ||
Copyright (C) 2017-2022 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 https://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. | ||
""" | ||
import copy | ||
from dataclasses import _is_dataclass_instance, fields | ||
|
||
|
||
def _asdict_inner(obj, dict_factory): | ||
if _is_dataclass_instance(obj): | ||
result = [] | ||
for f in fields(obj): | ||
value = _asdict_inner(getattr(obj, f.name), dict_factory) | ||
# 过滤掉为空或者None的字段 | ||
if not value: | ||
continue | ||
result.append((f.name, value)) | ||
return dict_factory(result) | ||
elif isinstance(obj, (list, tuple)): | ||
return type(obj)(_asdict_inner(v, dict_factory) for v in obj) | ||
elif isinstance(obj, dict): | ||
return type(obj)((_asdict_inner(k, dict_factory), _asdict_inner(v, dict_factory)) for k, v in obj.items()) | ||
else: | ||
return copy.deepcopy(obj) | ||
|
||
|
||
def asdict(obj, *, dict_factory=dict): | ||
if not _is_dataclass_instance(obj): | ||
raise TypeError("asdict() should be called on dataclass instances") | ||
return _asdict_inner(obj, dict_factory) |
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
Oops, something went wrong.