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

Method SetBucketObjectLockConfig

api-object-lock.go:142–184  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

140
141// SetBucketObjectLockConfig sets object lock configuration in given bucket. mode, validity and unit are either all set or all nil.
142func (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.
187func (c *Client) GetObjectLockConfig(ctx context.Context, bucketName string) (objectLock string, mode *RetentionMode, validity *uint, unit *ValidityUnit, err error) {

Callers 1

SetObjectLockConfigMethod · 0.95

Calls 9

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

Tested by

no test coverage detected