SetBucketVersioning sets a bucket versioning configuration
(ctx context.Context, bucketName string, config BucketVersioningConfiguration)
| 28 | |
| 29 | // SetBucketVersioning sets a bucket versioning configuration |
| 30 | func (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. |
| 70 | func (c *Client) EnableVersioning(ctx context.Context, bucketName string) error { |
no test coverage detected