MCPcopy Index your code
hub / github.com/cloudquery/cloudquery / validateConfig

Function validateConfig

cli/cmd/validate_config.go:58–211  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

56}
57
58func validateConfig(cmd *cobra.Command, args []string) error {
59 cqDir, err := cmd.Flags().GetString("cq-dir")
60 if err != nil {
61 return err
62 }
63 licenseFile, err := cmd.Flags().GetString("license")
64 if err != nil {
65 return err
66 }
67
68 ctx := cmd.Context()
69
70 log.Info().Strs("args", args).Msg("Loading spec(s)")
71 fmt.Printf("Loading spec(s) from %s\n", strings.Join(args, ", "))
72 specReader, err := specs.NewSpecReader(args)
73 if err != nil {
74 return fmt.Errorf("failed to load spec(s) from %s. Error: %w", strings.Join(args, ", "), err)
75 }
76 sources := specReader.Sources
77 destinations := specReader.Destinations
78
79 authToken, err := auth.GetAuthTokenIfNeeded(log.Logger, sources, destinations, nil)
80 if err != nil {
81 return fmt.Errorf("failed to get auth token: %w", err)
82 }
83
84 apiClient, err := api.NewClient(authToken.Value)
85 if err != nil {
86 return fmt.Errorf("failed to create Hub API client: %w", err)
87 }
88
89 // Partition entries: CloudQuery-registry plugins fetch their schema from the
90 // Hub API; all other registries fall through to the original plugin-spawn path.
91 sourcePluginConfigs := make([]managedplugin.Config, 0, len(sources))
92 sourceRegInferred := make([]bool, 0, len(sources))
93 sourceSpawnIdx := make([]int, 0, len(sources))
94 destinationPluginConfigs := make([]managedplugin.Config, 0, len(destinations))
95 destinationRegInferred := make([]bool, 0, len(destinations))
96 destinationSpawnIdx := make([]int, 0, len(destinations))
97
98 var initErrors []error
99
100 useHubAPI := licenseFile == ""
101 for i, source := range sources {
102 if useHubAPI && source.Registry == specs.RegistryCloudQuery {
103 if err := validateViaHubAPI(ctx, apiClient, source.Path, cloudquery_api.PluginKindSource, source.Version, source.Spec); err != nil {
104 initErrors = append(initErrors, fmt.Errorf("failed to validate source config %v: %w", source.VersionString(), err))
105 } else {
106 log.Info().Str("source", source.VersionString()).Msg("validated successfully")
107 }
108 continue
109 }
110 sourcePluginConfigs = append(sourcePluginConfigs, managedplugin.Config{
111 Name: source.Name,
112 Version: source.Version,
113 Path: source.Path,
114 Registry: SpecRegistryToPlugin(source.Registry),
115 DockerAuth: source.DockerRegistryAuthToken,

Callers

nothing calls this directly

Calls 10

validateViaHubAPIFunction · 0.85
SpecRegistryToPluginFunction · 0.85
enrichClientErrorFunction · 0.85
validatePluginSpecFunction · 0.85
PrintfMethod · 0.80
ErrorfMethod · 0.80
VersionStringMethod · 0.80
RegistryInferredMethod · 0.80
PrintlnMethod · 0.80
ContextMethod · 0.45

Tested by

no test coverage detected