Skip to content

Commit 399f778

Browse files
author
Benjamin Perez
committed
Fixed object lock
1 parent 114bc36 commit 399f778

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

restapi/client.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func init() {
5252
// that are used within this project.
5353
type MinioClient interface {
5454
listBucketsWithContext(ctx context.Context) ([]minio.BucketInfo, error)
55-
makeBucketWithContext(ctx context.Context, bucketName, location string) error
55+
makeBucketWithContext(ctx context.Context, bucketName, location string, objectLocking bool) error
5656
setBucketPolicyWithContext(ctx context.Context, bucketName, policy string) error
5757
removeBucket(ctx context.Context, bucketName string) error
5858
getBucketNotification(ctx context.Context, bucketName string) (config notification.Configuration, err error)
@@ -83,10 +83,11 @@ func (c minioClient) listBucketsWithContext(ctx context.Context) ([]minio.Bucket
8383
return c.client.ListBuckets(ctx)
8484
}
8585

86-
// implements minio.MakeBucketWithContext(ctx, bucketName, location)
87-
func (c minioClient) makeBucketWithContext(ctx context.Context, bucketName, location string) error {
86+
// implements minio.MakeBucketWithContext(ctx, bucketName, location, objectLocking)
87+
func (c minioClient) makeBucketWithContext(ctx context.Context, bucketName, location string, objectLocking bool) error {
8888
return c.client.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{
89-
Region: location,
89+
Region: location,
90+
ObjectLocking: objectLocking,
9091
})
9192
}
9293

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

113-
// implements minio.enableVersioning(ctx, bucketName)
114-
func (c minioClient) enableVersioning(ctx context.Context, bucketName string) error {
115-
return c.client.EnableVersioning(ctx, bucketName)
116-
}
117-
118114
// implements minio.getBucketVersioning(ctx, bucketName)
119115
func (c minioClient) getBucketVersioning(ctx context.Context, bucketName string) (minio.BucketVersioningConfiguration, error) {
120116
return c.client.GetBucketVersioning(ctx, bucketName)

restapi/user_buckets.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@ func getListBucketsResponse(session *models.Principal) (*models.ListBucketsRespo
285285
}
286286

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

312-
if err := makeBucket(ctx, minioClient, *br.Name); err != nil {
312+
if err := makeBucket(ctx, minioClient, *br.Name, br.Versioning); err != nil {
313313
return prepareError(err)
314314
}
315-
// if versioned
316-
if br.Versioning {
317-
// we will tolerate this call failing
318-
if err := minioClient.enableVersioning(ctx, *br.Name); err != nil {
319-
log.Println("error versioning bucket:", err)
320-
}
321-
}
315+
322316
// if it has support for
323317
if br.Quota != nil && br.Quota.Enabled != nil && *br.Quota.Enabled {
324318
mAdmin, err := newMAdminClient(session)

restapi/user_buckets_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535

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

5555
// mock function of makeBucketsWithContext()
56-
func (mc minioClientMock) makeBucketWithContext(ctx context.Context, bucketName, location string) error {
57-
return minioMakeBucketWithContextMock(ctx, bucketName, location)
56+
func (mc minioClientMock) makeBucketWithContext(ctx context.Context, bucketName, location string, objectLock bool) error {
57+
return minioMakeBucketWithContextMock(ctx, bucketName, location, objectLock)
5858
}
5959

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

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

0 commit comments

Comments
 (0)