validateViaHubAPI fetches the JSON schema for a CloudQuery-registry plugin from the Hub API and validates spec against it. The plugin path is the canonical "team/name" hub identifier from the source/destination's `path:` field.
(ctx context.Context, c *cloudquery_api.ClientWithResponses, pluginPath string, kind cloudquery_api.PluginKind, version string, spec map[string]any)
| 214 | // the Hub API and validates spec against it. The plugin path is the canonical |
| 215 | // "team/name" hub identifier from the source/destination's `path:` field. |
| 216 | func validateViaHubAPI(ctx context.Context, c *cloudquery_api.ClientWithResponses, pluginPath string, kind cloudquery_api.PluginKind, version string, spec map[string]any) error { |
| 217 | team, name, err := splitHubPath(pluginPath) |
| 218 | if err != nil { |
| 219 | return err |
| 220 | } |
| 221 | log.Info().Str("team", team).Str("name", name).Str("version", version).Str("kind", string(kind)).Msg("Fetching spec schema from Hub API") |
| 222 | resp, err := c.GetPluginVersionWithResponse(ctx, team, kind, name, version) |
| 223 | if err != nil { |
| 224 | return fmt.Errorf("failed to fetch spec schema from Hub API: %w", err) |
| 225 | } |
| 226 | if resp.StatusCode() != http.StatusOK || resp.JSON200 == nil { |
| 227 | return hub.ErrorFromHTTPResponse(resp.HTTPResponse, resp) |
| 228 | } |
| 229 | if resp.JSON200.SpecJsonSchema == nil || *resp.JSON200.SpecJsonSchema == "" { |
| 230 | log.Info().Str("name", name).Msg("Hub did not return a spec schema, skipping validation") |
| 231 | return nil |
| 232 | } |
| 233 | return validateSpecAgainstSchema(*resp.JSON200.SpecJsonSchema, spec) |
| 234 | } |
| 235 | |
| 236 | // splitHubPath parses a CloudQuery-registry path field ("team/name") into its parts. |
| 237 | func splitHubPath(p string) (team, name string, err error) { |
no test coverage detected