mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
cli: fix invalid upper case name on AWS (#2546)
This commit is contained in:
parent
d67f1a035f
commit
eaec73cca4
@ -5,6 +5,10 @@ variable "name" {
|
||||
condition = length(var.name) <= 10
|
||||
error_message = "The length of the name of the Constellation must be <= 10 characters"
|
||||
}
|
||||
validation {
|
||||
condition = var.name == lower(var.name)
|
||||
error_message = "The name of the Constellation must be in lowercase"
|
||||
}
|
||||
}
|
||||
|
||||
variable "node_groups" {
|
||||
|
@ -728,7 +728,7 @@ func (c *Config) Validate(force bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validate.RegisterTranslation("valid_name", trans, registerValidateNameError, c.translateValidateNameError); err != nil {
|
||||
if err := validate.RegisterTranslation("valid_name", trans, c.registerValidateNameError, c.translateValidateNameError); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -421,6 +421,16 @@ func TestValidate(t *testing.T) {
|
||||
wantErr: true,
|
||||
wantErrCount: awsErrCount,
|
||||
},
|
||||
"AWS config with upper case name": {
|
||||
cnf: func() *Config {
|
||||
cnf := Default()
|
||||
cnf.RemoveProviderAndAttestationExcept(cloudprovider.AWS)
|
||||
cnf.Name = "testAWS"
|
||||
return cnf
|
||||
}(),
|
||||
wantErr: true,
|
||||
wantErrCount: awsErrCount + 1,
|
||||
},
|
||||
"AWS config with correct region and zone format": {
|
||||
cnf: func() *Config {
|
||||
cnf := Default()
|
||||
|
@ -711,7 +711,10 @@ func returnsTrue(_ validator.FieldLevel) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func registerValidateNameError(ut ut.Translator) error {
|
||||
func (c *Config) registerValidateNameError(ut ut.Translator) error {
|
||||
if c.Provider.AWS != nil {
|
||||
return ut.Add("validate_name", "{0} must be no more than {1} characters long and contain only lowercase letters", true)
|
||||
}
|
||||
return ut.Add("validate_name", "{0} must be no more than {1} characters long", true)
|
||||
}
|
||||
|
||||
@ -731,7 +734,8 @@ func (c *Config) translateValidateNameError(ut ut.Translator, fe validator.Field
|
||||
// This also allows us to eventually add more validation rules for constellation names if necessary.
|
||||
func (c *Config) validateName(fl validator.FieldLevel) bool {
|
||||
if c.Provider.AWS != nil {
|
||||
return len(fl.Field().String()) <= constants.AWSConstellationNameLength
|
||||
name := fl.Field().String()
|
||||
return strings.ToLower(name) == name && len(name) <= constants.AWSConstellationNameLength
|
||||
}
|
||||
return len(fl.Field().String()) <= constants.ConstellationNameLength
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user