added glob matching to auth middleware
This commit is contained in:
@@ -3,6 +3,8 @@ package hwsauth
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/gobwas/glob"
|
||||
)
|
||||
|
||||
// IgnorePaths excludes specified paths from authentication middleware.
|
||||
@@ -25,6 +27,19 @@ func (auth *Authenticator[T, TX]) IgnorePaths(paths ...string) error {
|
||||
return fmt.Errorf("Invalid path: '%s'", path)
|
||||
}
|
||||
}
|
||||
auth.ignoredPaths = paths
|
||||
auth.ignoredPaths = prepareGlobs(paths)
|
||||
return nil
|
||||
}
|
||||
|
||||
func prepareGlobs(paths []string) []glob.Glob {
|
||||
compiledGlobs := make([]glob.Glob, 0, len(paths))
|
||||
for _, pattern := range paths {
|
||||
g, err := glob.Compile(pattern)
|
||||
if err != nil {
|
||||
// If pattern fails to compile, skip it
|
||||
continue
|
||||
}
|
||||
compiledGlobs = append(compiledGlobs, g)
|
||||
}
|
||||
return compiledGlobs
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user