[arvados] updated: 2.1.0-2868-g25162c18b

git repository hosting git at public.arvados.org
Mon Sep 12 20:33:09 UTC 2022


Summary of changes:
 services/keep-web/handler.go | 171 +++++++++++--------------------------------
 services/keep-web/main.go    |   4 -
 2 files changed, 44 insertions(+), 131 deletions(-)

       via  25162c18b4290f7763cd545f2d94d96650ebc9d9 (commit)
       via  bd387cabd3fb58e8456f38ba54bb4af0be6500bb (commit)
       via  94cf0f9216f09ae37e04686945ff2731bdc74db8 (commit)
      from  6b0d4ac8df4b5b4255eb56b1d76865f06089ca2a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 25162c18b4290f7763cd545f2d94d96650ebc9d9
Author: Tom Clegg <tom at curii.com>
Date:   Mon Sep 12 16:32:24 2022 -0400

    19362: Fix version in status response.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>

diff --git a/services/keep-web/handler.go b/services/keep-web/handler.go
index bc62a2a39..0e964e463 100644
--- a/services/keep-web/handler.go
+++ b/services/keep-web/handler.go
@@ -19,6 +19,7 @@ import (
 	"strings"
 	"sync"
 
+	"git.arvados.org/arvados.git/lib/cmd"
 	"git.arvados.org/arvados.git/sdk/go/arvados"
 	"git.arvados.org/arvados.git/sdk/go/arvadosclient"
 	"git.arvados.org/arvados.git/sdk/go/auth"
@@ -63,7 +64,7 @@ func (h *handler) setup() {
 }
 
 func (h *handler) serveStatus(w http.ResponseWriter, r *http.Request) {
-	json.NewEncoder(w).Encode(struct{ Version string }{version})
+	json.NewEncoder(w).Encode(struct{ Version string }{cmd.Version.String()})
 }
 
 // updateOnSuccess wraps httpserver.ResponseWriter. If the handler
diff --git a/services/keep-web/main.go b/services/keep-web/main.go
index 7a23cd1fa..cd379dc6b 100644
--- a/services/keep-web/main.go
+++ b/services/keep-web/main.go
@@ -16,10 +16,6 @@ import (
 	"github.com/prometheus/client_golang/prometheus"
 )
 
-var (
-	version = "dev"
-)
-
 var Command = service.Command(arvados.ServiceNameKeepweb, newHandlerOrErrorHandler)
 
 func newHandlerOrErrorHandler(ctx context.Context, cluster *arvados.Cluster, token string, reg *prometheus.Registry) service.Handler {

commit bd387cabd3fb58e8456f38ba54bb4af0be6500bb
Author: Tom Clegg <tom at curii.com>
Date:   Mon Sep 12 16:32:12 2022 -0400

    19362: Remove dead code.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>

diff --git a/services/keep-web/handler.go b/services/keep-web/handler.go
index 0eecb1af1..bc62a2a39 100644
--- a/services/keep-web/handler.go
+++ b/services/keep-web/handler.go
@@ -30,11 +30,10 @@ import (
 )
 
 type handler struct {
-	Cache      cache
-	Cluster    *arvados.Cluster
-	clientPool *arvadosclient.ClientPool
-	setupOnce  sync.Once
-	webdavLS   webdav.LockSystem
+	Cache     cache
+	Cluster   *arvados.Cluster
+	setupOnce sync.Once
+	webdavLS  webdav.LockSystem
 }
 
 var urlPDHDecoder = strings.NewReplacer(" ", "+", "-", "+")
@@ -56,10 +55,6 @@ func parseCollectionIDFromURL(s string) string {
 }
 
 func (h *handler) setup() {
-	// Errors will be handled at the client pool.
-	arv, _ := arvados.NewClientFromConfig(h.Cluster)
-	h.clientPool = arvadosclient.MakeClientPoolWith(arv)
-
 	keepclient.DefaultBlockCache.MaxBlocks = h.Cluster.Collections.WebDAVCache.MaxBlockEntries
 
 	// Even though we don't accept LOCK requests, every webdav
@@ -373,13 +368,6 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 		stripParts++
 	}
 
-	arv := h.clientPool.Get()
-	if arv == nil {
-		http.Error(w, "client pool error: "+h.clientPool.Err().Error(), http.StatusInternalServerError)
-		return
-	}
-	defer h.clientPool.Put(arv)
-
 	dirOpenMode := os.O_RDONLY
 	if writeMethod[r.Method] {
 		dirOpenMode = os.O_RDWR
@@ -597,28 +585,6 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 	}
 }
 
-func (h *handler) getClients(reqID, token string) (arv *arvadosclient.ArvadosClient, kc *keepclient.KeepClient, client *arvados.Client, release func(), err error) {
-	arv = h.clientPool.Get()
-	if arv == nil {
-		err = h.clientPool.Err()
-		return
-	}
-	release = func() { h.clientPool.Put(arv) }
-	arv.ApiToken = token
-	kc, err = keepclient.MakeKeepClient(arv)
-	if err != nil {
-		release()
-		return
-	}
-	kc.RequestID = reqID
-	client = (&arvados.Client{
-		APIHost:   arv.ApiServer,
-		AuthToken: arv.ApiToken,
-		Insecure:  arv.ApiInsecure,
-	}).WithRequestID(reqID)
-	return
-}
-
 var dirListingTemplate = `<!DOCTYPE HTML>
 <HTML><HEAD>
   <META name="robots" content="NOINDEX">

commit 94cf0f9216f09ae37e04686945ff2731bdc74db8
Author: Tom Clegg <tom at curii.com>
Date:   Mon Sep 12 16:09:20 2022 -0400

    19362: Merge serveSiteFS into main code path.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>

diff --git a/services/keep-web/handler.go b/services/keep-web/handler.go
index 7ac8bc02d..0eecb1af1 100644
--- a/services/keep-web/handler.go
+++ b/services/keep-web/handler.go
@@ -14,7 +14,6 @@ import (
 	"net/http"
 	"net/url"
 	"os"
-	"path/filepath"
 	"sort"
 	"strconv"
 	"strings"
@@ -274,11 +273,6 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 		}
 	}
 
-	if collectionID == "" && !useSiteFS {
-		http.Error(w, notFoundMessage, http.StatusNotFound)
-		return
-	}
-
 	forceReload := false
 	if cc := r.Header.Get("Cache-Control"); strings.Contains(cc, "no-cache") || strings.Contains(cc, "must-revalidate") {
 		forceReload = true
@@ -319,11 +313,6 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	if useSiteFS {
-		h.serveSiteFS(w, r, reqTokens, credentialsOK, attachment)
-		return
-	}
-
 	targetPath := pathParts[stripParts:]
 	if tokens == nil && len(targetPath) > 0 && strings.HasPrefix(targetPath[0], "t=") {
 		// http://ID.example/t=TOKEN/PATH...
@@ -338,6 +327,25 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 		stripParts++
 	}
 
+	fsprefix := ""
+	if useSiteFS {
+		if writeMethod[r.Method] {
+			http.Error(w, errReadOnly.Error(), http.StatusMethodNotAllowed)
+			return
+		}
+		if len(reqTokens) == 0 {
+			w.Header().Add("WWW-Authenticate", "Basic realm=\"collections\"")
+			http.Error(w, unauthorizedMessage, http.StatusUnauthorized)
+			return
+		}
+		tokens = reqTokens
+	} else if collectionID == "" {
+		http.Error(w, notFoundMessage, http.StatusNotFound)
+		return
+	} else {
+		fsprefix = "by_id/" + collectionID + "/"
+	}
+
 	if tokens == nil {
 		tokens = reqTokens
 		if h.Cluster.Users.AnonymousUserToken != "" {
@@ -393,7 +401,7 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 			http.Error(w, "cache error: "+err.Error(), http.StatusInternalServerError)
 			return
 		}
-		f, err := fs.OpenFile("by_id/"+collectionID, dirOpenMode, 0)
+		f, err := fs.OpenFile(fsprefix, dirOpenMode, 0)
 		if errors.As(err, &statusErr) && statusErr.HTTPStatus() == http.StatusForbidden {
 			// collection id is outside token scope
 			validToken[token] = true
@@ -485,12 +493,22 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 		return
 	}
 
+	if r.Method == http.MethodGet || r.Method == http.MethodHead {
+		targetfnm := fsprefix + strings.Join(pathParts[stripParts:], "/")
+		if fi, err := sessionFS.Stat(targetfnm); err == nil && fi.IsDir() {
+			if !strings.HasSuffix(r.URL.Path, "/") {
+				h.seeOtherWithCookie(w, r, r.URL.Path+"/", credentialsOK)
+			} else {
+				h.serveDirectory(w, r, fi.Name(), sessionFS, targetfnm, !useSiteFS)
+			}
+			return
+		}
+	}
+
 	var basename string
 	if len(targetPath) > 0 {
 		basename = targetPath[len(targetPath)-1]
 	}
-	applyContentDispositionHdr(w, r, basename, attachment)
-
 	if arvadosclient.PDHMatch(collectionID) && writeMethod[r.Method] {
 		http.Error(w, errReadOnly.Error(), http.StatusMethodNotAllowed)
 		return
@@ -499,7 +517,7 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 		http.Error(w, "Not permitted", http.StatusForbidden)
 		return
 	}
-	h.logUploadOrDownload(r, session.arvadosclient, sessionFS, "by_id/"+collectionID+"/"+strings.Join(targetPath, "/"), nil, tokenUser)
+	h.logUploadOrDownload(r, session.arvadosclient, sessionFS, fsprefix+strings.Join(targetPath, "/"), nil, tokenUser)
 
 	if writeMethod[r.Method] {
 		// Save the collection only if/when all
@@ -516,7 +534,7 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 		// subsequent read requests.
 		client := session.client.WithRequestID(r.Header.Get("X-Request-Id"))
 		sessionFS = client.SiteFileSystem(session.keepclient)
-		writingDir, err := sessionFS.OpenFile("by_id/"+collectionID, os.O_RDONLY, 0)
+		writingDir, err := sessionFS.OpenFile(fsprefix, os.O_RDONLY, 0)
 		if err != nil {
 			http.Error(w, err.Error(), http.StatusInternalServerError)
 			return
@@ -544,11 +562,14 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 				return nil
 			}}
 	}
+	if r.Method == http.MethodGet {
+		applyContentDispositionHdr(w, r, basename, attachment)
+	}
 	wh := webdav.Handler{
 		Prefix: "/" + strings.Join(pathParts[:stripParts], "/"),
 		FileSystem: &webdavFS{
 			collfs:        sessionFS,
-			prefix:        "by_id/" + collectionID + "/",
+			prefix:        fsprefix,
 			writing:       writeMethod[r.Method],
 			alwaysReadEOF: r.Method == "PROPFIND",
 		},
@@ -559,17 +580,6 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 			}
 		},
 	}
-	if r.Method == http.MethodGet || r.Method == http.MethodHead {
-		targetfnm := "by_id/" + collectionID + "/" + strings.Join(pathParts[stripParts:], "/")
-		if fi, err := sessionFS.Stat(targetfnm); err == nil && fi.IsDir() {
-			if !strings.HasSuffix(r.URL.Path, "/") {
-				h.seeOtherWithCookie(w, r, r.URL.Path+"/", credentialsOK)
-			} else {
-				h.serveDirectory(w, r, fi.Name(), sessionFS, targetfnm, true)
-			}
-			return
-		}
-	}
 	wh.ServeHTTP(w, r)
 	if r.Method == http.MethodGet && w.WroteStatus() == http.StatusOK {
 		wrote := int64(w.WroteBodyBytes())
@@ -609,66 +619,6 @@ func (h *handler) getClients(reqID, token string) (arv *arvadosclient.ArvadosCli
 	return
 }
 
-func (h *handler) serveSiteFS(w http.ResponseWriter, r *http.Request, tokens []string, credentialsOK, attachment bool) {
-	if len(tokens) == 0 {
-		w.Header().Add("WWW-Authenticate", "Basic realm=\"collections\"")
-		http.Error(w, unauthorizedMessage, http.StatusUnauthorized)
-		return
-	}
-	if writeMethod[r.Method] {
-		http.Error(w, errReadOnly.Error(), http.StatusMethodNotAllowed)
-		return
-	}
-
-	fs, sess, user, err := h.Cache.GetSession(tokens[0])
-	if err != nil {
-		http.Error(w, err.Error(), http.StatusInternalServerError)
-		return
-	}
-	f, err := fs.Open(r.URL.Path)
-	if os.IsNotExist(err) {
-		http.Error(w, err.Error(), http.StatusNotFound)
-		return
-	} else if err != nil {
-		http.Error(w, err.Error(), http.StatusInternalServerError)
-		return
-	}
-	defer f.Close()
-	if fi, err := f.Stat(); err == nil && fi.IsDir() && r.Method == "GET" {
-		if !strings.HasSuffix(r.URL.Path, "/") {
-			h.seeOtherWithCookie(w, r, r.URL.Path+"/", credentialsOK)
-		} else {
-			h.serveDirectory(w, r, fi.Name(), fs, r.URL.Path, false)
-		}
-		return
-	}
-
-	if !h.userPermittedToUploadOrDownload(r.Method, user) {
-		http.Error(w, "Not permitted", http.StatusForbidden)
-		return
-	}
-	h.logUploadOrDownload(r, sess.arvadosclient, fs, r.URL.Path, nil, user)
-
-	if r.Method == "GET" {
-		_, basename := filepath.Split(r.URL.Path)
-		applyContentDispositionHdr(w, r, basename, attachment)
-	}
-	wh := webdav.Handler{
-		FileSystem: &webdavFS{
-			collfs:        fs,
-			writing:       writeMethod[r.Method],
-			alwaysReadEOF: r.Method == "PROPFIND",
-		},
-		LockSystem: h.webdavLS,
-		Logger: func(_ *http.Request, err error) {
-			if err != nil {
-				ctxlog.FromContext(r.Context()).WithError(err).Error("error reported by webdav handler")
-			}
-		},
-	}
-	wh.ServeHTTP(w, r)
-}
-
 var dirListingTemplate = `<!DOCTYPE HTML>
 <HTML><HEAD>
   <META name="robots" content="NOINDEX">

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list