Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api/web): fix get stage plugins #931

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading