github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/pkg/inspector/rule/executable.go (about) 1 package rule 2 3 import ( 4 "errors" 5 "fmt" 6 "regexp" 7 ) 8 9 // ExecutableInPath is a rule that ensures the given executable is in 10 // the system's path 11 type ExecutableInPath struct { 12 Meta 13 Executable string 14 } 15 16 // Name is the name of the rule 17 func (e ExecutableInPath) Name() string { 18 return fmt.Sprintf("Executable In Path: %s", e.Executable) 19 } 20 21 // IsRemoteRule returns true if the rule is to be run from outside of the node 22 func (e ExecutableInPath) IsRemoteRule() bool { return false } 23 24 // Validate the rule 25 func (e ExecutableInPath) Validate() []error { 26 if e.Executable == "" { 27 return []error{errors.New("Executable cannot be empty")} 28 } 29 r := regexp.MustCompile("^[a-zA-Z-]+$") 30 if !r.MatchString(e.Executable) { 31 return []error{fmt.Errorf("Executable name %q is not valid. Name must match %s", e.Executable, r.String())} 32 } 33 return nil 34 }