Update profile name validation pattern. #8493
- prevents some incompatible characters from making their way into profile names and causing DNS/hostnames issuespull/8648/head
parent
2660b92109
commit
2cf72f7ca8
|
@ -84,13 +84,13 @@ func PrimaryControlPlane(cc *ClusterConfig) (Node, error) {
|
||||||
return cp, nil
|
return cp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProfileNameValid checks if the profile name is container name friendly
|
// ProfileNameValid checks if the profile name is container name and DNS hostname/label friendly.
|
||||||
func ProfileNameValid(name string) bool {
|
func ProfileNameValid(name string) bool {
|
||||||
|
// RestrictedNamePattern describes the characters allowed to represent a profile's name
|
||||||
|
const RestrictedNamePattern = `(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])`
|
||||||
|
|
||||||
// RestrictedNameChars collects the characters allowed to represent a name
|
var validName = regexp.MustCompile(`^` + RestrictedNamePattern + `$`)
|
||||||
const RestrictedNameChars = `[a-zA-Z0-9][a-zA-Z0-9_.-]`
|
|
||||||
|
|
||||||
var validName = regexp.MustCompile(`^` + RestrictedNameChars + `+$`)
|
|
||||||
return validName.MatchString(name)
|
return validName.MatchString(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,6 +181,7 @@ func SaveProfile(name string, cfg *ClusterConfig, miniHome ...string) error {
|
||||||
if err = os.Rename(tf.Name(), path); err != nil {
|
if err = os.Rename(tf.Name(), path); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue