Skip to content

Commit

Permalink
Introduce for client the network name validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Hoppe committed Feb 25, 2024
1 parent b55fb13 commit 8155110
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions internal/config/iaas/v1alpha/include/network/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// this file is used for validating network data and properties

package network

import (
"fmt"
"regexp"
)

// ValidateNetworkName validates a given network name
func ValidateNetworkName(name string) error {
if len(name) > 63 || name == "" {
return fmt.Errorf("name bust be non-empty and < 64 characters")
}

exp := `^[A-Za-z0-9]+((-|_|\s|\.)[A-Za-z0-9]+)*$`
r := regexp.MustCompile(exp)
if !r.MatchString(name) {
return fmt.Errorf("invalid cluster name. valid name is of: %s", exp)
}
return nil
}

0 comments on commit 8155110

Please sign in to comment.