diff --git a/restapi/client.go b/restapi/client.go index 822c69fefd..574466fa28 100644 --- a/restapi/client.go +++ b/restapi/client.go @@ -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) @@ -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, }) } @@ -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) diff --git a/restapi/user_buckets.go b/restapi/user_buckets.go index a9ba6c2ec3..d86fc3285b 100644 --- a/restapi/user_buckets.go +++ b/restapi/user_buckets.go @@ -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 @@ -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) diff --git a/restapi/user_buckets_test.go b/restapi/user_buckets_test.go index 036ac56db2..bb439be58c 100644 --- a/restapi/user_buckets_test.go +++ b/restapi/user_buckets_test.go @@ -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) @@ -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() @@ -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()) } }