2020-08-11 14:37:20 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2021-05-18 11:10:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/api"
|
2021-11-15 12:56:16 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
2020-08-11 14:37:20 +00:00
|
|
|
)
|
|
|
|
|
2021-07-13 14:57:48 +00:00
|
|
|
const maxObjectList = 1000 // Limit number of objects in a listObjectsResponse/listObjectsVersionsResponse.
|
2020-08-11 14:37:20 +00:00
|
|
|
|
2021-05-13 20:25:31 +00:00
|
|
|
// ListBucketsHandler handles bucket listing requests.
|
2020-08-19 23:33:43 +00:00
|
|
|
func (h *handler) ListBucketsHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var (
|
2021-08-05 09:18:52 +00:00
|
|
|
own = owner.NewID()
|
|
|
|
res *ListBucketsResponse
|
|
|
|
reqInfo = api.GetReqInfo(r.Context())
|
2020-08-19 23:33:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
list, err := h.obj.ListBuckets(r.Context())
|
|
|
|
if err != nil {
|
2021-08-05 09:18:52 +00:00
|
|
|
h.logAndSendError(w, "something went wrong", reqInfo, err)
|
2020-08-19 23:33:43 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-10-23 00:12:37 +00:00
|
|
|
if len(list) > 0 {
|
|
|
|
own = list[0].Owner
|
|
|
|
}
|
|
|
|
|
2020-08-19 23:33:43 +00:00
|
|
|
res = &ListBucketsResponse{
|
|
|
|
Owner: Owner{
|
2020-10-19 01:05:08 +00:00
|
|
|
ID: own.String(),
|
|
|
|
DisplayName: own.String(),
|
2020-08-19 23:33:43 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, item := range list {
|
|
|
|
res.Buckets.Buckets = append(res.Buckets.Buckets, Bucket{
|
|
|
|
Name: item.Name,
|
2022-01-25 13:13:17 +00:00
|
|
|
CreationDate: item.Created.UTC().Format(time.RFC3339),
|
2020-08-19 23:33:43 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = api.EncodeToResponse(w, res); err != nil {
|
2021-08-05 09:18:52 +00:00
|
|
|
h.logAndSendError(w, "something went wrong", reqInfo, err)
|
2020-08-19 23:33:43 +00:00
|
|
|
}
|
|
|
|
}
|