-
Notifications
You must be signed in to change notification settings - Fork 351
/
listbuckets.go
57 lines (48 loc) · 1.38 KB
/
listbuckets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package operations
import (
"net/http"
"github.com/treeverse/lakefs/pkg/gateway/errors"
"github.com/treeverse/lakefs/pkg/gateway/serde"
"github.com/treeverse/lakefs/pkg/permissions"
)
type ListBuckets struct{}
func (controller *ListBuckets) RequiredPermissions(_ *http.Request) (permissions.Node, error) {
return permissions.Node{
Permission: permissions.Permission{
Action: permissions.ListRepositoriesAction,
Resource: "*",
},
}, nil
}
// Handle - list buckets (repositories)
func (controller *ListBuckets) Handle(w http.ResponseWriter, req *http.Request, o *AuthorizedOperation) {
if o.HandleUnsupported(w, req, "events") {
return
}
o.Incr("list_repos", o.Principal, "", "")
buckets := make([]serde.Bucket, 0)
var after string
for {
// list repositories
repos, hasMore, err := o.Catalog.ListRepositories(req.Context(), -1, "", after)
if err != nil {
_ = o.EncodeError(w, req, err, errors.Codes.ToAPIErr(errors.ErrInternalError))
return
}
// collect repositories
for _, repo := range repos {
buckets = append(buckets, serde.Bucket{
CreationDate: serde.Timestamp(repo.CreationDate),
Name: repo.Name,
})
}
if !hasMore || len(repos) == 0 {
break
}
after = repos[len(repos)-1].Name
}
// write response
o.EncodeResponse(w, req, serde.ListAllMyBucketsResult{
Buckets: serde.Buckets{Bucket: buckets},
}, http.StatusOK)
}