2ff6e05ffc
Permit integration - part 1 * WIP permit integration * slim down build * Merge branch 'main' of bitbucket.org:aarete/query-orchestration into feature/permit-integration-1 * omit swagger from auth * clean build * comment * part 1 completed this is the initial permitio parts and tests without integration. Also testing.md since we have a new test target `task test:permitio` * feature flag for no jwt validation * permit integration * fix ci unit tests * ci fix * build fix * fix home handler * fix redirect * test fix * update docs for auth
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package cognitoauth
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
// matchRoute determines if a request path matches a route pattern by converting
|
|
// Echo-style route patterns to regular expressions for matching.
|
|
//
|
|
// The function supports several pattern formats:
|
|
// - Exact path matching (e.g., "/users/profile")
|
|
// - Parameter patterns (e.g., "/users/:id" matches "/users/123")
|
|
// - Wildcard patterns (e.g., "/static/*" matches any path starting with "/static/")
|
|
//
|
|
// Parameters:
|
|
// - requestPath: The actual HTTP request path to check
|
|
// - routePattern: The Echo-style route pattern to match against
|
|
//
|
|
// Returns:
|
|
// - bool: true if the requestPath matches the routePattern, false otherwise
|
|
//
|
|
// Note that if the conversion of the route pattern to a regular expression fails,
|
|
// the function will return false.
|
|
func matchRoute(requestPath, routePattern string) bool {
|
|
// Convert Echo route pattern to regex pattern
|
|
// e.g., "/users/:id" to "/users/([^/]+)"
|
|
regexPattern := "^"
|
|
patternParts := strings.Split(routePattern, "/")
|
|
|
|
for i, part := range patternParts {
|
|
if i > 0 {
|
|
regexPattern += "/"
|
|
}
|
|
|
|
if strings.HasPrefix(part, ":") {
|
|
// Parameter part (e.g., :id)
|
|
regexPattern += "([^/]+)"
|
|
} else if part == "*" {
|
|
// Wildcard - match anything
|
|
regexPattern += ".*"
|
|
} else {
|
|
// Literal part - escape any regex metacharacters
|
|
regexPattern += regexp.QuoteMeta(part)
|
|
}
|
|
}
|
|
|
|
regexPattern += "$"
|
|
|
|
// Compile and match
|
|
regex, err := regexp.Compile(regexPattern)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
return regex.MatchString(requestPath)
|
|
}
|