Skip to content

Commit

Permalink
✨ Update UploadPart impl (#361)
Browse files Browse the repository at this point in the history
* ✨ No limit on the number of ns that the admin user can create

* ✨ Update UploadPart impl
  • Loading branch information
tosone authored May 2, 2024
1 parent 3ab33a8 commit 6c643f6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
13 changes: 9 additions & 4 deletions pkg/handlers/namespaces/namespaces_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ import (

func TestPostNamespace(t *testing.T) {
logger.SetLevel("debug")
e := echo.New()
validators.Initialize(e)

assert.NoError(t, tests.Initialize(t))
assert.NoError(t, tests.DB.Init())
defer func() {
Expand All @@ -56,6 +55,9 @@ func TestPostNamespace(t *testing.T) {
assert.NoError(t, tests.DB.DeInit())
}()

e := echo.New()
validators.Initialize(e)

ctrl := gomock.NewController(t)
defer ctrl.Finish()

Expand Down Expand Up @@ -169,8 +171,8 @@ func TestPostNamespace(t *testing.T) {

// TestPostNamespaceCreateFailed1 get name failed
func TestPostNamespaceCreateFailed1(t *testing.T) {
e := echo.New()
validators.Initialize(e)
logger.SetLevel("debug")

assert.NoError(t, tests.Initialize(t))
assert.NoError(t, tests.DB.Init())
defer func() {
Expand All @@ -180,6 +182,9 @@ func TestPostNamespaceCreateFailed1(t *testing.T) {
assert.NoError(t, tests.DB.DeInit())
}()

e := echo.New()
validators.Initialize(e)

userServiceFactory := dao.NewUserServiceFactory()
userService := userServiceFactory.New()

Expand Down
38 changes: 30 additions & 8 deletions pkg/storage/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/rs/zerolog/log"

"github.com/go-sigma/sigma/pkg/configs"
"github.com/go-sigma/sigma/pkg/consts"
Expand Down Expand Up @@ -267,25 +268,46 @@ func (a *awss3) CreateUploadID(ctx context.Context, path string) (string, error)

// UploadPart uploads a part of an object.
func (a *awss3) UploadPart(ctx context.Context, path, uploadID string, partNumber int64, body io.Reader) (string, error) {
_, err := a.uploader.UploadWithContext(ctx, &s3manager.UploadInput{
Bucket: aws.String(a.bucket),
Key: aws.String(a.sanitizePath(path)),
Body: body,
})
file, err := os.CreateTemp("", "s3")
if err != nil {
return "", err
}
_, err = io.Copy(file, body)
if err != nil {
return "", err
}
err = file.Sync()
if err != nil {
return "", err
}
resp, err := a.client.UploadPartCopyWithContext(ctx, &s3.UploadPartCopyInput{
err = file.Close()
if err != nil {
return "", err
}
defer func() {
err := os.Remove(file.Name())
if err != nil {
log.Error().Err(err).Str("File", file.Name()).Msg("Remove upload temp file failed")
}
}()

fd, err := os.Open(file.Name())
if err != nil {
return "", err
}
defer fd.Close() // nolint: errcheck

resp, err := a.client.UploadPartWithContext(ctx, &s3.UploadPartInput{
Bucket: aws.String(a.bucket),
Key: aws.String(a.sanitizePath(path)),
UploadId: aws.String(uploadID),
PartNumber: aws.Int64(partNumber),
CopySource: aws.String(a.bucket + "/" + a.sanitizePath(path)),
Body: fd,
})
if err != nil {
return "", err
}
return aws.StringValue(resp.CopyPartResult.ETag), nil
return aws.StringValue(resp.ETag), nil
}

// CommitUpload commits an upload.
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/challenge/authchallenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type Manager interface {

// AddResponse adds the response to the challenge
// manager. The challenges will be parsed out of
// the WWW-Authenicate headers and added to the
// the WWW-Authenticate headers and added to the
// URL which was produced the response. If the
// response was authorized, any challenges for the
// endpoint will be cleared.
Expand Down

0 comments on commit 6c643f6

Please sign in to comment.