11c4b26c0b
* Move code setting up the HTTP server to it's own package * This helps clean up the `main` function and make it easier to read * Rename the `BasicAuthMiddleware` to remove reference to Basic since it can now handle any type of auth type https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/-/merge_requests/90
18 lines
384 B
Go
18 lines
384 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/auth"
|
|
)
|
|
|
|
func AuthMiddleware(handlerFunc http.HandlerFunc, authProvider auth.AuthProvider) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if authProvider.IsAllowed(r) {
|
|
handlerFunc.ServeHTTP(w, r)
|
|
} else {
|
|
w.WriteHeader(http.StatusUnauthorized)
|
|
}
|
|
}
|
|
}
|