SetBucketObjectLockConfig sets object lock configuration in given bucket. mode, validity and unit are either all set or all nil.
(ctx context.Context, bucketName string, mode *RetentionMode, validity *uint, unit *ValidityUnit)
| 140 | |
| 141 | // SetBucketObjectLockConfig sets object lock configuration in given bucket. mode, validity and unit are either all set or all nil. |
| 142 | func (c *Client) SetBucketObjectLockConfig(ctx context.Context, bucketName string, mode *RetentionMode, validity *uint, unit *ValidityUnit) error { |
| 143 | // Input validation. |
| 144 | if err := s3utils.CheckValidBucketName(bucketName); err != nil { |
| 145 | return err |
| 146 | } |
| 147 | |
| 148 | // Get resources properly escaped and lined up before |
| 149 | // using them in http request. |
| 150 | urlValues := make(url.Values) |
| 151 | urlValues.Set("object-lock", "") |
| 152 | |
| 153 | config, err := newObjectLockConfig(mode, validity, unit) |
| 154 | if err != nil { |
| 155 | return err |
| 156 | } |
| 157 | |
| 158 | configData, err := xml.Marshal(config) |
| 159 | if err != nil { |
| 160 | return err |
| 161 | } |
| 162 | |
| 163 | reqMetadata := requestMetadata{ |
| 164 | bucketName: bucketName, |
| 165 | queryValues: urlValues, |
| 166 | contentBody: bytes.NewReader(configData), |
| 167 | contentLength: int64(len(configData)), |
| 168 | contentMD5Base64: sumMD5Base64(configData), |
| 169 | contentSHA256Hex: sum256Hex(configData), |
| 170 | } |
| 171 | |
| 172 | // Execute PUT bucket object lock configuration. |
| 173 | resp, err := c.executeMethod(ctx, http.MethodPut, reqMetadata) |
| 174 | defer closeResponse(resp) |
| 175 | if err != nil { |
| 176 | return err |
| 177 | } |
| 178 | if resp != nil { |
| 179 | if resp.StatusCode != http.StatusOK { |
| 180 | return httpRespToErrorResponse(resp, bucketName, "") |
| 181 | } |
| 182 | } |
| 183 | return nil |
| 184 | } |
| 185 | |
| 186 | // GetObjectLockConfig gets object lock configuration of given bucket. |
| 187 | func (c *Client) GetObjectLockConfig(ctx context.Context, bucketName string) (objectLock string, mode *RetentionMode, validity *uint, unit *ValidityUnit, err error) { |
no test coverage detected