X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f96550cc40f340c79339338d1da81394bfcb64ad..8a704d9628a2731635d0d1cb96a85a83c0f79a13:/services/arv-git-httpd/auth_handler.go diff --git a/services/arv-git-httpd/auth_handler.go b/services/arv-git-httpd/auth_handler.go index 39a9098c52..bfdb3969d7 100644 --- a/services/arv-git-httpd/auth_handler.go +++ b/services/arv-git-httpd/auth_handler.go @@ -3,9 +3,9 @@ package main import ( "log" "net/http" - "net/http/cgi" "os" "strings" + "sync" "time" "git.curoverse.com/arvados.git/sdk/go/arvadosclient" @@ -13,13 +13,25 @@ import ( "git.curoverse.com/arvados.git/sdk/go/httpserver" ) -var clientPool = arvadosclient.MakeClientPool() - type authHandler struct { - handler *cgi.Handler + handler http.Handler + clientPool *arvadosclient.ClientPool + setupOnce sync.Once +} + +func (h *authHandler) setup() { + os.Setenv("ARVADOS_API_HOST", theConfig.Client.APIHost) + if theConfig.Client.Insecure { + os.Setenv("ARVADOS_API_HOST_INSECURE", "1") + } else { + os.Setenv("ARVADOS_API_HOST_INSECURE", "") + } + h.clientPool = arvadosclient.MakeClientPool() } func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) { + h.setupOnce.Do(h.setup) + var statusCode int var statusText string var apiToken string @@ -69,12 +81,12 @@ func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) { repoName = pathParts[0] repoName = strings.TrimRight(repoName, "/") - arv := clientPool.Get() + arv := h.clientPool.Get() if arv == nil { - statusCode, statusText = http.StatusInternalServerError, "connection pool failed: "+clientPool.Err().Error() + statusCode, statusText = http.StatusInternalServerError, "connection pool failed: "+h.clientPool.Err().Error() return } - defer clientPool.Put(arv) + defer h.clientPool.Put(arv) // Ask API server whether the repository is readable using // this token (by trying to read it!) @@ -130,7 +142,7 @@ func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) { "/" + repoName + "/.git", } for _, dir := range tryDirs { - if fileInfo, err := os.Stat(theConfig.Root + dir); err != nil { + if fileInfo, err := os.Stat(theConfig.RepoRoot + dir); err != nil { if !os.IsNotExist(err) { statusCode, statusText = http.StatusInternalServerError, err.Error() return @@ -142,7 +154,7 @@ func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) { } if rewrittenPath == "" { log.Println("WARNING:", repoUUID, - "git directory not found in", theConfig.Root, tryDirs) + "git directory not found in", theConfig.RepoRoot, tryDirs) // We say "content not found" to disambiguate from the // earlier "API says that repo does not exist" error. statusCode, statusText = http.StatusNotFound, "content not found" @@ -150,7 +162,5 @@ func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) { } r.URL.Path = rewrittenPath - handlerCopy := *h.handler - handlerCopy.Env = append(handlerCopy.Env, "REMOTE_USER="+r.RemoteAddr) // Should be username - handlerCopy.ServeHTTP(&w, r) + h.handler.ServeHTTP(&w, r) }