Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions restapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func init() {
// that are used within this project.
type MinioClient interface {
listBucketsWithContext(ctx context.Context) ([]minio.BucketInfo, error)
makeBucketWithContext(ctx context.Context, bucketName, location string) error
makeBucketWithContext(ctx context.Context, bucketName, location string, objectLocking bool) error
setBucketPolicyWithContext(ctx context.Context, bucketName, policy string) error
removeBucket(ctx context.Context, bucketName string) error
getBucketNotification(ctx context.Context, bucketName string) (config notification.Configuration, err error)
Expand Down Expand Up @@ -83,10 +83,11 @@ func (c minioClient) listBucketsWithContext(ctx context.Context) ([]minio.Bucket
return c.client.ListBuckets(ctx)
}

// implements minio.MakeBucketWithContext(ctx, bucketName, location)
func (c minioClient) makeBucketWithContext(ctx context.Context, bucketName, location string) error {
// implements minio.MakeBucketWithContext(ctx, bucketName, location, objectLocking)
func (c minioClient) makeBucketWithContext(ctx context.Context, bucketName, location string, objectLocking bool) error {
return c.client.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{
Region: location,
Region: location,
ObjectLocking: objectLocking,
})
}

Expand All @@ -110,11 +111,6 @@ func (c minioClient) getBucketPolicy(ctx context.Context, bucketName string) (st
return c.client.GetBucketPolicy(ctx, bucketName)
}

// implements minio.enableVersioning(ctx, bucketName)
func (c minioClient) enableVersioning(ctx context.Context, bucketName string) error {
return c.client.EnableVersioning(ctx, bucketName)
}

// implements minio.getBucketVersioning(ctx, bucketName)
func (c minioClient) getBucketVersioning(ctx context.Context, bucketName string) (minio.BucketVersioningConfiguration, error) {
return c.client.GetBucketVersioning(ctx, bucketName)
Expand Down
14 changes: 4 additions & 10 deletions restapi/user_buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ func getListBucketsResponse(session *models.Principal) (*models.ListBucketsRespo
}

// makeBucket creates a bucket for an specific minio client
func makeBucket(ctx context.Context, client MinioClient, bucketName string) error {
func makeBucket(ctx context.Context, client MinioClient, bucketName string, objectLocking bool) error {
// creates a new bucket with bucketName with a context to control cancellations and timeouts.
if err := client.makeBucketWithContext(ctx, bucketName, "us-east-1"); err != nil {
if err := client.makeBucketWithContext(ctx, bucketName, "us-east-1", objectLocking); err != nil {
return err
}
return nil
Expand All @@ -309,16 +309,10 @@ func getMakeBucketResponse(session *models.Principal, br *models.MakeBucketReque
// defining the client to be used
minioClient := minioClient{client: mClient}

if err := makeBucket(ctx, minioClient, *br.Name); err != nil {
if err := makeBucket(ctx, minioClient, *br.Name, br.Versioning); err != nil {
return prepareError(err)
}
// if versioned
if br.Versioning {
// we will tolerate this call failing
if err := minioClient.enableVersioning(ctx, *br.Name); err != nil {
log.Println("error versioning bucket:", err)
}
}

// if it has support for
if br.Quota != nil && br.Quota.Enabled != nil && *br.Quota.Enabled {
mAdmin, err := newMAdminClient(session)
Expand Down
14 changes: 7 additions & 7 deletions restapi/user_buckets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

// assigning mock at runtime instead of compile time
var minioListBucketsWithContextMock func(ctx context.Context) ([]minio.BucketInfo, error)
var minioMakeBucketWithContextMock func(ctx context.Context, bucketName, location string) error
var minioMakeBucketWithContextMock func(ctx context.Context, bucketName, location string, objectLock bool) error
var minioSetBucketPolicyWithContextMock func(ctx context.Context, bucketName, policy string) error
var minioRemoveBucketMock func(bucketName string) error
var minioGetBucketPolicyMock func(bucketName string) (string, error)
Expand All @@ -53,8 +53,8 @@ func (mc minioClientMock) listBucketsWithContext(ctx context.Context) ([]minio.B
}

// mock function of makeBucketsWithContext()
func (mc minioClientMock) makeBucketWithContext(ctx context.Context, bucketName, location string) error {
return minioMakeBucketWithContextMock(ctx, bucketName, location)
func (mc minioClientMock) makeBucketWithContext(ctx context.Context, bucketName, location string, objectLock bool) error {
return minioMakeBucketWithContextMock(ctx, bucketName, location, objectLock)
}

// mock function of setBucketPolicyWithContext()
Expand Down Expand Up @@ -141,18 +141,18 @@ func TestMakeBucket(t *testing.T) {
ctx := context.Background()
// Test-1: makeBucket() create a bucket
// mock function response from makeBucketWithContext(ctx)
minioMakeBucketWithContextMock = func(ctx context.Context, bucketName, location string) error {
minioMakeBucketWithContextMock = func(ctx context.Context, bucketName, location string, objectLock bool) error {
return nil
}
if err := makeBucket(ctx, minClient, "bucktest1"); err != nil {
if err := makeBucket(ctx, minClient, "bucktest1", true); err != nil {
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
}

// Test-2 makeBucket() make sure errors are handled correctly when error on MakeBucketWithContext
minioMakeBucketWithContextMock = func(ctx context.Context, bucketName, location string) error {
minioMakeBucketWithContextMock = func(ctx context.Context, bucketName, location string, objectLock bool) error {
return errors.New("error")
}
if err := makeBucket(ctx, minClient, "bucktest1"); assert.Error(err) {
if err := makeBucket(ctx, minClient, "bucktest1", true); assert.Error(err) {
assert.Equal("error", err.Error())
}
}
Expand Down