Skip to content

Commit

Permalink
fix(api/web): fix get stage plugins (#931)
Browse files Browse the repository at this point in the history
* fix(api/web): fix get stage plugins
  • Loading branch information
Han-Ya-Jun authored Sep 18, 2024
1 parent d97aa82 commit 358ae2f
Showing 1 changed file with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# 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.
#
import copy

from rest_framework import serializers

Expand Down Expand Up @@ -82,26 +81,30 @@ def get_proxy(self, obj):
return proxy

def get_plugins(self, obj):
plugins = copy.deepcopy(self.context.get("stage_plugins", {}))
stage_plugins = self.context.get("stage_plugins", {})
# v2 才有plugin数据
if not self.context["is_schema_v2"]:
return list(plugins.values())
return list(stage_plugins.values())

# 如果类型是merge, 同一个类型的环境 + 资源插件将会同时存在
# 如果类型是override, 同一个类型的环境插件将会被资源插件覆盖
rules = PLUGIN_MERGE_TYPE

# 根据 rules 配置确定是否资源插件配置覆盖环境插件配置
plugins = []
override_plugins = set()
for plugin in obj.get("plugins", []):
plugin_type = plugin["type"]
if rules.get(plugin_type, "") == "merge":
plugin["binding_type"] = PluginBindingScopeEnum.RESOURCE.value
plugins[f"{plugin_type}:resource"] = plugin
else:
plugin["binding_type"] = PluginBindingScopeEnum.RESOURCE.value
plugins[plugin_type] = plugin

return list(plugins.values())
plugin["binding_type"] = PluginBindingScopeEnum.RESOURCE.value

# 根据 rules 配置确定是否资源插件配置覆盖环境插件配置
# 如果类型是merge, 同一个类型的环境 + 资源插件将会同时存在
# 如果类型是override, 同一个类型的环境插件将会被资源插件覆盖
if not (stage_plugins.get(plugin_type) and PLUGIN_MERGE_TYPE.get(plugin_type, "") == "merge"):
override_plugins.add(plugin_type)

plugins.append(plugin)

plugins.extend(
[plugin for plugin_type, plugin in stage_plugins.items() if plugin_type not in override_plugins]
)

return plugins


class ResourceVersionRetrieveOutputSLZ(serializers.Serializer):
Expand Down

0 comments on commit 358ae2f

Please sign in to comment.