Skip to content

Commit

Permalink
Revert "ROX-19609: add cluster name validation to infractl (#980)"
Browse files Browse the repository at this point in the history
This reverts commit 5128fa5.
  • Loading branch information
gavin-stackrox committed Sep 22, 2023
1 parent 24d14df commit b2f5dab
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 43 deletions.
26 changes: 1 addition & 25 deletions cmd/infractl/cluster/create/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,7 @@ func run(ctx context.Context, conn *grpc.ClientConn, cmd *cobra.Command, args []
displayUserNotes(cmd, args, &req)

if len(args) > 1 {
name := args[1]
err := validateName(name)
if err != nil {
return nil, err
}
req.Parameters["name"] = name
req.Parameters["name"] = args[1]
} else {
name, err := determineName(ctx, conn, args[0])
if err != nil {
Expand Down Expand Up @@ -151,25 +146,6 @@ func run(ctx context.Context, conn *grpc.ClientConn, cmd *cobra.Command, args []
return prettyResourceByID(*clusterID), nil
}

func validateName(name string) error {
if len(name) < 3 {
return errors.New("cluster name too short")
}
if len(name) > 28 {
return errors.New("cluster name too long")
}

match, err := regexp.MatchString(`^(?:[a-z](?:[-a-z0-9]{0,28}[a-z0-9])?)$`, name)
if err != nil {
return err
}
if !match {
return errors.New("The name does not match the requirements. Only lowercase letters, numbers, and '-' allowed, must start with a letter and end with a letter or number.")
}

return nil
}

func determineWorkingEnvironment() {
workingEnvironment.gitTopLevel = ""
workingEnvironment.tag = ""
Expand Down
18 changes: 0 additions & 18 deletions cmd/infractl/cluster/create/create.bats
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,6 @@ setup() {
assert_output --partial "parameter \"main-image\" was not provided"
}

@test "provided name failed validation because too short" {
run infractl create test-qa-demo ab
assert_failure
assert_output --partial "Error: cluster name too short"
}

@test "provided name failed validation because too long" {
run infractl create test-qa-demo this-name-will-be-too-loooooooooooooooooooong
assert_failure
assert_output --partial "Error: cluster name too long"
}

@test "provided name failed validation because does not match regex" {
run infractl create test-qa-demo THIS-IN-INVALID
assert_failure
assert_output --partial "Error: The name does not match the requirements."
}

infractl() {
"$ROOT"/bin/infractl -e localhost:8443 -k "$@"
}
Expand Down

0 comments on commit b2f5dab

Please sign in to comment.