Skip to content

Commit

Permalink
Introduce validate function on the right place (#209)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Hoppe <robert.hoppe@mail.schwarz>
  • Loading branch information
roberth1988 and Robert Hoppe committed Feb 25, 2024
1 parent 38a4c2d commit 7de209d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/services/iaas-api/v1alpha/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 iaas

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 7de209d

Please sign in to comment.