Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TT-12865] Rename config parameter, update usage, support mux params on legacy #6506

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions cli/linter/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,10 @@
"enable_strict_routes": {
"type": "boolean"
},
"enable_prefix_matching": {
"enable_path_prefix_matching": {
"type": "boolean"
},
"enable_suffix_matching": {
"enable_path_suffix_matching": {
"type": "boolean"
},
"flush_interval": {
Expand Down
24 changes: 12 additions & 12 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ type HttpServerOptionsConfig struct {
// Regular expressions and parameterized routes will be left alone regardless of this setting.
EnableStrictRoutes bool `json:"enable_strict_routes"`

// EnablePrefixMatching changes the URL matching from wildcard mode to prefix mode.
// EnablePathPrefixMatching changes the URL matching from wildcard mode to prefix mode.
// For example, `/json` matches `*/json*` by current default behaviour.
// If prefix matching is enabled, the match will be performed as a prefix match (`/json*`).
//
Expand All @@ -423,16 +423,16 @@ type HttpServerOptionsConfig struct {
// - Full listen path and endpoint (`/listen-path/json`)
// - Stripped listen path (`/json`) - match.
//
// For inputs that start with `/`, a prefix match is ensured by prepending
// the start of string `^` caret.
// For inputs that start with `/`, a prefix match is ensured by
// prepending the start of string `^` caret.
//
// For all other cases, the pattern remains unmodified.
//
// Combine this option with EnableSuffixMatching to achieve strict
// url matching with `/json` being evaluated as `^/json$`.
EnablePrefixMatching bool `json:"enable_prefix_matching"`
// Combine this option with `enable_path_suffix_matching` to achieve
// exact url matching with `/json` being evaluated as `^/json$`.
EnablePathPrefixMatching bool `json:"enable_path_prefix_matching"`

// EnableSuffixMatching changes the URL matching to match as a suffix.
// EnablePathSuffixMatching changes the URL matching to match as a suffix.
// For example: `/json` is matched as `/json$` against the following paths:
//
// - Full listen path and versioning URL (`/listen-path/v4/json`)
Expand All @@ -444,12 +444,12 @@ type HttpServerOptionsConfig struct {
// - Full listen path and endpoint (`/listen-path/json`)
// - Stripped listen path (`/json`) - match.
//
// If the input pattern already ends with a `$` (`/json$`) then
// the pattern remains unmodified.
// If the input pattern already ends with a `$` (`/json$`)
// then the pattern remains unmodified.
//
// Combine this option with EnablePrefixMatching to achieve strict
// url matching with `/json` being evaluated as `^/json$`.
EnableSuffixMatching bool `json:"enable_suffix_matching"`
// Combine this option with `enable_path_prefix_matching` to achieve
// exact url matching with `/json` being evaluated as `^/json$`.
EnablePathSuffixMatching bool `json:"enable_path_suffix_matching"`

// Disable TLS verification. Required if you are using self-signed certificates.
SSLInsecureSkipVerify bool `json:"ssl_insecure_skip_verify"`
Expand Down
4 changes: 2 additions & 2 deletions gateway/api_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,8 @@ func (a APIDefinitionLoader) generateRegex(stringSpec string, newSpec *URLSpec,
err error
)
// Hook per-api settings here via newSpec *URLSpec
isPrefixMatch := conf.HttpServerOptions.EnablePrefixMatching
isSuffixMatch := conf.HttpServerOptions.EnableSuffixMatching
isPrefixMatch := conf.HttpServerOptions.EnablePathPrefixMatching
isSuffixMatch := conf.HttpServerOptions.EnablePathSuffixMatching
isIgnoreCase := newSpec.IgnoreCase || conf.IgnoreEndpointCase

pattern = httputil.PreparePathRegexp(stringSpec, isPrefixMatch, isSuffixMatch)
Expand Down
2 changes: 1 addition & 1 deletion gateway/api_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func TestConflictingPaths(t *testing.T) {

func TestIgnored(t *testing.T) {
ts := StartTest(func(c *config.Config) {
c.HttpServerOptions.EnablePrefixMatching = true
c.HttpServerOptions.EnablePathPrefixMatching = true
})
defer ts.Close()

Expand Down
12 changes: 3 additions & 9 deletions gateway/mw_granular_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func (m *GranularAccessMiddleware) ProcessRequest(w http.ResponseWriter, r *http
gwConfig := m.Gw.GetConfig()

// Hook per-api settings here (m.Spec...)
isPrefixMatch := gwConfig.HttpServerOptions.EnablePrefixMatching
isSuffixMatch := gwConfig.HttpServerOptions.EnableSuffixMatching
isPrefixMatch := gwConfig.HttpServerOptions.EnablePathPrefixMatching
isSuffixMatch := gwConfig.HttpServerOptions.EnablePathSuffixMatching

if isPrefixMatch {
urlPaths := []string{
Expand Down Expand Up @@ -97,13 +97,7 @@ func (m *GranularAccessMiddleware) ProcessRequest(w http.ResponseWriter, r *http
continue
}

pattern := accessSpec.URL

// Extends legacy by honoring isSuffixMatch.
// Append $ if so configured to match end of request path.
if isSuffixMatch && !strings.HasSuffix(pattern, "$") {
pattern += "$"
}
pattern := httputil.PreparePathRegexp(accessSpec.URL, false, isSuffixMatch)

logger.Debug("Checking: ", urlPath, " Against:", pattern)

Expand Down
2 changes: 1 addition & 1 deletion gateway/mw_granular_access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestGranularAccessMiddleware_ProcessRequest(t *testing.T) {
g := StartTest(func(c *config.Config) {
c.HttpServerOptions.EnablePrefixMatching = true
c.HttpServerOptions.EnablePathPrefixMatching = true
})
defer g.Close()

Expand Down
4 changes: 2 additions & 2 deletions gateway/session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ func (sfr sessionFailReason) String() string {

func (l *SessionLimiter) RateLimitInfo(r *http.Request, api *APISpec, endpoints user.Endpoints) (*user.EndpointRateLimitInfo, bool) {
// Hook per-api settings here (m.Spec...)
isPrefixMatch := l.config.HttpServerOptions.EnablePrefixMatching
isSuffixMatch := l.config.HttpServerOptions.EnableSuffixMatching
isPrefixMatch := l.config.HttpServerOptions.EnablePathPrefixMatching
isSuffixMatch := l.config.HttpServerOptions.EnablePathSuffixMatching

urlPaths := []string{
api.StripListenPath(r.URL.Path),
Expand Down
Loading