Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/lib/configreader/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
ErrLeadingWhitespace = "configreader.leading_whitespace"
ErrTrailingWhitespace = "configreader.trailing_whitespace"
ErrAlphaNumericDashUnderscore = "configreader.alpha_numeric_dash_underscore"
ErrAlphaNumericDash = "configreader.alpha_numeric_dash"
ErrAlphaNumericDotUnderscore = "configreader.alpha_numeric_dot_underscore"
ErrAlphaNumericDashDotUnderscore = "configreader.alpha_numeric_dash_dot_underscore"
ErrInvalidAWSTag = "configreader.invalid_aws_tag"
Expand Down Expand Up @@ -140,6 +141,13 @@ func ErrorAlphaNumericDashUnderscore(provided string) error {
})
}

func ErrorAlphaNumericDash(provided string) error {
return errors.WithStack(&errors.Error{
Kind: ErrAlphaNumericDash,
Message: fmt.Sprintf("%s must contain only letters, numbers, and dashes", s.UserStr(provided)),
})
}

func ErrorAlphaNumericDotUnderscore(provided string) error {
return errors.WithStack(&errors.Error{
Kind: ErrAlphaNumericDotUnderscore,
Expand Down
7 changes: 7 additions & 0 deletions pkg/lib/configreader/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type StringValidation struct {
AlphaNumericDashUnderscoreOrEmpty bool
AlphaNumericDashUnderscore bool
AlphaNumericDotUnderscore bool
AlphaNumericDash bool
AWSTag bool
DNS1035 bool
DNS1123 bool
Expand Down Expand Up @@ -334,6 +335,12 @@ func ValidateStringVal(val string, v *StringValidation) error {
}
}

if v.AlphaNumericDash {
if !regex.IsAlphaNumericDash(val) {
return ErrorAlphaNumericDash(val)
}
}

if v.AlphaNumericDashUnderscoreOrEmpty {
if !regex.IsAlphaNumericDashUnderscore(val) && val != "" {
return ErrorAlphaNumericDashUnderscore(val)
Expand Down
6 changes: 6 additions & 0 deletions pkg/lib/regex/regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ func IsAlphaNumericDotUnderscore(s string) bool {
return _alphaNumericDotUnderscoreRegex.MatchString(s)
}

var _alphaNumericDashRegex = regexp.MustCompile(`^[a-zA-Z0-9\-]+$`)

func IsAlphaNumericDash(s string) bool {
return _alphaNumericDashRegex.MatchString(s)
}

// used the evaluated form of
// https://github.com/docker/distribution/blob/3150937b9f2b1b5b096b2634d0e7c44d4a0f89fb/reference/regexp.go#L68-L70
var _dockerValidImage = regexp.MustCompile(
Expand Down
6 changes: 3 additions & 3 deletions pkg/types/clusterconfig/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,9 @@ var nodeGroupsFieldValidation *cr.StructValidation = &cr.StructValidation{
{
StructField: "Name",
StringValidation: &cr.StringValidation{
Required: true,
AlphaNumericDashUnderscore: true,
MaxLength: _maxNodeGroupLength,
Required: true,
AlphaNumericDash: true,
MaxLength: _maxNodeGroupLength,
},
},
{
Expand Down
4 changes: 4 additions & 0 deletions pkg/types/clusterstate/clusterstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,13 @@ func GetClusterState(stacks ClusterStacks) State {
}

if slices.HasString([]string{
cloudformation.StackStatusCreateInProgress,
cloudformation.StackStatusCreateComplete,
cloudformation.StackStatusUpdateInProgress,
cloudformation.StackStatusUpdateComplete,
cloudformation.StackStatusRollbackInProgress,
cloudformation.StackStatusRollbackComplete,
cloudformation.StackStatusUpdateRollbackInProgress,
cloudformation.StackStatusUpdateRollbackComplete,
}, controlPlaneStatus) {
return StateClusterExists
Expand Down