| 164 | } |
| 165 | |
| 166 | func ValidateRegistry(registry Registry) error { |
| 167 | if registry.SchemaVersion != SchemaVersion && registry.SchemaVersion != SchemaVersionV2 { |
| 168 | return fmt.Errorf("unsupported schema_version %d", registry.SchemaVersion) |
| 169 | } |
| 170 | seen := make(map[string]struct{}, len(registry.Plugins)) |
| 171 | for index, plugin := range registry.Plugins { |
| 172 | if registry.SchemaVersion == SchemaVersion && PluginInstallType(plugin) == InstallTypeDirect { |
| 173 | return fmt.Errorf("plugins[%d]: direct install requires schema_version %d", index, SchemaVersionV2) |
| 174 | } |
| 175 | if errValidate := ValidatePlugin(plugin); errValidate != nil { |
| 176 | return fmt.Errorf("plugins[%d]: %w", index, errValidate) |
| 177 | } |
| 178 | id := strings.TrimSpace(plugin.ID) |
| 179 | if _, exists := seen[id]; exists { |
| 180 | return fmt.Errorf("plugins[%d]: duplicate plugin id %q", index, id) |
| 181 | } |
| 182 | seen[id] = struct{}{} |
| 183 | } |
| 184 | return nil |
| 185 | } |
| 186 | |
| 187 | func ValidatePlugin(plugin Plugin) error { |
| 188 | required := map[string]string{ |