MCPcopy Create free account
hub / github.com/cloudquery/cloudquery / validate

Method validate

cli/internal/specs/v0/spec_reader.go:209–246  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

207}
208
209func (r *SpecReader) validate() error {
210 if len(r.Sources) == 0 {
211 return errors.New("expecting at least one source")
212 }
213 if len(r.Destinations) == 0 {
214 return errors.New("expecting at least one destination")
215 }
216
217 // here we check if source with different versions use the same destination and error out if yes
218 var destinationSourceMap = make(map[string]string)
219 for _, source := range r.Sources {
220 for _, destination := range source.Destinations {
221 if r.destinationsMap[destination] == nil {
222 return fmt.Errorf("source %s references unknown destination %s", source.Name, destination)
223 }
224 destinationToSourceKey := fmt.Sprintf("%s-%s", destination, source.Path)
225 if destinationSourceMap[destinationToSourceKey] == "" {
226 destinationSourceMap[destinationToSourceKey] = source.Path + "@" + source.Version
227 } else if destinationSourceMap[destinationToSourceKey] != source.Path+"@"+source.Version {
228 return fmt.Errorf("destination %s is used by multiple sources %s with different versions", destination, source.Path)
229 }
230 }
231 }
232
233 var err error
234 for _, destination := range r.Destinations {
235 if destination.SyncGroupId != "" && destination.WriteMode == WriteModeOverwriteDeleteStale {
236 err = errors.Join(err, fmt.Errorf("destination %s: sync_group_id is not supported with write_mode: %s", destination.Name, destination.WriteMode))
237 }
238 for _, transformer := range destination.Transformers {
239 if r.transformersMap[transformer] == nil {
240 err = errors.Join(err, fmt.Errorf("destination %s references unknown transformer %s", destination.Name, transformer))
241 }
242 }
243 }
244
245 return err
246}
247
248func (r *SpecReader) relaxedValidate() error {
249 if len(r.Sources) == 0 && len(r.Destinations) == 0 {

Callers 2

NewSpecReaderFunction · 0.45

Calls 1

ErrorfMethod · 0.80

Tested by

no test coverage detected