Skip to content

Commit

Permalink
feature: 插件配置公共常量支持 (closed TencentBlueKing#1500)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyyalt committed Apr 20, 2023
1 parent 7ee2fc4 commit d3a9acd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 17 additions & 2 deletions apps/backend/subscription/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,20 @@ def get_plugin_path(plugin_name: str, target_host: models.Host, agent_config: Di
return plugin_path


def get_plugin_common_constants(plugin_name: str) -> Dict:
"""
获取插件配置公共常量
https://github.com/TencentBlueKing/bk-nodeman/issues/1500
:param plugin_name: 插件名称
"""
common_constants = models.GlobalSettings.get_config(
key=models.GlobalSettings.KeyEnum.PLUGIN_COMMON_CONSTANTS.value,
default={},
)
# 返回特定插件是否开启公共常量
return common_constants.get(plugin_name, {}).update({"global": common_constants.get("global", {})})


def get_all_subscription_steps_context(
subscription_step: models.SubscriptionStep,
instance_info: Dict,
Expand Down Expand Up @@ -1011,10 +1025,11 @@ def get_all_subscription_steps_context(
"inner_ip": target_host.inner_ip,
"outer_ip": target_host.outer_ip,
"login_ip": target_host.login_ip,
}
},
# 获取插件配置公共常量
"constants": get_plugin_common_constants(plugin_name),
},
)

# 深拷贝一份,避免原数据后续被污染
context = copy.deepcopy(context)
return context
Expand Down
2 changes: 2 additions & 0 deletions apps/node_man/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class KeyEnum(Enum):
GSE_AGENT2_VERSION = "GSE_AGENT2_VERSION"
# 【临时变量】主机安装动作新增推送身份动作, cc版本稳定后废除
ENABLE_PUSH_HOST_IDENTIFIER = "ENABLE_PUSH_HOST_IDENTIFIER"
# 插件配置公共常量支持 issue: https://github.com/TencentBlueKing/bk-nodeman/issues/1500
PLUGIN_COMMON_CONSTANTS = "PLUGIN_COMMON_CONSTANTS"

key = models.CharField(_("键"), max_length=255, db_index=True, primary_key=True)
v_json = JSONField(_("值"))
Expand Down

0 comments on commit d3a9acd

Please sign in to comment.