in internal/client/integrations/integrations.go [1291:1364]
func Import(folder string, numConnections int) (err error) {
var fileNames []string
rIntegrationFlowFiles := regexp.MustCompile(`[\w|-]+\+[0-9]+\+[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}\.json`)
apiclient.ClientPrintHttpResponse.Set(false)
defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())
err = filepath.Walk(folder, func(path string, info os.FileInfo, err error) error {
if err != nil {
clilog.Warning.Println("integration folder not found")
return nil
}
if info.IsDir() {
return nil
}
if filepath.Ext(path) != ".json" {
return nil
}
fileName := filepath.Base(path)
if ok := rIntegrationFlowFiles.Match([]byte(fileName)); ok {
fileNames = append(fileNames, path)
}
return nil
})
if err != nil {
return err
}
numEntities := len(fileNames)
clilog.Info.Printf("Found %d Integration Versions in the folder\n", numEntities)
clilog.Debug.Printf("Importing versions with %d connections\n", numConnections)
errChan := make(chan error)
workChan := make(chan string, numEntities)
fanOutWg := sync.WaitGroup{}
fanInWg := sync.WaitGroup{}
errs := []string{}
fanInWg.Add(1)
go func() {
defer fanInWg.Done()
for {
newErr, ok := <-errChan
if !ok {
return
}
errs = append(errs, newErr.Error())
}
}()
for i := 0; i < numConnections; i++ {
fanOutWg.Add(1)
go importWorker(&fanOutWg, workChan, folder, numConnections, errChan)
}
for _, fileName := range fileNames {
workChan <- fileName
}
close(workChan)
fanOutWg.Wait()
close(errChan)
fanInWg.Wait()
if len(errs) > 0 {
return errors.New(strings.Join(errs, "\n"))
}
return nil
}