mirror of
https://github.com/versity/versitygw.git
synced 2026-01-10 13:27:21 +00:00
feat: Created UploadPartCopy action
This commit is contained in:
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/scoutgw.iml" filepath="$PROJECT_DIR$/.idea/scoutgw.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
9
.idea/scoutgw.iml
generated
Normal file
9
.idea/scoutgw.iml
generated
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -42,6 +42,7 @@ type Backend interface {
|
||||
PutObjectAcl(*s3.PutObjectAclInput) s3err.ErrorCode
|
||||
RestoreObject(bucket, object string, restoreRequest *s3.RestoreRequest) s3err.ErrorCode
|
||||
UploadPart(bucket, object, uploadId string, Body io.ReadSeeker) (*s3.UploadPartOutput, s3err.ErrorCode)
|
||||
UploadPartCopy(*s3.UploadPartCopyInput) (*s3.UploadPartCopyOutput, s3err.ErrorCode)
|
||||
|
||||
IsTaggingSupported() bool
|
||||
GetTags(bucket, object string) (map[string]string, error)
|
||||
@@ -76,6 +77,9 @@ func (BackendUnsupported) PutObjectAcl(*s3.PutObjectAclInput) s3err.ErrorCode {
|
||||
func (BackendUnsupported) RestoreObject(bucket, object string, restoreRequest *s3.RestoreRequest) s3err.ErrorCode {
|
||||
return s3err.ErrNotImplemented
|
||||
}
|
||||
func (BackendUnsupported) UploadPartCopy(*s3.UploadPartCopyInput) (*s3.UploadPartCopyOutput, s3err.ErrorCode) {
|
||||
return nil, s3err.ErrNotImplemented
|
||||
}
|
||||
func (BackendUnsupported) UploadPart(bucket, object, uploadId string, Body io.ReadSeeker) (*s3.UploadPartOutput, s3err.ErrorCode) {
|
||||
return nil, s3err.ErrNotImplemented
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
@@ -30,12 +31,12 @@ func (sa *S3ApiRouter) Init(app *fiber.App, be backend.Backend) {
|
||||
app.Put("/:bucket", func(ctx *fiber.Ctx) error {
|
||||
bucket, acl, grantFullControl, grantRead, grantReadACP, granWrite, grantWriteACP :=
|
||||
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-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")
|
||||
|
||||
grants := grantFullControl + grantRead + grantReadACP + granWrite + grantWriteACP
|
||||
|
||||
@@ -228,22 +229,64 @@ func (sa *S3ApiRouter) Init(app *fiber.App, be backend.Backend) {
|
||||
// CopyObject action
|
||||
// PutObject action
|
||||
// UploadPart action
|
||||
// UploadPartCopy action
|
||||
app.Put("/:bucket/:key/*", func(ctx *fiber.Ctx) error {
|
||||
copySource := strings.Split(ctx.Get("X-Amz-Copy-Source"), "/")
|
||||
dstBucket, dstKeyStart, dstKeyEnd, uploadId := ctx.Params("bucket"), ctx.Params("key"), ctx.Params("*1"), ctx.Query("uploadId")
|
||||
acl, grantFullControl, grantRead, grantReadACP, granWrite, grantWriteACP :=
|
||||
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")
|
||||
dstBucket, dstKeyStart, dstKeyEnd, uploadId, partNumberStr := ctx.Params("bucket"), ctx.Params("key"), ctx.Params("*1"), ctx.Query("uploadId"), ctx.Query("partNumber")
|
||||
copySource, copySrcIfMatch, copySrcIfNoneMatch,
|
||||
copySrcModifSince, copySrcUnmodifSince, acl,
|
||||
grantFullControl, grantRead, grantReadACP,
|
||||
granWrite, grantWriteACP :=
|
||||
// Copy source headers
|
||||
ctx.Get("X-Amz-Copy-Source"),
|
||||
ctx.Get("X-Amz-Copy-Source-If-Match"),
|
||||
ctx.Get("X-Amz-Copy-Source-If-None-Match"),
|
||||
ctx.Get("X-Amz-Copy-Source-If-Modified-Since"),
|
||||
ctx.Get("X-Amz-Copy-Source-If-Unmodified-Since"),
|
||||
// Permission headers
|
||||
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")
|
||||
|
||||
grants := grantFullControl + grantRead + grantReadACP + granWrite + grantWriteACP
|
||||
|
||||
if dstKeyEnd != "" {
|
||||
dstKeyStart = strings.Join([]string{dstKeyStart, dstKeyEnd}, "/")
|
||||
}
|
||||
|
||||
if partNumberStr != "" {
|
||||
copySrcModifSinceDate, err := time.Parse(time.RFC3339, copySrcModifSince)
|
||||
if err != nil && copySrcModifSince != "" {
|
||||
return errors.New("wrong api call")
|
||||
}
|
||||
|
||||
copySrcUnmodifSinceDate, err := time.Parse(time.RFC3339, copySrcUnmodifSince)
|
||||
if err != nil && copySrcUnmodifSince != "" {
|
||||
return errors.New("wrong api call")
|
||||
}
|
||||
|
||||
partNumber, err := strconv.ParseInt(partNumberStr, 10, 64)
|
||||
if err != nil {
|
||||
return errors.New("wrong api call")
|
||||
}
|
||||
|
||||
res, code := be.UploadPartCopy(&s3.UploadPartCopyInput{
|
||||
Bucket: &dstBucket,
|
||||
Key: &dstKeyStart,
|
||||
PartNumber: &partNumber,
|
||||
UploadId: &uploadId,
|
||||
CopySource: ©Source,
|
||||
CopySourceIfMatch: ©SrcIfMatch,
|
||||
CopySourceIfNoneMatch: ©SrcIfNoneMatch,
|
||||
CopySourceIfModifiedSince: ©SrcModifSinceDate,
|
||||
CopySourceIfUnmodifiedSince: ©SrcUnmodifSinceDate,
|
||||
})
|
||||
|
||||
return responce[*s3.UploadPartCopyOutput](ctx, res, code)
|
||||
}
|
||||
|
||||
if uploadId != "" {
|
||||
body := io.ReadSeeker(bytes.NewReader([]byte(ctx.Body())))
|
||||
res, code := be.UploadPart(dstBucket, dstKeyStart, uploadId, body)
|
||||
@@ -268,8 +311,9 @@ func (sa *S3ApiRouter) Init(app *fiber.App, be backend.Backend) {
|
||||
return responce[internal.Any](ctx, nil, code)
|
||||
}
|
||||
|
||||
if len(copySource) > 1 {
|
||||
srcBucket, srcObject := copySource[0], copySource[1:]
|
||||
if copySource != "" {
|
||||
copySourceSplit := strings.Split(copySource, "/")
|
||||
srcBucket, srcObject := copySourceSplit[0], copySourceSplit[1:]
|
||||
|
||||
res, code := be.CopyObject(srcBucket, strings.Join(srcObject, "/"), dstBucket, dstKeyStart)
|
||||
return responce[*s3response.CopyObjectResponse](ctx, res, code)
|
||||
|
||||
Reference in New Issue
Block a user