MCPcopy Index your code
hub / github.com/cloudfoundry/cli / GetAndValidatePlugin

Method GetAndValidatePlugin

actor/pluginaction/install.go:83–153  ·  view source on GitHub ↗
(pluginMetadata PluginMetadata, commandList CommandList, path string)

Source from the content-addressed store, hash-verified

81}
82
83func (actor Actor) GetAndValidatePlugin(pluginMetadata PluginMetadata, commandList CommandList, path string) (configv3.Plugin, error) {
84 plugin, err := pluginMetadata.GetMetadata(path)
85 if err != nil || plugin.Name == "" || len(plugin.Commands) == 0 {
86 return configv3.Plugin{}, actionerror.PluginInvalidError{Err: err}
87 }
88
89 var pluginLibraryMajorVersion int
90 hasPluginLibraryVersion := plugin.LibraryVersion != configv3.PluginVersion{}
91 if !hasPluginLibraryVersion {
92 pluginLibraryMajorVersion = 1
93 } else {
94 pluginLibraryMajorVersion = plugin.LibraryVersion.Major
95 }
96
97 if pluginLibraryMajorVersion > 1 {
98 return configv3.Plugin{}, actionerror.PluginInvalidLibraryVersionError{}
99 }
100
101 installedPlugins := actor.config.Plugins()
102
103 conflictingNames := []string{}
104 conflictingAliases := []string{}
105
106 for _, command := range plugin.Commands {
107 if commandList.HasCommand(command.Name) || commandList.HasAlias(command.Name) {
108 conflictingNames = append(conflictingNames, command.Name)
109 }
110
111 if commandList.HasAlias(command.Alias) || commandList.HasCommand(command.Alias) {
112 conflictingAliases = append(conflictingAliases, command.Alias)
113 }
114
115 for _, installedPlugin := range installedPlugins {
116 // we do not error if a plugins commands conflict with previous
117 // versions of the same plugin
118 if plugin.Name == installedPlugin.Name {
119 continue
120 }
121
122 for _, installedCommand := range installedPlugin.Commands {
123 if command.Name == installedCommand.Name || command.Name == installedCommand.Alias {
124 conflictingNames = append(conflictingNames, command.Name)
125 }
126
127 if command.Alias != "" &&
128 (command.Alias == installedCommand.Alias || command.Alias == installedCommand.Name) {
129 conflictingAliases = append(conflictingAliases, command.Alias)
130 }
131 }
132 }
133 }
134
135 if len(conflictingNames) > 0 || len(conflictingAliases) > 0 {
136 sort.Slice(conflictingNames, func(i, j int) bool {
137 return strings.ToLower(conflictingNames[i]) < strings.ToLower(conflictingNames[j])
138 })
139
140 sort.Slice(conflictingAliases, func(i, j int) bool {

Callers

nothing calls this directly

Implementers 1

FakeActorcommand/v7/v7fakes/fake_actor.go

Calls 5

GetMetadataMethod · 0.65
PluginsMethod · 0.65
HasCommandMethod · 0.65
HasAliasMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected