@@ -33,14 +33,14 @@ var (
3333 // GatewayEndpointRegex matches one or more word characters, optionally followed by dot-separated word segments
3434 GatewayEndpointRegex = `^\w+(\.\w+)*$`
3535
36- validateK8sResourceName = combineValidationFuncs (regex (k8sResourceNameRegex ), minLength ( 1 ) , maxLength (253 ))
37- validateVpcID = combineValidationFuncs (regex (VpcIDRegex ), maxLength (255 ))
36+ validateK8sResourceName = combineValidationFuncs (regex (k8sResourceNameRegex ), notEmpty , maxLength (253 ))
37+ validateVpcID = combineValidationFuncs (regex (VpcIDRegex ), notEmpty , maxLength (255 ))
3838 validateEipAllocationID = combineValidationFuncs (regex (EipAllocationIDRegex ), maxLength (255 ))
3939 validateSnapshotID = combineValidationFuncs (regex (SnapshotIDRegex ), maxLength (255 ))
40- validateIamInstanceProfileName = combineValidationFuncs (regex (IamInstanceProfileNameRegex ), minLength ( 1 ) , maxLength (128 ))
40+ validateIamInstanceProfileName = combineValidationFuncs (regex (IamInstanceProfileNameRegex ), notEmpty , maxLength (128 ))
4141 validateIamInstanceProfileArn = combineValidationFuncs (regex (IamInstanceProfileArnRegex ), maxLength (255 ))
4242 validateZoneName = combineValidationFuncs (regex (ZoneNameRegex ), maxLength (255 ))
43- validateTagKey = combineValidationFuncs (regex (TagKeyRegex ), minLength ( 1 ) , maxLength (128 ))
43+ validateTagKey = combineValidationFuncs (regex (TagKeyRegex ), notEmpty , maxLength (128 ))
4444 validateGatewayEndpointName = combineValidationFuncs (regex (GatewayEndpointRegex ), maxLength (255 ))
4545)
4646
@@ -72,22 +72,18 @@ func regex(regex string) validateFunc[string] {
7272 }
7373}
7474
75- // nolint:unparam
76- func minLength (min int ) validateFunc [string ] {
77- return func (name string , fld * field.Path ) field.ErrorList {
78- var allErrs field.ErrorList
79- if utf8 .RuneCountInString (name ) < min {
80- return field.ErrorList {field .Invalid (fld , name , fmt .Sprintf ("must not be fewer than %d characters, got %d" , min , len (name )))}
81- }
82- return allErrs
75+ func notEmpty (name string , fld * field.Path ) field.ErrorList {
76+ if utf8 .RuneCountInString (name ) == 0 {
77+ return field.ErrorList {field .Required (fld , "cannot be empty" )}
8378 }
79+ return nil
8480}
8581
8682func maxLength (max int ) validateFunc [string ] {
8783 return func (name string , fld * field.Path ) field.ErrorList {
8884 var allErrs field.ErrorList
89- if utf8 .RuneCountInString (name ) > max {
90- return field.ErrorList {field .Invalid (fld , name , fmt .Sprintf ("must not be more than %d characters, got %d" , max , len ( name ) ))}
85+ if l := utf8 .RuneCountInString (name ); l > max {
86+ return field.ErrorList {field .Invalid (fld , name , fmt .Sprintf ("must not be more than %d characters, got %d" , max , l ))}
9187 }
9288 return allErrs
9389 }
0 commit comments