Merge pull request #9367 from medyagh/pname_length
don't allow profile name to be less than 2 characterspull/9401/head
commit
5614ed0edc
|
@ -155,7 +155,7 @@ func runStart(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
if !config.ProfileNameValid(ClusterFlagValue()) {
|
if !config.ProfileNameValid(ClusterFlagValue()) {
|
||||||
out.WarningT("Profile name '{{.name}}' is not valid", out.V{"name": ClusterFlagValue()})
|
out.WarningT("Profile name '{{.name}}' is not valid", out.V{"name": ClusterFlagValue()})
|
||||||
exit.Message(reason.Usage, "Only alphanumeric and dashes '-' are permitted. Minimum 1 character, starting with alphanumeric.")
|
exit.Message(reason.Usage, "Only alphanumeric and dashes '-' are permitted. Minimum 2 characters, starting with alphanumeric.")
|
||||||
}
|
}
|
||||||
|
|
||||||
existing, err := config.Load(ClusterFlagValue())
|
existing, err := config.Load(ClusterFlagValue())
|
||||||
|
|
|
@ -90,8 +90,8 @@ func ProfileNameValid(name string) bool {
|
||||||
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])`
|
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])`
|
||||||
|
|
||||||
var validName = regexp.MustCompile(`^` + RestrictedNamePattern + `$`)
|
var validName = regexp.MustCompile(`^` + RestrictedNamePattern + `$`)
|
||||||
|
// length needs to be more than 1 character because docker volume #9366
|
||||||
return validName.MatchString(name)
|
return validName.MatchString(name) && len(name) > 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProfileNameInReservedKeywords checks if the profile is an internal keywords
|
// ProfileNameInReservedKeywords checks if the profile is an internal keywords
|
||||||
|
|
|
@ -80,10 +80,11 @@ func TestProfileNameValid(t *testing.T) {
|
||||||
"pro-file1": true,
|
"pro-file1": true,
|
||||||
"1st-profile": true,
|
"1st-profile": true,
|
||||||
"1st-2nd-3rd-profile": true,
|
"1st-2nd-3rd-profile": true,
|
||||||
"n": true,
|
|
||||||
"1": true,
|
|
||||||
"12567": true,
|
"12567": true,
|
||||||
|
"111": true,
|
||||||
|
|
||||||
|
"1": false,
|
||||||
|
"n": false,
|
||||||
"pro file": false,
|
"pro file": false,
|
||||||
"pro-file-": false,
|
"pro-file-": false,
|
||||||
"-profile": false,
|
"-profile": false,
|
||||||
|
|
Loading…
Reference in New Issue