github.com/argoproj/argo-events@v1.9.1/pkg/apis/eventsource/v1alpha1/config.go (about)

     1  package v1alpha1
     2  
     3  import (
     4  	fmt "fmt"
     5  	"path"
     6  	"regexp"
     7  )
     8  
     9  type WatchPathConfig struct {
    10  	// Directory to watch for events
    11  	Directory string `json:"directory" protobuf:"bytes,1,opt,name=directory"`
    12  	// Path is relative path of object to watch with respect to the directory
    13  	Path string `json:"path,omitempty" protobuf:"bytes,2,opt,name=path"`
    14  	// PathRegexp is regexp of relative path of object to watch with respect to the directory
    15  	PathRegexp string `json:"pathRegexp,omitempty" protobuf:"bytes,3,opt,name=pathRegexp"`
    16  }
    17  
    18  // Validate validates WatchPathConfig
    19  func (c *WatchPathConfig) Validate() error {
    20  	if c.Directory == "" {
    21  		return fmt.Errorf("directory is required")
    22  	}
    23  	if !path.IsAbs(c.Directory) {
    24  		return fmt.Errorf("directory must be an absolute file path")
    25  	}
    26  	if c.Path == "" && c.PathRegexp == "" {
    27  		return fmt.Errorf("either path or pathRegexp must be specified")
    28  	}
    29  	if c.Path != "" && c.PathRegexp != "" {
    30  		return fmt.Errorf("path and pathRegexp cannot be specified together")
    31  	}
    32  	if c.Path != "" && path.IsAbs(c.Path) {
    33  		return fmt.Errorf("path must be a relative file path")
    34  	}
    35  	if c.PathRegexp != "" {
    36  		_, err := regexp.Compile(c.PathRegexp)
    37  		if err != nil {
    38  			return err
    39  		}
    40  	}
    41  	return nil
    42  }