2020-08-11 14:37:20 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/middleware"
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
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 (
|
2022-04-25 09:57:58 +00:00
|
|
|
own user.ID
|
2021-08-05 09:18:52 +00:00
|
|
|
res *ListBucketsResponse
|
2023-07-05 14:05:45 +00:00
|
|
|
reqInfo = middleware.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 {
|
2022-05-25 17:25:43 +00:00
|
|
|
own = list[0].Owner
|
2020-10-23 00:12:37 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
if err = middleware.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
|
|
|
}
|
|
|
|
}
|