(plugin Plugin)
| 230 | } |
| 231 | |
| 232 | func ValidatePluginVersions(plugin Plugin) error { |
| 233 | if len(plugin.Versions) == 0 { |
| 234 | return nil |
| 235 | } |
| 236 | seen := make(map[string]struct{}, len(plugin.Versions)) |
| 237 | for index, version := range plugin.Versions { |
| 238 | version.Version = normalizeVersion(version.Version) |
| 239 | if !validPluginVersion(version.Version) { |
| 240 | return fmt.Errorf("versions[%d]: invalid plugin version %q", index, version.Version) |
| 241 | } |
| 242 | if _, exists := seen[version.Version]; exists { |
| 243 | return fmt.Errorf("versions[%d]: duplicate plugin version %q", index, version.Version) |
| 244 | } |
| 245 | seen[version.Version] = struct{}{} |
| 246 | installType := strings.ToLower(strings.TrimSpace(version.Install.Type)) |
| 247 | if installType == "" { |
| 248 | installType = PluginInstallType(plugin) |
| 249 | version.Install.Type = installType |
| 250 | } |
| 251 | if installType != PluginInstallType(plugin) { |
| 252 | return fmt.Errorf("versions[%d]: install type %q does not match plugin install type %q", index, installType, PluginInstallType(plugin)) |
| 253 | } |
| 254 | if errPlan := ValidateInstallPlan(version.Install); errPlan != nil { |
| 255 | return fmt.Errorf("versions[%d]: %w", index, errPlan) |
| 256 | } |
| 257 | } |
| 258 | return nil |
| 259 | } |
| 260 | |
| 261 | func PluginInstallType(plugin Plugin) string { |
| 262 | installType := strings.ToLower(strings.TrimSpace(plugin.Install.Type)) |
no test coverage detected