2020-08-11 14:37:20 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2021-01-14 17:39:48 +00:00
|
|
|
"encoding/xml"
|
2020-08-11 14:37:20 +00:00
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2020-10-19 01:05:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
2021-05-18 11:10:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/api"
|
2020-08-11 14:37:20 +00:00
|
|
|
)
|
|
|
|
|
2021-05-13 20:25:31 +00:00
|
|
|
// VersioningConfiguration contains VersioningConfiguration XML representation.
|
2021-01-14 17:39:48 +00:00
|
|
|
type VersioningConfiguration struct {
|
|
|
|
XMLName xml.Name `xml:"VersioningConfiguration"`
|
|
|
|
Text string `xml:",chardata"`
|
|
|
|
Xmlns string `xml:"xmlns,attr"`
|
|
|
|
}
|
|
|
|
|
2021-05-13 20:25:31 +00:00
|
|
|
// ListMultipartUploadsResult contains ListMultipartUploadsResult XML representation.
|
2021-01-14 17:39:48 +00:00
|
|
|
type ListMultipartUploadsResult struct {
|
|
|
|
XMLName xml.Name `xml:"ListMultipartUploadsResult"`
|
|
|
|
Text string `xml:",chardata"`
|
|
|
|
Xmlns string `xml:"xmlns,attr"`
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
CreationDate: item.Created.Format(time.RFC3339),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-13 20:25:31 +00:00
|
|
|
// GetBucketVersioningHandler implements bucket versioning getter handler.
|
2021-01-14 17:39:48 +00:00
|
|
|
func (h *handler) GetBucketVersioningHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var (
|
2021-08-05 09:18:52 +00:00
|
|
|
reqInfo = api.GetReqInfo(r.Context())
|
|
|
|
res = new(VersioningConfiguration)
|
2021-01-14 17:39:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
res.Xmlns = "http://s3.amazonaws.com/doc/2006-03-01/"
|
|
|
|
|
|
|
|
if err := api.EncodeToResponse(w, res); err != nil {
|
2021-08-05 09:18:52 +00:00
|
|
|
h.logAndSendError(w, "something went wrong", reqInfo, err)
|
2021-01-14 17:39:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-13 20:25:31 +00:00
|
|
|
// ListMultipartUploadsHandler implements multipart uploads listing handler.
|
2021-01-14 17:39:48 +00:00
|
|
|
func (h *handler) ListMultipartUploadsHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var (
|
2021-08-05 09:18:52 +00:00
|
|
|
reqInfo = api.GetReqInfo(r.Context())
|
|
|
|
res = new(ListMultipartUploadsResult)
|
2021-01-14 17:39:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
res.Xmlns = "http://s3.amazonaws.com/doc/2006-03-01/"
|
|
|
|
|
|
|
|
if err := api.EncodeToResponse(w, res); err != nil {
|
2021-08-05 09:18:52 +00:00
|
|
|
h.logAndSendError(w, "something went wrong", reqInfo, err)
|
2021-01-14 17:39:48 +00:00
|
|
|
}
|
|
|
|
}
|