mirror of
https://github.com/openziti/zrok.git
synced 2026-08-28 02:34:14 -05:00
32 lines
894 B
Go
32 lines
894 B
Go
package util
|
|
|
|
import (
|
|
"regexp"
|
|
|
|
goaway "github.com/TwiN/go-away"
|
|
)
|
|
|
|
// IsValidShareToken ensures that the string represents a valid unique name. Lowercase alphanumeric only. 3-32 characters.
|
|
func IsValidShareToken(uniqueName string, skipProfanityCheck bool) bool {
|
|
match, err := regexp.Match("^[a-z0-9-]{3,32}$", []byte(uniqueName))
|
|
if err != nil {
|
|
return false
|
|
}
|
|
if match && !skipProfanityCheck && goaway.IsProfane(uniqueName) {
|
|
return false
|
|
}
|
|
return match
|
|
}
|
|
|
|
// IsValidNameInNamespace ensures that the string represents a valid name in a namespace. Lowercase alphanumeric only. 3-64 characters.
|
|
func IsValidNameInNamespace(uniqueName string, skipProfanityCheck bool) bool {
|
|
match, err := regexp.Match("^[a-z0-9-]{3,63}$", []byte(uniqueName))
|
|
if err != nil {
|
|
return false
|
|
}
|
|
if match && !skipProfanityCheck && goaway.IsProfane(uniqueName) {
|
|
return false
|
|
}
|
|
return match
|
|
}
|