MCPcopy
hub / github.com/minio/minio-go / SetBucketVersioning

Method SetBucketVersioning

api-bucket-versioning.go:30–67  ·  view source on GitHub ↗

SetBucketVersioning sets a bucket versioning configuration

(ctx context.Context, bucketName string, config BucketVersioningConfiguration)

Source from the content-addressed store, hash-verified

28
29// SetBucketVersioning sets a bucket versioning configuration
30func (c *Client) SetBucketVersioning(ctx context.Context, bucketName string, config BucketVersioningConfiguration) error {
31 // Input validation.
32 if err := s3utils.CheckValidBucketName(bucketName); err != nil {
33 return err
34 }
35
36 buf, err := xml.Marshal(config)
37 if err != nil {
38 return err
39 }
40
41 // Get resources properly escaped and lined up before
42 // using them in http request.
43 urlValues := make(url.Values)
44 urlValues.Set("versioning", "")
45
46 reqMetadata := requestMetadata{
47 bucketName: bucketName,
48 queryValues: urlValues,
49 contentBody: bytes.NewReader(buf),
50 contentLength: int64(len(buf)),
51 contentMD5Base64: sumMD5Base64(buf),
52 contentSHA256Hex: sum256Hex(buf),
53 }
54
55 // Execute PUT to set a bucket versioning.
56 resp, err := c.executeMethod(ctx, http.MethodPut, reqMetadata)
57 defer closeResponse(resp)
58 if err != nil {
59 return err
60 }
61 if resp != nil {
62 if resp.StatusCode != http.StatusOK {
63 return httpRespToErrorResponse(resp, bucketName, "")
64 }
65 }
66 return nil
67}
68
69// EnableVersioning - enable object versioning in given bucket.
70func (c *Client) EnableVersioning(ctx context.Context, bucketName string) error {

Callers 2

EnableVersioningMethod · 0.95
SuspendVersioningMethod · 0.95

Calls 8

executeMethodMethod · 0.95
CheckValidBucketNameFunction · 0.92
sumMD5Base64Function · 0.85
sum256HexFunction · 0.85
httpRespToErrorResponseFunction · 0.85
closeResponseFunction · 0.70
MarshalMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected