1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
12 func (fs *customFileSystem) defaultUUID(uuid string) (string, error) {
17 err := fs.RequestAndDecode(&resp, "GET", "arvados/v1/users/current", nil, nil)
24 // loadOneChild loads only the named child, if it exists.
25 func (fs *customFileSystem) projectsLoadOne(parent inode, uuid, name string) (inode, error) {
26 uuid, err := fs.defaultUUID(uuid)
31 var contents CollectionList
32 for _, subst := range []string{"/", fs.forwardSlashNameSubstitution} {
33 contents = CollectionList{}
34 err = fs.RequestAndDecode(&contents, "GET", "arvados/v1/groups/"+uuid+"/contents", nil, ResourceListParams{
37 {"name", "=", strings.Replace(name, subst, "/", -1)},
38 {"uuid", "is_a", []string{"arvados#collection", "arvados#group"}},
39 {"groups.group_class", "=", "project"},
45 if len(contents.Items) > 0 || fs.forwardSlashNameSubstitution == "/" || fs.forwardSlashNameSubstitution == "" || !strings.Contains(name, fs.forwardSlashNameSubstitution) {
48 // If the requested name contains the configured "/"
49 // replacement string and didn't match a
50 // project/collection exactly, we'll try again with
51 // "/" in its place, so a lookup of a munged name
52 // works regardless of whether the directory listing
53 // has been populated with escaped names.
55 // Note this doesn't handle items whose names contain
56 // both "/" and the substitution string.
58 if len(contents.Items) == 0 {
61 coll := contents.Items[0]
63 if strings.Contains(coll.UUID, "-j7d0g-") {
64 // Group item was loaded into a Collection var -- but
65 // we only need the Name and UUID anyway, so it's OK.
66 return fs.newProjectNode(parent, coll.Name, coll.UUID), nil
67 } else if strings.Contains(coll.UUID, "-4zz18-") {
68 return deferredCollectionFS(fs, parent, coll), nil
70 log.Printf("projectnode: unrecognized UUID in response: %q", coll.UUID)
71 return nil, ErrInvalidArgument
75 func (fs *customFileSystem) projectsLoadAll(parent inode, uuid string) ([]inode, error) {
76 uuid, err := fs.defaultUUID(uuid)
83 // Note: the "filters" slice's backing array might be reused
84 // by append(filters,...) below. This isn't goroutine safe,
85 // but all accesses are in the same goroutine, so it's OK.
86 filters := []Filter{{"owner_uuid", "=", uuid}}
87 params := ResourceListParams{
93 var resp CollectionList
94 err = fs.RequestAndDecode(&resp, "GET", "arvados/v1/collections", nil, params)
98 if len(resp.Items) == 0 {
101 for _, i := range resp.Items {
103 if fs.forwardSlashNameSubstitution != "" {
104 coll.Name = strings.Replace(coll.Name, "/", fs.forwardSlashNameSubstitution, -1)
106 if !permittedName(coll.Name) {
109 inodes = append(inodes, deferredCollectionFS(fs, parent, coll))
111 params.Filters = append(filters, Filter{"uuid", ">", resp.Items[len(resp.Items)-1].UUID})
114 filters = append(filters, Filter{"group_class", "=", "project"})
115 params.Filters = filters
118 err = fs.RequestAndDecode(&resp, "GET", "arvados/v1/groups", nil, params)
122 if len(resp.Items) == 0 {
125 for _, group := range resp.Items {
126 if fs.forwardSlashNameSubstitution != "" {
127 group.Name = strings.Replace(group.Name, "/", fs.forwardSlashNameSubstitution, -1)
129 if !permittedName(group.Name) {
132 inodes = append(inodes, fs.newProjectNode(parent, group.Name, group.UUID))
134 params.Filters = append(filters, Filter{"uuid", ">", resp.Items[len(resp.Items)-1].UUID})