Skip to content

Add validation for apigw creation with no routes#16649

Merged
missylbytes merged 14 commits into
mainfrom
add-checks-apigw-creation-no-routes
Mar 20, 2023
Merged

Add validation for apigw creation with no routes#16649
missylbytes merged 14 commits into
mainfrom
add-checks-apigw-creation-no-routes

Conversation

@missylbytes
Copy link
Copy Markdown
Contributor

@missylbytes missylbytes commented Mar 16, 2023

Description

To meet the standard (Gateways require at least one listener defined) we need to add checks in to verify that at least one listener is defined.

Testing & Reproduction steps

make dev-build 
consul agent -dev

Open another terminal, create a file called gateway.hcl with the following content:

Kind = "api-gateway"
Name = "my-gateway"

After creating the file, run the following command in the same terminal:

consul config write gateway.hcl

This should error out, saying "api gateway must have at least one listener"

PR Checklist

  • updated test coverage
  • external facing docs updated
  • not a security concern

Comment thread agent/structs/config_entry_gateways.go Outdated
}

if len(e.Listeners) == 0 {
return errors.New("api gateway must have at least one listener")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor (and more stylistic than anything and not blocking), would we want to use a sentinel error here so callers could act on the error type in the future?

Copy link
Copy Markdown
Contributor Author

@missylbytes missylbytes Mar 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I don't feel like that matches the way the other validations are handled, but I'm also realizing I didn't follow that way either. Ex: https://github.com/hashicorp/consul/blob/main/agent/structs/config_entry_gateways.go#L803
I do think that is probably a good idea for the future though

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially because I think it sends a 500 error back right now

@missylbytes missylbytes marked this pull request as ready for review March 16, 2023 18:42
@missylbytes missylbytes requested a review from a team as a code owner March 16, 2023 18:42
Copy link
Copy Markdown
Contributor

@t-eckert t-eckert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Would you mind just formatting the .mdx tables you added so the vertical bars align?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants