[ARVADOS] created: 2.1.0-104-g69221de9d

Git user git at public.arvados.org
Wed Nov 18 20:05:12 UTC 2020


        at  69221de9db77ccb68f8d744e5d2dceeef963ae36 (commit)


commit 69221de9db77ccb68f8d744e5d2dceeef963ae36
Author: Tom Clegg <tom at tomclegg.ca>
Date:   Wed Nov 18 15:04:28 2020 -0500

    17014: Munge list items in controller responses.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at tomclegg.ca>

diff --git a/lib/controller/router/response.go b/lib/controller/router/response.go
index c1f44eec3..8d143cf6c 100644
--- a/lib/controller/router/response.go
+++ b/lib/controller/router/response.go
@@ -97,15 +97,51 @@ func (rtr *router) sendResponse(w http.ResponseWriter, req *http.Request, resp i
 			} else if defaultItemKind != "" {
 				item["kind"] = defaultItemKind
 			}
-			items[i] = applySelectParam(opts.Select, item)
+			item = applySelectParam(opts.Select, item)
+			rtr.mungeItemFields(item)
+			items[i] = item
 		}
 		if opts.Count == "none" {
 			delete(tmp, "items_available")
 		}
 	} else {
 		tmp = applySelectParam(opts.Select, tmp)
+		rtr.mungeItemFields(tmp)
 	}
 
+	w.Header().Set("Content-Type", "application/json")
+	enc := json.NewEncoder(w)
+	enc.SetEscapeHTML(false)
+	enc.Encode(tmp)
+}
+
+func (rtr *router) sendError(w http.ResponseWriter, err error) {
+	code := http.StatusInternalServerError
+	if err, ok := err.(interface{ HTTPStatus() int }); ok {
+		code = err.HTTPStatus()
+	}
+	httpserver.Error(w, err.Error(), code)
+}
+
+var infixMap = map[string]interface{}{
+	"4zz18": arvados.Collection{},
+	"j7d0g": arvados.Group{},
+}
+
+var mungeKind = regexp.MustCompile(`\..`)
+
+func kind(resp interface{}) string {
+	t := fmt.Sprintf("%T", resp)
+	if !strings.HasPrefix(t, "arvados.") {
+		return ""
+	}
+	return mungeKind.ReplaceAllStringFunc(t, func(s string) string {
+		// "arvados.CollectionList" => "arvados#collectionList"
+		return "#" + strings.ToLower(s[1:])
+	})
+}
+
+func (rtr *router) mungeItemFields(tmp map[string]interface{}) {
 	for k, v := range tmp {
 		if strings.HasSuffix(k, "_at") {
 			// Format non-nil timestamps as
@@ -156,34 +192,4 @@ func (rtr *router) sendResponse(w http.ResponseWriter, req *http.Request, resp i
 			}
 		}
 	}
-	w.Header().Set("Content-Type", "application/json")
-	enc := json.NewEncoder(w)
-	enc.SetEscapeHTML(false)
-	enc.Encode(tmp)
-}
-
-func (rtr *router) sendError(w http.ResponseWriter, err error) {
-	code := http.StatusInternalServerError
-	if err, ok := err.(interface{ HTTPStatus() int }); ok {
-		code = err.HTTPStatus()
-	}
-	httpserver.Error(w, err.Error(), code)
-}
-
-var infixMap = map[string]interface{}{
-	"4zz18": arvados.Collection{},
-	"j7d0g": arvados.Group{},
-}
-
-var mungeKind = regexp.MustCompile(`\..`)
-
-func kind(resp interface{}) string {
-	t := fmt.Sprintf("%T", resp)
-	if !strings.HasPrefix(t, "arvados.") {
-		return ""
-	}
-	return mungeKind.ReplaceAllStringFunc(t, func(s string) string {
-		// "arvados.CollectionList" => "arvados#collectionList"
-		return "#" + strings.ToLower(s[1:])
-	})
 }

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list