From bd81427dd59bc9583634a1ee51c93dca8694c0b6 Mon Sep 17 00:00:00 2001 From: Samir Patel <48686912+54mir@users.noreply.github.com> Date: Mon, 13 Dec 2021 23:10:04 -0600 Subject: [PATCH] load auth object into handler --- http/handler.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/http/handler.go b/http/handler.go index bdab80501..d03182e29 100644 --- a/http/handler.go +++ b/http/handler.go @@ -68,6 +68,8 @@ type Handler struct { middleware []func(http.Handler) http.Handler pprofCPUProfileBuffer *bytes.Buffer + + auth *auth.Auth } // externalPrefixFlag denotes endpoints that are intended to be exposed to clients. @@ -114,6 +116,13 @@ func OptHandlerAPI(api *pilosa.API) handlerOption { } } +func OptHandlerAuth(auth *auth.Auth) handlerOption { + return func(h *Handler) error { + h.auth = auth + return nil + } +} + func OptHandlerFileSystem(fs pilosa.FileSystem) handlerOption { return func(h *Handler) error { h.fileSystem = fs @@ -3357,15 +3366,22 @@ func (h *Handler) handlePostRestore(w http.ResponseWriter, r *http.Request) { } func (h *Handler) handleLogin(w http.ResponseWriter, r *http.Request) { - auth.Login(w, r) + h.logger.Infof("Handle Login Begin") + h.logger.Infof("Handler: %+v", h) + tst := h.auth + _ = tst + h.logger.Infof("Accessing Auth") + + h.auth.Login(w, r) + h.logger.Infof("Handle Login End") } func (h *Handler) handleRedirect(w http.ResponseWriter, r *http.Request) { - auth.Redirect(w, r) + h.auth.Redirect(w, r) } func (h *Handler) handleCheckAuthentication(w http.ResponseWriter, r *http.Request) { - groups := auth.Authenticate(w, r) + groups := h.auth.Authenticate(w, r) if groups == nil { w.Header().Add("Content-Type", "text/plain") w.WriteHeader(http.StatusForbidden)