github.com/saucelabs/saucectl@v0.175.1/internal/imagerunner/utils.go (about) 1 package imagerunner 2 3 import ( 4 "regexp" 5 "strings" 6 ) 7 8 func GetCanonicalServiceName(serviceName string) string { 9 serviceName = strings.TrimSpace(serviceName) 10 if serviceName == "" { 11 return "" 12 } 13 // make sure the service name has only lowercase letters, numbers, and underscores 14 canonicalName := strings.ToLower(regexp.MustCompile("[^a-zA-Z0-9-]").ReplaceAllString(serviceName, "-")) 15 // remove successives dashes 16 canonicalName = regexp.MustCompile("-+").ReplaceAllString(canonicalName, "-") 17 // avoids container names starting with dash 18 canonicalName = regexp.MustCompile("^-").ReplaceAllString(canonicalName, "s-") 19 return canonicalName 20 }