From d3d5a1baed1cd8c9b3e6e60dff57cae8167a472f Mon Sep 17 00:00:00 2001 From: Nikita Zinkevich Date: Wed, 6 Nov 2024 12:33:44 +0300 Subject: [PATCH] [#100] s3: Support creating of versioned bucket Add "versioning" parameter handling in CreateBucket method Signed-off-by: Nikita Zinkevich --- internal/s3/client.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/internal/s3/client.go b/internal/s3/client.go index 0765807..b4824b0 100644 --- a/internal/s3/client.go +++ b/internal/s3/client.go @@ -215,6 +215,26 @@ func (c *Client) CreateBucket(bucket string, params map[string]string) CreateBuc return CreateBucketResponse{Success: false, Error: err.Error()} } + var versioning bool + if strVersioned, ok := params["versioning"]; ok { + if versioning, err = strconv.ParseBool(strVersioned); err != nil { + stats.Report(c.vu, createBucketFails, 1) + return CreateBucketResponse{Success: false, Error: err.Error()} + } + } + if versioning { + _, err = c.cli.PutBucketVersioning(context.TODO(), &s3.PutBucketVersioningInput{ + Bucket: aws.String(bucket), + VersioningConfiguration: &types.VersioningConfiguration{ + Status: types.BucketVersioningStatusEnabled, + }, + }) + if err != nil { + stats.Report(c.vu, createBucketFails, 1) + return CreateBucketResponse{Success: false, Error: err.Error()} + } + } + stats.Report(c.vu, createBucketSuccess, 1) stats.Report(c.vu, createBucketDuration, metrics.D(time.Since(start))) return CreateBucketResponse{Success: true}