forked from TrueCloudLab/frostfs-s3-gw
[#301] Implement GetBucketLocation
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
9b14340816
commit
b9f77b3d96
6 changed files with 43 additions and 21 deletions
|
@ -22,6 +22,7 @@ type (
|
||||||
Owner *owner.ID
|
Owner *owner.ID
|
||||||
Created time.Time
|
Created time.Time
|
||||||
BasicACL uint32
|
BasicACL uint32
|
||||||
|
LocationConstraint string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObjectInfo holds S3 object data.
|
// ObjectInfo holds S3 object data.
|
||||||
|
|
|
@ -9,12 +9,18 @@ import (
|
||||||
func (h *handler) GetBucketLocationHandler(w http.ResponseWriter, r *http.Request) {
|
func (h *handler) GetBucketLocationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
reqInfo := api.GetReqInfo(r.Context())
|
reqInfo := api.GetReqInfo(r.Context())
|
||||||
|
|
||||||
if _, err := h.obj.GetBucketInfo(r.Context(), reqInfo.BucketName); err != nil {
|
bktInfo, err := h.obj.GetBucketInfo(r.Context(), reqInfo.BucketName)
|
||||||
h.logAndSendError(w, "something went wrong", reqInfo, err)
|
if err != nil {
|
||||||
|
h.logAndSendError(w, "could not get bucket info", reqInfo, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.EncodeToResponse(w, LocationResponse{Location: ""}); err != nil {
|
if err = checkOwner(bktInfo, r.Header.Get(api.AmzExpectedBucketOwner)); err != nil {
|
||||||
h.logAndSendError(w, "something went wrong", reqInfo, err)
|
h.logAndSendError(w, "expected owner doesn't match", reqInfo, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = api.EncodeToResponse(w, LocationResponse{Location: bktInfo.LocationConstraint}); err != nil {
|
||||||
|
h.logAndSendError(w, "couldn't encode bucket location response", reqInfo, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -549,6 +549,7 @@ func (h *handler) CreateBucketHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
for _, placementPolicy := range policies {
|
for _, placementPolicy := range policies {
|
||||||
if placementPolicy.LocationConstraint == createParams.LocationConstraint {
|
if placementPolicy.LocationConstraint == createParams.LocationConstraint {
|
||||||
p.Policy = placementPolicy.Policy
|
p.Policy = placementPolicy.Policy
|
||||||
|
p.LocationConstraint = createParams.LocationConstraint
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ type (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const locationConstraintAttr = ".s3-location-constraint"
|
||||||
|
|
||||||
func (n *layer) containerInfo(ctx context.Context, cid *cid.ID) (*data.BucketInfo, error) {
|
func (n *layer) containerInfo(ctx context.Context, cid *cid.ID) (*data.BucketInfo, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
@ -70,6 +72,8 @@ func (n *layer) containerInfo(ctx context.Context, cid *cid.ID) (*data.BucketInf
|
||||||
}
|
}
|
||||||
|
|
||||||
info.Created = time.Unix(unix, 0)
|
info.Created = time.Unix(unix, 0)
|
||||||
|
case locationConstraintAttr:
|
||||||
|
info.LocationConstraint = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,12 +125,21 @@ func (n *layer) createContainer(ctx context.Context, p *CreateBucketParams) (*ci
|
||||||
Owner: n.Owner(ctx),
|
Owner: n.Owner(ctx),
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
BasicACL: p.ACL,
|
BasicACL: p.ACL,
|
||||||
|
LocationConstraint: p.LocationConstraint,
|
||||||
}
|
}
|
||||||
cnr := container.New(
|
|
||||||
|
options := []container.Option{
|
||||||
container.WithPolicy(p.Policy),
|
container.WithPolicy(p.Policy),
|
||||||
container.WithCustomBasicACL(p.ACL),
|
container.WithCustomBasicACL(p.ACL),
|
||||||
container.WithAttribute(container.AttributeName, p.Name),
|
container.WithAttribute(container.AttributeName, p.Name),
|
||||||
container.WithAttribute(container.AttributeTimestamp, strconv.FormatInt(bktInfo.Created.Unix(), 10)))
|
container.WithAttribute(container.AttributeTimestamp, strconv.FormatInt(bktInfo.Created.Unix(), 10)),
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.LocationConstraint != "" {
|
||||||
|
options = append(options, container.WithAttribute(locationConstraintAttr, p.LocationConstraint))
|
||||||
|
}
|
||||||
|
|
||||||
|
cnr := container.New(options...)
|
||||||
container.SetNativeName(cnr, p.Name)
|
container.SetNativeName(cnr, p.Name)
|
||||||
|
|
||||||
cnr.SetSessionToken(p.SessionToken)
|
cnr.SetSessionToken(p.SessionToken)
|
||||||
|
|
|
@ -136,6 +136,7 @@ type (
|
||||||
Policy *netmap.PlacementPolicy
|
Policy *netmap.PlacementPolicy
|
||||||
EACL *eacl.Table
|
EACL *eacl.Table
|
||||||
SessionToken *session.Token
|
SessionToken *session.Token
|
||||||
|
LocationConstraint string
|
||||||
}
|
}
|
||||||
// PutBucketACLParams stores put bucket acl request parameters.
|
// PutBucketACLParams stores put bucket acl request parameters.
|
||||||
PutBucketACLParams struct {
|
PutBucketACLParams struct {
|
||||||
|
|
|
@ -87,7 +87,7 @@ See also `GetObject` and other method parameters.
|
||||||
|----|----------------------|-----------|
|
|----|----------------------|-----------|
|
||||||
| 🟢 | CreateBucket | PutBucket |
|
| 🟢 | CreateBucket | PutBucket |
|
||||||
| 🟢 | DeleteBucket | |
|
| 🟢 | DeleteBucket | |
|
||||||
| 🔵 | GetBucketLocation | |
|
| 🟢 | GetBucketLocation | |
|
||||||
| 🟢 | HeadBucket | |
|
| 🟢 | HeadBucket | |
|
||||||
| 🟢 | ListBuckets | |
|
| 🟢 | ListBuckets | |
|
||||||
| 🔵 | PutPublicAccessBlock | |
|
| 🔵 | PutPublicAccessBlock | |
|
||||||
|
|
Loading…
Reference in a new issue