forked from baron/baron-sso
3단계 권한 모델 확장, keto 권한 정책
This commit is contained in:
52
backend/internal/utils/slug.go
Normal file
52
backend/internal/utils/slug.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
slugRegex = regexp.MustCompile(`^[a-z0-9-]+$`)
|
||||
reservedSlugs = map[string]bool{
|
||||
"admin": true,
|
||||
"api": true,
|
||||
"auth": true,
|
||||
"system": true,
|
||||
"root": true,
|
||||
"super": true,
|
||||
"public": true,
|
||||
"internal": true,
|
||||
"baron": true,
|
||||
"sso": true,
|
||||
"login": true,
|
||||
"logout": true,
|
||||
"signup": true,
|
||||
"register": true,
|
||||
"tenant": true,
|
||||
"user": true,
|
||||
"dev": true,
|
||||
}
|
||||
)
|
||||
|
||||
// ValidateSlug checks if a slug meets requirements and is not reserved.
|
||||
func ValidateSlug(slug string) (bool, string) {
|
||||
s := strings.ToLower(strings.TrimSpace(slug))
|
||||
|
||||
if len(s) < 3 || len(s) > 32 {
|
||||
return false, "slug must be between 3 and 32 characters"
|
||||
}
|
||||
|
||||
if !slugRegex.MatchString(s) {
|
||||
return false, "slug can only contain lowercase letters, numbers, and hyphens"
|
||||
}
|
||||
|
||||
if strings.HasPrefix(s, "-") || strings.HasSuffix(s, "-") {
|
||||
return false, "slug cannot start or end with a hyphen"
|
||||
}
|
||||
|
||||
if reservedSlugs[s] {
|
||||
return false, "slug is a reserved keyword"
|
||||
}
|
||||
|
||||
return true, ""
|
||||
}
|
||||
Reference in New Issue
Block a user