2022-12-08 20:05:57 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"regexp"
|
|
|
|
)
|
|
|
|
|
2023-03-07 04:54:50 +08:00
|
|
|
var (
|
2023-05-17 22:58:03 +08:00
|
|
|
errInvalidExtClientPubKey = errors.New("incorrect ext client public key")
|
|
|
|
errInvalidExtClientID = errors.New("ext client ID must be alphanumderic and/or dashes and less that 15 chars")
|
|
|
|
errInvalidExtClientExtraIP = errors.New("ext client extra ip must be a valid cidr")
|
|
|
|
errInvalidExtClientDNS = errors.New("ext client dns must be a valid ip address")
|
2023-08-01 22:50:43 +08:00
|
|
|
errDuplicateExtClientName = errors.New("duplicate client name")
|
2023-03-07 04:54:50 +08:00
|
|
|
)
|
2022-12-08 20:05:57 +08:00
|
|
|
|
|
|
|
// allow only dashes and alphaneumeric for ext client and node names
|
|
|
|
func validName(name string) bool {
|
2023-05-17 22:58:03 +08:00
|
|
|
reg, err := regexp.Compile("^[a-zA-Z0-9-]+$")
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !reg.MatchString(name) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if len(name) > 15 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
2022-12-08 20:05:57 +08:00
|
|
|
}
|