diff --git a/internal/server/dash/web.go b/internal/server/dash/web.go index 0b908c0..48ac4b2 100644 --- a/internal/server/dash/web.go +++ b/internal/server/dash/web.go @@ -86,7 +86,7 @@ func (w *Web) Run() error { selector.NewSelectorMiddleware( selector.MatchFunc( ginx.MatchOperation( - authRoute, + authRoute.BasePath(), dashv1.MetadataAuthService[:], dashv1.OperationAuthServiceAuthLogin, ), diff --git a/pkg/server/ginx/metadata.go b/pkg/server/ginx/metadata.go index 332eb6c..2ba80c6 100644 --- a/pkg/server/ginx/metadata.go +++ b/pkg/server/ginx/metadata.go @@ -15,8 +15,8 @@ func metadataToMatches(base string, metadata ...[][3]string) map[string]map[stri return matches } -func MatchOperation(route gin.IRouter, metadata [][3]string, operations ...string) func(ctx *gin.Context) bool { - matches := metadataToMatches(route.Group("").BasePath(), metadata) +func MatchOperation(base string, metadata [][3]string, operations ...string) func(ctx *gin.Context) bool { + matches := metadataToMatches(base, metadata) opts := make(map[string]struct{}, len(operations)) for _, opt := range operations { opts[opt] = struct{}{} diff --git a/pkg/server/middleware/selector/selector.go b/pkg/server/middleware/selector/selector.go index 2bd8c52..bd027e5 100644 --- a/pkg/server/middleware/selector/selector.go +++ b/pkg/server/middleware/selector/selector.go @@ -26,15 +26,31 @@ func NewContextMatcher[T comparable](key string, value T) Matcher { }) } -func NewPathMatcher(path string) Matcher { +func NewLogicalNotMatcher(matcher Matcher) Matcher { return MatchFunc(func(ctx *gin.Context) bool { - return ctx.FullPath() == path + return !matcher.Match(ctx) }) } -func NewLogicalNotMatcher(matcher Matcher) Matcher { +func NewLogicalOrMatcher(matchers ...Matcher) Matcher { return MatchFunc(func(ctx *gin.Context) bool { - return !matcher.Match(ctx) + for _, m := range matchers { + if m.Match(ctx) { + return true + } + } + return false + }) +} + +func NewLogicalAndMatcher(matchers ...Matcher) Matcher { + return MatchFunc(func(ctx *gin.Context) bool { + for _, m := range matchers { + if !m.Match(ctx) { + return false + } + } + return true }) }