18805: add a 'static' go build tag that disables the pam login code,
[arvados.git] / lib / controller / router / response.go
index aee2fc590b093a2093ea26ce2cd91060096be198..c0c599be8bcd4f1acb6fbbc5ed90e6541cf08dfe 100644 (file)
@@ -26,11 +26,18 @@ type responseOptions struct {
 func (rtr *router) responseOptions(opts interface{}) (responseOptions, error) {
        var rOpts responseOptions
        switch opts := opts.(type) {
+       case *arvados.CreateOptions:
+               rOpts.Select = opts.Select
+       case *arvados.UpdateOptions:
+               rOpts.Select = opts.Select
        case *arvados.GetOptions:
                rOpts.Select = opts.Select
        case *arvados.ListOptions:
                rOpts.Select = opts.Select
                rOpts.Count = opts.Count
+       case *arvados.GroupContentsOptions:
+               rOpts.Select = opts.Select
+               rOpts.Count = opts.Count
        }
        return rOpts, nil
 }
@@ -82,35 +89,31 @@ func (rtr *router) sendResponse(w http.ResponseWriter, req *http.Request, resp i
                defaultItemKind = strings.TrimSuffix(respKind, "List")
        }
 
-       var items, included []interface{}
-       var itemsOK, includedOK bool
-       items, itemsOK = tmp["items"].([]interface{})
-       included, includedOK = tmp["included"].([]interface{})
-       if includedOK && len(included) > 0 {
-               items = append(items, included...)
-       }
-
-       if itemsOK {
-               for i, item := range items {
-                       // Fill in "kind" by inspecting UUID/PDH if
-                       // possible; fall back on assuming each
-                       // Items[] entry in an "arvados#fooList"
-                       // response should have kind="arvados#foo".
-                       item, _ := item.(map[string]interface{})
-                       infix := ""
-                       if uuid, _ := item["uuid"].(string); len(uuid) == 27 {
-                               infix = uuid[6:11]
-                       }
-                       if k := kind(infixMap[infix]); k != "" {
-                               item["kind"] = k
-                       } else if pdh, _ := item["portable_data_hash"].(string); pdh != "" {
-                               item["kind"] = "arvados#collection"
-                       } else if defaultItemKind != "" {
-                               item["kind"] = defaultItemKind
+       if _, isListResponse := tmp["items"].([]interface{}); isListResponse {
+               items, _ := tmp["items"].([]interface{})
+               included, _ := tmp["included"].([]interface{})
+               for _, slice := range [][]interface{}{items, included} {
+                       for i, item := range slice {
+                               // Fill in "kind" by inspecting UUID/PDH if
+                               // possible; fall back on assuming each
+                               // Items[] entry in an "arvados#fooList"
+                               // response should have kind="arvados#foo".
+                               item, _ := item.(map[string]interface{})
+                               infix := ""
+                               if uuid, _ := item["uuid"].(string); len(uuid) == 27 {
+                                       infix = uuid[6:11]
+                               }
+                               if k := kind(infixMap[infix]); k != "" {
+                                       item["kind"] = k
+                               } else if pdh, _ := item["portable_data_hash"].(string); pdh != "" {
+                                       item["kind"] = "arvados#collection"
+                               } else if defaultItemKind != "" {
+                                       item["kind"] = defaultItemKind
+                               }
+                               item = applySelectParam(opts.Select, item)
+                               rtr.mungeItemFields(item)
+                               slice[i] = item
                        }
-                       item = applySelectParam(opts.Select, item)
-                       rtr.mungeItemFields(item)
-                       items[i] = item
                }
                if opts.Count == "none" {
                        delete(tmp, "items_available")
@@ -135,6 +138,7 @@ func (rtr *router) sendError(w http.ResponseWriter, err error) {
 }
 
 var infixMap = map[string]interface{}{
+       "gj3su": arvados.APIClientAuthorization{},
        "4zz18": arvados.Collection{},
        "xvhdp": arvados.ContainerRequest{},
        "dz642": arvados.Container{},
@@ -147,6 +151,11 @@ var infixMap = map[string]interface{}{
        "7fd4e": arvados.Workflow{},
 }
 
+var specialKindTransforms = map[string]string{
+       "arvados.APIClientAuthorization":     "arvados#apiClientAuthorization",
+       "arvados.APIClientAuthorizationList": "arvados#apiClientAuthorizationList",
+}
+
 var mungeKind = regexp.MustCompile(`\..`)
 
 func kind(resp interface{}) string {
@@ -154,6 +163,9 @@ func kind(resp interface{}) string {
        if !strings.HasPrefix(t, "arvados.") {
                return ""
        }
+       if k, ok := specialKindTransforms[t]; ok {
+               return k
+       }
        return mungeKind.ReplaceAllStringFunc(t, func(s string) string {
                // "arvados.CollectionList" => "arvados#collectionList"
                return "#" + strings.ToLower(s[1:])