Skip to content

Commit

Permalink
ensure route parents are unique when creating an http route
Browse files Browse the repository at this point in the history
  • Loading branch information
jm96441n committed Apr 7, 2023
1 parent 430df05 commit 7a3d2d8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions agent/structs/config_entry_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package structs

import (
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -143,10 +144,16 @@ func (e *HTTPRouteConfigEntry) Validate() error {
APIGateway: true,
}

uniques := make(map[ResourceReference]struct{}, len(e.Parents))

for _, parent := range e.Parents {
if !validParentKinds[parent.Kind] {
return fmt.Errorf("unsupported parent kind: %q, must be 'api-gateway'", parent.Kind)
}
if _, ok := uniques[parent]; ok {
return errors.New("route parents must be unique")
}
uniques[parent] = struct{}{}
}

if err := validateConfigEntryMeta(e.Meta); err != nil {
Expand Down

0 comments on commit 7a3d2d8

Please sign in to comment.