Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 6 additions & 9 deletions agent/consul/discoverychain/gateway_httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,14 @@ func httpRouteToDiscoveryChain(route structs.HTTPRouteConfigEntry) (*structs.Ser

for idx, rule := range route.Rules {
modifier := httpRouteFiltersToServiceRouteHeaderModifier(rule.Filters.Headers)
prefixRewrite := httpRouteFiltersToDestinationPrefixRewrite(rule.Filters.URLRewrites)
prefixRewrite := httpRouteFiltersToDestinationPrefixRewrite(rule.Filters.URLRewrite)

var destination structs.ServiceRouteDestination
if len(rule.Services) == 1 {
// TODO open question: is there a use case where someone might want to set the rewrite to ""?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎉

service := rule.Services[0]

servicePrefixRewrite := httpRouteFiltersToDestinationPrefixRewrite(service.Filters.URLRewrites)
if servicePrefixRewrite == "" {
servicePrefixRewrite := httpRouteFiltersToDestinationPrefixRewrite(service.Filters.URLRewrite)
if service.Filters.URLRewrite == nil {
servicePrefixRewrite = prefixRewrite
}
serviceModifier := httpRouteFiltersToServiceRouteHeaderModifier(service.Filters.Headers)
Expand Down Expand Up @@ -176,11 +175,9 @@ func httpRouteToDiscoveryChain(route structs.HTTPRouteConfigEntry) (*structs.Ser
return router, splitters, defaults
}

func httpRouteFiltersToDestinationPrefixRewrite(rewrites []structs.URLRewrite) string {
for _, rewrite := range rewrites {
if rewrite.Path != "" {
return rewrite.Path
}
func httpRouteFiltersToDestinationPrefixRewrite(rewrite *structs.URLRewrite) string {
if rewrite != nil && rewrite.Path != "" {
return rewrite.Path
}
return ""
Comment thread
andrewstucki marked this conversation as resolved.
Outdated
}
Expand Down
15 changes: 5 additions & 10 deletions agent/structs/config_entry_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,14 @@ func validateFilters(filter HTTPFilters) error {
}
}

for i, rewrite := range filter.URLRewrites {
if err := validateURLRewrite(rewrite); err != nil {
return fmt.Errorf("HTTPFilters, URLRewrite[%d], %w", i, err)
}
if err := validateURLRewrite(filter.URLRewrite); err != nil {
return fmt.Errorf("HTTPFilters, URLRewrite, %w", err)
}

return nil
}

func validateURLRewrite(rewrite URLRewrite) error {
func validateURLRewrite(rewrite *URLRewrite) error {
// TODO: we don't really have validation of the actual params
// passed as "PrefixRewrite" in our discoverychain config
// entries, figure out if we should have something here
Expand Down Expand Up @@ -403,8 +401,8 @@ type HTTPQueryMatch struct {
// HTTPFilters specifies a list of filters used to modify a request
// before it is routed to an upstream.
type HTTPFilters struct {
Headers []HTTPHeaderFilter
URLRewrites []URLRewrite
Headers []HTTPHeaderFilter
URLRewrite *URLRewrite
}

// HTTPHeaderFilter specifies how HTTP headers should be modified.
Expand Down Expand Up @@ -554,9 +552,6 @@ func (e *TCPRouteConfigEntry) CanWrite(authz acl.Authorizer) error {
// TCPService is a service reference for a TCPRoute
type TCPService struct {
Name string
// Weight specifies the proportion of requests forwarded to the referenced service.
// This is computed as weight/(sum of all weights in the list of services).
Weight int

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎉


acl.EnterpriseMeta
}
Expand Down
12 changes: 6 additions & 6 deletions agent/structs/structs.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ func (o *HTTPRouteConfigEntry) DeepCopy() *HTTPRouteConfigEntry {
}
}
}
if o.Rules[i2].Filters.URLRewrites != nil {
cp.Rules[i2].Filters.URLRewrites = make([]URLRewrite, len(o.Rules[i2].Filters.URLRewrites))
copy(cp.Rules[i2].Filters.URLRewrites, o.Rules[i2].Filters.URLRewrites)
if o.Rules[i2].Filters.URLRewrite != nil {
cp.Rules[i2].Filters.URLRewrite = new(URLRewrite)
*cp.Rules[i2].Filters.URLRewrite = *o.Rules[i2].Filters.URLRewrite
}
if o.Rules[i2].Matches != nil {
cp.Rules[i2].Matches = make([]HTTPMatch, len(o.Rules[i2].Matches))
Expand Down Expand Up @@ -373,9 +373,9 @@ func (o *HTTPRouteConfigEntry) DeepCopy() *HTTPRouteConfigEntry {
}
}
}
if o.Rules[i2].Services[i4].Filters.URLRewrites != nil {
cp.Rules[i2].Services[i4].Filters.URLRewrites = make([]URLRewrite, len(o.Rules[i2].Services[i4].Filters.URLRewrites))
copy(cp.Rules[i2].Services[i4].Filters.URLRewrites, o.Rules[i2].Services[i4].Filters.URLRewrites)
if o.Rules[i2].Services[i4].Filters.URLRewrite != nil {
cp.Rules[i2].Services[i4].Filters.URLRewrite = new(URLRewrite)
*cp.Rules[i2].Services[i4].Filters.URLRewrite = *o.Rules[i2].Services[i4].Filters.URLRewrite
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions api/config_entry_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ func (a *TCPRouteConfigEntry) GetModifyIndex() uint64 { return a.ModifyIndex
// TCPService is a service reference for a TCPRoute
type TCPService struct {
Name string
// Weight specifies the proportion of requests forwarded to the referenced service.
// This is computed as weight/(sum of all weights in the list of services).
Weight int

// Partition is the partition the config entry is associated with.
// Partitioning is a Consul Enterprise feature.
Expand Down Expand Up @@ -195,8 +192,8 @@ type HTTPQueryMatch struct {
// HTTPFilters specifies a list of filters used to modify a request
// before it is routed to an upstream.
type HTTPFilters struct {
Headers []HTTPHeaderFilter
URLRewrites []URLRewrite
Headers []HTTPHeaderFilter
URLRewrite *URLRewrite
}

// HTTPHeaderFilter specifies how HTTP headers should be modified.
Expand Down
26 changes: 8 additions & 18 deletions proto/private/pbconfigentry/config_entry.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading