projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
10112: add Definition tab to workflow page
[arvados.git]
/
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 741e543850709ca1f075751597778e0e7ef769d0..9f92cd1b7213f5a720a771ae349fac7dd6558b39 100644
(file)
--- a/
services/arv-git-httpd/auth_handler.go
+++ b/
services/arv-git-httpd/auth_handler.go
@@
-3,7
+3,6
@@
package main
import (
"log"
"net/http"
import (
"log"
"net/http"
- "net/http/cgi"
"os"
"strings"
"sync"
"os"
"strings"
"sync"
@@
-14,22
+13,24
@@
import (
"git.curoverse.com/arvados.git/sdk/go/httpserver"
)
"git.curoverse.com/arvados.git/sdk/go/httpserver"
)
-func newArvadosClient() interface{} {
- arv, err := arvadosclient.MakeArvadosClient()
- if err != nil {
- log.Println("MakeArvadosClient:", err)
- return nil
- }
- return &arv
+type authHandler struct {
+ handler http.Handler
+ clientPool *arvadosclient.ClientPool
+ setupOnce sync.Once
}
}
-var connectionPool = &sync.Pool{New: newArvadosClient}
-
-type authHandler struct {
- handler *cgi.Handler
+func (h *authHandler) setup() {
+ ac, err := arvadosclient.New(&theConfig.Client)
+ if err != nil {
+ log.Fatal(err)
+ }
+ h.clientPool = &arvadosclient.ClientPool{Prototype: ac}
+ log.Printf("%+v", h.clientPool.Prototype)
}
func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
}
func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
+ h.setupOnce.Do(h.setup)
+
var statusCode int
var statusText string
var apiToken string
var statusCode int
var statusText string
var apiToken string
@@
-79,12
+80,12
@@
func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
repoName = pathParts[0]
repoName = strings.TrimRight(repoName, "/")
repoName = pathParts[0]
repoName = strings.TrimRight(repoName, "/")
- arv
, ok := connectionPool.Get().(*arvadosclient.ArvadosClient
)
- if
!ok ||
arv == nil {
- statusCode, statusText = http.StatusInternalServerError, "connection pool failed
"
+ arv
:= h.clientPool.Get(
)
+ if arv == nil {
+ statusCode, statusText = http.StatusInternalServerError, "connection pool failed
: "+h.clientPool.Err().Error()
return
}
return
}
- defer
connection
Pool.Put(arv)
+ defer
h.client
Pool.Put(arv)
// Ask API server whether the repository is readable using
// this token (by trying to read it!)
// Ask API server whether the repository is readable using
// this token (by trying to read it!)
@@
-140,7
+141,7
@@
func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
"/" + repoName + "/.git",
}
for _, dir := range tryDirs {
"/" + repoName + "/.git",
}
for _, dir := range tryDirs {
- if fileInfo, err := os.Stat(theConfig.Root + dir); err != nil {
+ if fileInfo, err := os.Stat(theConfig.R
epoR
oot + dir); err != nil {
if !os.IsNotExist(err) {
statusCode, statusText = http.StatusInternalServerError, err.Error()
return
if !os.IsNotExist(err) {
statusCode, statusText = http.StatusInternalServerError, err.Error()
return
@@
-152,7
+153,7
@@
func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
}
if rewrittenPath == "" {
log.Println("WARNING:", repoUUID,
}
if rewrittenPath == "" {
log.Println("WARNING:", repoUUID,
- "git directory not found in", theConfig.Root, tryDirs)
+ "git directory not found in", theConfig.R
epoR
oot, 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"
// 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"
@@
-160,7
+161,5
@@
func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
}
r.URL.Path = rewrittenPath
}
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)
}
}