2023-06-21 12:31:33 +02:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/auth"
|
|
|
|
)
|
|
|
|
|
2023-06-21 12:58:43 +02:00
|
|
|
func AuthMiddleware(handlerFunc http.HandlerFunc, authProvider auth.AuthProvider) http.HandlerFunc {
|
2023-06-21 12:31:33 +02:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if authProvider.IsAllowed(r) {
|
|
|
|
handlerFunc.ServeHTTP(w, r)
|
|
|
|
} else {
|
|
|
|
w.WriteHeader(http.StatusUnauthorized)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|