-
Notifications
You must be signed in to change notification settings - Fork 342
/
listbuckets.go
43 lines (36 loc) · 1.08 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
package operations
import (
"net/http"
"github.com/treeverse/lakefs/pkg/permissions"
"github.com/treeverse/lakefs/pkg/gateway/errors"
"github.com/treeverse/lakefs/pkg/gateway/serde"
)
type ListBuckets struct{}
func (controller *ListBuckets) RequiredPermissions(_ *http.Request) ([]permissions.Permission, error) {
return []permissions.Permission{
{
Action: permissions.ListRepositoriesAction,
Resource: "*",
},
}, nil
}
func (controller *ListBuckets) Handle(w http.ResponseWriter, req *http.Request, o *AuthorizedOperation) {
o.Incr("list_repos")
repos, _, err := o.Catalog.ListRepositories(req.Context(), -1, "", "")
if err != nil {
_ = o.EncodeError(w, req, errors.Codes.ToAPIErr(errors.ErrInternalError))
return
}
// assemble response
buckets := make([]serde.Bucket, len(repos))
for i, repo := range repos {
buckets[i] = serde.Bucket{
CreationDate: serde.Timestamp(repo.CreationDate),
Name: repo.Name,
}
}
// write response
o.EncodeResponse(w, req, serde.ListAllMyBucketsResult{
Buckets: serde.Buckets{Bucket: buckets},
}, http.StatusOK)
}