func processEndpoints()

in internal/cmd/integrations/apply.go [274:314]


func processEndpoints(endpointsFolder string) (err error) {
	var stat fs.FileInfo
	rJSONFiles := regexp.MustCompile(`(\S*)\.json`)

	if stat, err = os.Stat(endpointsFolder); err == nil && stat.IsDir() {
		// create any endpoint attachments
		err = filepath.Walk(endpointsFolder, func(path string, info os.FileInfo, err error) error {
			if err != nil {
				return err
			}
			if !info.IsDir() {
				endpointFile := filepath.Base(path)
				if rJSONFiles.MatchString(endpointFile) {
					clilog.Info.Printf("Found configuration for endpoint attachment: %s\n", endpointFile)
				}
				if !connections.FindEndpoint(getFilenameWithoutExtension(endpointFile)) {
					// the endpoint does not exist, try to create it
					endpointBytes, err := utils.ReadFile(path)
					if err != nil {
						return err
					}
					serviceAccountName, err := getServiceAttachment(endpointBytes)
					if err != nil {
						return err
					}
					if _, err = connections.CreateEndpoint(getFilenameWithoutExtension(endpointFile),
						serviceAccountName, "", false); err != nil {
						return err
					}
				} else {
					clilog.Info.Printf("Endpoint %s already exists\n", endpointFile)
				}
			}
			return nil
		})
		if err != nil {
			return err
		}
	}
	return nil
}