github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/providers/security/filesec/util.go (about) 1 // Copyright (c) 2020-2022, R.I. Pienaar and the Choria Project contributors 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 5 package filesec 6 7 import ( 8 "os" 9 "regexp" 10 "runtime" 11 "strings" 12 ) 13 14 // MatchAnyRegex checks str against a list of possible regex, if any match true is returned 15 func MatchAnyRegex(str string, regex []string) bool { 16 matcher := regexp.MustCompile("^/.+/$") 17 18 for _, reg := range regex { 19 if matcher.MatchString(reg) { 20 reg = strings.TrimLeft(reg, "/") 21 reg = strings.TrimRight(reg, "/") 22 } 23 24 if matched, _ := regexp.MatchString(reg, str); matched { 25 return true 26 } 27 } 28 29 return false 30 } 31 32 func uid() int { 33 if useFakeUID { 34 return fakeUID 35 } 36 37 return os.Geteuid() 38 } 39 40 func runtimeOs() string { 41 if useFakeOS { 42 return fakeOS 43 } 44 45 return runtime.GOOS 46 }