mirror of
https://github.com/versity/versitygw.git
synced 2026-09-20 15:04:27 +00:00
feat: Implemented GetBucketACL, PutBucketACL posix functions, fixed authentication middleware signed headers bug
This commit is contained in:
@@ -82,7 +82,7 @@ var _ backend.Backend = &BackendMock{}
|
||||
// ListObjectsV2Func: func(bucket string, prefix string, marker string, delim string, maxkeys int) (*s3.ListObjectsV2Output, error) {
|
||||
// panic("mock out the ListObjectsV2 method")
|
||||
// },
|
||||
// PutBucketFunc: func(bucket string) error {
|
||||
// PutBucketFunc: func(bucket string, owner string) error {
|
||||
// panic("mock out the PutBucket method")
|
||||
// },
|
||||
// PutBucketAclFunc: func(putBucketAclInput *s3.PutBucketAclInput) error {
|
||||
@@ -112,9 +112,6 @@ var _ backend.Backend = &BackendMock{}
|
||||
// StringFunc: func() string {
|
||||
// panic("mock out the String method")
|
||||
// },
|
||||
// UploadPartFunc: func(bucket string, object string, uploadId string, Body io.ReadSeeker) (*s3.UploadPartOutput, error) {
|
||||
// panic("mock out the UploadPart method")
|
||||
// },
|
||||
// UploadPartCopyFunc: func(uploadPartCopyInput *s3.UploadPartCopyInput) (*s3.UploadPartCopyOutput, error) {
|
||||
// panic("mock out the UploadPartCopy method")
|
||||
// },
|
||||
@@ -186,7 +183,7 @@ type BackendMock struct {
|
||||
ListObjectsV2Func func(bucket string, prefix string, marker string, delim string, maxkeys int) (*s3.ListObjectsV2Output, error)
|
||||
|
||||
// PutBucketFunc mocks the PutBucket method.
|
||||
PutBucketFunc func(bucket string) error
|
||||
PutBucketFunc func(bucket string, owner string) error
|
||||
|
||||
// PutBucketAclFunc mocks the PutBucketAcl method.
|
||||
PutBucketAclFunc func(putBucketAclInput *s3.PutBucketAclInput) error
|
||||
@@ -215,9 +212,6 @@ type BackendMock struct {
|
||||
// StringFunc mocks the String method.
|
||||
StringFunc func() string
|
||||
|
||||
// UploadPartFunc mocks the UploadPart method.
|
||||
UploadPartFunc func(bucket string, object string, uploadId string, Body io.ReadSeeker) (*s3.UploadPartOutput, error)
|
||||
|
||||
// UploadPartCopyFunc mocks the UploadPartCopy method.
|
||||
UploadPartCopyFunc func(uploadPartCopyInput *s3.UploadPartCopyInput) (*s3.UploadPartCopyOutput, error)
|
||||
|
||||
@@ -391,6 +385,8 @@ type BackendMock struct {
|
||||
PutBucket []struct {
|
||||
// Bucket is the bucket argument value.
|
||||
Bucket string
|
||||
// Owner is the owner argument value.
|
||||
Owner string
|
||||
}
|
||||
// PutBucketAcl holds details about calls to the PutBucketAcl method.
|
||||
PutBucketAcl []struct {
|
||||
@@ -453,17 +449,6 @@ type BackendMock struct {
|
||||
// String holds details about calls to the String method.
|
||||
String []struct {
|
||||
}
|
||||
// UploadPart holds details about calls to the UploadPart method.
|
||||
UploadPart []struct {
|
||||
// Bucket is the bucket argument value.
|
||||
Bucket string
|
||||
// Object is the object argument value.
|
||||
Object string
|
||||
// UploadId is the uploadId argument value.
|
||||
UploadId string
|
||||
// Body is the Body argument value.
|
||||
Body io.ReadSeeker
|
||||
}
|
||||
// UploadPartCopy holds details about calls to the UploadPartCopy method.
|
||||
UploadPartCopy []struct {
|
||||
// UploadPartCopyInput is the uploadPartCopyInput argument value.
|
||||
@@ -500,7 +485,6 @@ type BackendMock struct {
|
||||
lockSetTags sync.RWMutex
|
||||
lockShutdown sync.RWMutex
|
||||
lockString sync.RWMutex
|
||||
lockUploadPart sync.RWMutex
|
||||
lockUploadPartCopy sync.RWMutex
|
||||
}
|
||||
|
||||
@@ -1272,19 +1256,21 @@ func (mock *BackendMock) ListObjectsV2Calls() []struct {
|
||||
}
|
||||
|
||||
// PutBucket calls PutBucketFunc.
|
||||
func (mock *BackendMock) PutBucket(bucket string) error {
|
||||
func (mock *BackendMock) PutBucket(bucket string, owner string) error {
|
||||
if mock.PutBucketFunc == nil {
|
||||
panic("BackendMock.PutBucketFunc: method is nil but Backend.PutBucket was just called")
|
||||
}
|
||||
callInfo := struct {
|
||||
Bucket string
|
||||
Owner string
|
||||
}{
|
||||
Bucket: bucket,
|
||||
Owner: owner,
|
||||
}
|
||||
mock.lockPutBucket.Lock()
|
||||
mock.calls.PutBucket = append(mock.calls.PutBucket, callInfo)
|
||||
mock.lockPutBucket.Unlock()
|
||||
return mock.PutBucketFunc(bucket)
|
||||
return mock.PutBucketFunc(bucket, owner)
|
||||
}
|
||||
|
||||
// PutBucketCalls gets all the calls that were made to PutBucket.
|
||||
@@ -1293,9 +1279,11 @@ func (mock *BackendMock) PutBucket(bucket string) error {
|
||||
// len(mockedBackend.PutBucketCalls())
|
||||
func (mock *BackendMock) PutBucketCalls() []struct {
|
||||
Bucket string
|
||||
Owner string
|
||||
} {
|
||||
var calls []struct {
|
||||
Bucket string
|
||||
Owner string
|
||||
}
|
||||
mock.lockPutBucket.RLock()
|
||||
calls = mock.calls.PutBucket
|
||||
@@ -1621,50 +1609,6 @@ func (mock *BackendMock) StringCalls() []struct {
|
||||
return calls
|
||||
}
|
||||
|
||||
// UploadPart calls UploadPartFunc.
|
||||
func (mock *BackendMock) UploadPart(bucket string, object string, uploadId string, Body io.ReadSeeker) (*s3.UploadPartOutput, error) {
|
||||
if mock.UploadPartFunc == nil {
|
||||
panic("BackendMock.UploadPartFunc: method is nil but Backend.UploadPart was just called")
|
||||
}
|
||||
callInfo := struct {
|
||||
Bucket string
|
||||
Object string
|
||||
UploadId string
|
||||
Body io.ReadSeeker
|
||||
}{
|
||||
Bucket: bucket,
|
||||
Object: object,
|
||||
UploadId: uploadId,
|
||||
Body: Body,
|
||||
}
|
||||
mock.lockUploadPart.Lock()
|
||||
mock.calls.UploadPart = append(mock.calls.UploadPart, callInfo)
|
||||
mock.lockUploadPart.Unlock()
|
||||
return mock.UploadPartFunc(bucket, object, uploadId, Body)
|
||||
}
|
||||
|
||||
// UploadPartCalls gets all the calls that were made to UploadPart.
|
||||
// Check the length with:
|
||||
//
|
||||
// len(mockedBackend.UploadPartCalls())
|
||||
func (mock *BackendMock) UploadPartCalls() []struct {
|
||||
Bucket string
|
||||
Object string
|
||||
UploadId string
|
||||
Body io.ReadSeeker
|
||||
} {
|
||||
var calls []struct {
|
||||
Bucket string
|
||||
Object string
|
||||
UploadId string
|
||||
Body io.ReadSeeker
|
||||
}
|
||||
mock.lockUploadPart.RLock()
|
||||
calls = mock.calls.UploadPart
|
||||
mock.lockUploadPart.RUnlock()
|
||||
return calls
|
||||
}
|
||||
|
||||
// UploadPartCopy calls UploadPartCopyFunc.
|
||||
func (mock *BackendMock) UploadPartCopy(uploadPartCopyInput *s3.UploadPartCopyInput) (*s3.UploadPartCopyOutput, error) {
|
||||
if mock.UploadPartCopyFunc == nil {
|
||||
|
||||
+13
-10
@@ -152,15 +152,17 @@ func (c S3ApiController) ListActions(ctx *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
func (c S3ApiController) PutBucketActions(ctx *fiber.Ctx) error {
|
||||
bucket, acl, grantFullControl, grantRead, grantReadACP, granWrite, grantWriteACP :=
|
||||
bucket, acl, grantFullControl, grantRead, grantReadACP, granWrite, grantWriteACP, access :=
|
||||
ctx.Params("bucket"),
|
||||
ctx.Get("X-Amz-Acl"),
|
||||
ctx.Get("X-Amz-Grant-Full-Control"),
|
||||
ctx.Get("X-Amz-Grant-Read"),
|
||||
ctx.Get("X-Amz-Grant-Read-Acp"),
|
||||
ctx.Get("X-Amz-Grant-Write"),
|
||||
ctx.Get("X-Amz-Grant-Write-Acp")
|
||||
ctx.Get("X-Amz-Grant-Write-Acp"),
|
||||
ctx.Locals("access")
|
||||
|
||||
owner := access.(string)
|
||||
grants := grantFullControl + grantRead + grantReadACP + granWrite + grantWriteACP
|
||||
|
||||
if grants != "" || acl != "" {
|
||||
@@ -168,19 +170,20 @@ func (c S3ApiController) PutBucketActions(ctx *fiber.Ctx) error {
|
||||
return errors.New("wrong api call")
|
||||
}
|
||||
err := c.be.PutBucketAcl(&s3.PutBucketAclInput{
|
||||
Bucket: &bucket,
|
||||
ACL: types.BucketCannedACL(acl),
|
||||
GrantFullControl: &grantFullControl,
|
||||
GrantRead: &grantRead,
|
||||
GrantReadACP: &grantReadACP,
|
||||
GrantWrite: &granWrite,
|
||||
GrantWriteACP: &grantWriteACP,
|
||||
Bucket: &bucket,
|
||||
ACL: types.BucketCannedACL(acl),
|
||||
GrantFullControl: &grantFullControl,
|
||||
GrantRead: &grantRead,
|
||||
GrantReadACP: &grantReadACP,
|
||||
GrantWrite: &granWrite,
|
||||
GrantWriteACP: &grantWriteACP,
|
||||
AccessControlPolicy: &types.AccessControlPolicy{Owner: &types.Owner{ID: &owner}},
|
||||
})
|
||||
|
||||
return SendResponse(ctx, err)
|
||||
}
|
||||
|
||||
err := c.be.PutBucket(bucket)
|
||||
err := c.be.PutBucket(bucket, owner)
|
||||
return SendResponse(ctx, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ func TestS3ApiController_ListActions(t *testing.T) {
|
||||
app := fiber.New()
|
||||
s3ApiController := S3ApiController{be: &BackendMock{
|
||||
GetBucketAclFunc: func(bucket string) (*s3.GetBucketAclOutput, error) {
|
||||
return &s3.GetBucketAclOutput{}, nil
|
||||
return nil, nil
|
||||
},
|
||||
ListMultipartUploadsFunc: func(output *s3.ListMultipartUploadsInput) (s3response.ListMultipartUploadsResponse, error) {
|
||||
return s3response.ListMultipartUploadsResponse{}, nil
|
||||
@@ -333,7 +333,7 @@ func TestS3ApiController_PutBucketActions(t *testing.T) {
|
||||
PutBucketAclFunc: func(*s3.PutBucketAclInput) error {
|
||||
return nil
|
||||
},
|
||||
PutBucketFunc: func(bucket string) error {
|
||||
PutBucketFunc: func(bucket, owner string) error {
|
||||
return nil
|
||||
},
|
||||
}}
|
||||
@@ -406,9 +406,6 @@ func TestS3ApiController_PutActions(t *testing.T) {
|
||||
UploadPartCopyFunc: func(*s3.UploadPartCopyInput) (*s3.UploadPartCopyOutput, error) {
|
||||
return &s3.UploadPartCopyOutput{}, nil
|
||||
},
|
||||
UploadPartFunc: func(bucket, object, uploadId string, Body io.ReadSeeker) (*s3.UploadPartOutput, error) {
|
||||
return &s3.UploadPartOutput{}, nil
|
||||
},
|
||||
PutObjectAclFunc: func(*s3.PutObjectAclInput) error {
|
||||
return nil
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user