mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
Fix: restrict validation to RFC1123 label name
This commit is contained in:
+11
-6
@@ -31,6 +31,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var serviceIDRegexp = regexp.MustCompile("^[0-9a-f]{32}$")
|
var serviceIDRegexp = regexp.MustCompile("^[0-9a-f]{32}$")
|
||||||
|
var dnsLabelRegexp = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)
|
||||||
|
|
||||||
func ValidateServiceID(id string) bool {
|
func ValidateServiceID(id string) bool {
|
||||||
return serviceIDRegexp.MatchString(id)
|
return serviceIDRegexp.MatchString(id)
|
||||||
@@ -104,13 +105,17 @@ func (s *ServiceSpec) Validate() error {
|
|||||||
return fmt.Errorf("invalid mode: %q", s.Mode)
|
return fmt.Errorf("invalid mode: %q", s.Mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Name != "" {
|
func (s *ServiceSpec) Validate() error {
|
||||||
if len(s.Name) > 253 {
|
if s.Mode != "someExpectedMode" {
|
||||||
return fmt.Errorf("service name too long (max 253 characters): %q", s.Name)
|
return fmt.Errorf("invalid mode: %q", s.Mode)
|
||||||
}
|
}
|
||||||
dnsSubdomainRegexp := regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(?:\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`)
|
|
||||||
if !dnsSubdomainRegexp.MatchString(s.Name) {
|
if s.Name != "" {
|
||||||
return fmt.Errorf("invalid service name %q: must be a valid DNS subdomain", s.Name)
|
if len(s.Name) > 63 {
|
||||||
|
return fmt.Errorf("service name too long (max 63 characters): %q", s.Name)
|
||||||
|
}
|
||||||
|
if !dnsLabelRegexp.MatchString(s.Name) {
|
||||||
|
return fmt.Errorf("invalid service name: %q. Must comply with RFC 1123 label format", s.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user