1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00

fix(edgestack): validate edge stack name for api [BE-11365] (#222)

This commit is contained in:
Oscar Zhou 2024-12-11 08:21:46 +13:00 committed by GitHub
parent 05e872337a
commit 40c7742e46
6 changed files with 88 additions and 7 deletions

View file

@ -5,6 +5,7 @@ import (
"errors"
"strconv"
"strings"
"unicode"
)
// GetPortainerURLFromEdgeKey returns the portainer URL from an edge key
@ -28,3 +29,24 @@ func GetPortainerURLFromEdgeKey(edgeKey string) (string, error) {
return keyInfo[0], nil
}
// IsValidEdgeStackName validates an edge stack name
// Edge stack name must be between 1 and 255 characters long
// and can only contain lowercase letters, digits, hyphens and underscores
// Edge stack name must start with either a lowercase letter or a digit
func IsValidEdgeStackName(name string) bool {
if len(name) == 0 || len(name) > 255 {
return false
}
if !unicode.IsLower(rune(name[0])) && !unicode.IsDigit(rune(name[0])) {
return false
}
for _, r := range name {
if !(unicode.IsLower(r) || unicode.IsDigit(r) || r == '-' || r == '_') {
return false
}
}
return true
}