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

Method PutObjectRetention

api-object-retention.go:75–135  ·  view source on GitHub ↗

PutObjectRetention sets the retention configuration for an object and specific version. Object retention prevents an object version from being deleted or overwritten for a specified period. Parameters: - ctx: Context for request cancellation and timeout - bucketName: Name of the bucket - objectName

(ctx context.Context, bucketName, objectName string, opts PutObjectRetentionOptions)

Source from the content-addressed store, hash-verified

73//
74// Returns an error if the operation fails or if the retention settings are invalid.
75func (c *Client) PutObjectRetention(ctx context.Context, bucketName, objectName string, opts PutObjectRetentionOptions) error {
76 // Input validation.
77 if err := s3utils.CheckValidBucketName(bucketName); err != nil {
78 return err
79 }
80
81 if err := s3utils.CheckValidObjectName(objectName); err != nil {
82 return err
83 }
84
85 // Get resources properly escaped and lined up before
86 // using them in http request.
87 urlValues := make(url.Values)
88 urlValues.Set("retention", "")
89
90 if opts.VersionID != "" {
91 urlValues.Set("versionId", opts.VersionID)
92 }
93
94 retention, err := newObjectRetention(opts.Mode, opts.RetainUntilDate)
95 if err != nil {
96 return err
97 }
98
99 retentionData, err := xml.Marshal(retention)
100 if err != nil {
101 return err
102 }
103
104 // Build headers.
105 headers := make(http.Header)
106
107 if opts.GovernanceBypass {
108 // Set the bypass goverenance retention header
109 headers.Set(amzBypassGovernance, "true")
110 }
111
112 reqMetadata := requestMetadata{
113 bucketName: bucketName,
114 objectName: objectName,
115 queryValues: urlValues,
116 contentBody: bytes.NewReader(retentionData),
117 contentLength: int64(len(retentionData)),
118 contentMD5Base64: sumMD5Base64(retentionData),
119 contentSHA256Hex: sum256Hex(retentionData),
120 customHeader: headers,
121 }
122
123 // Execute PUT Object Retention.
124 resp, err := c.executeMethod(ctx, http.MethodPut, reqMetadata)
125 defer closeResponse(resp)
126 if err != nil {
127 return err
128 }
129 if resp != nil {
130 if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent {
131 return httpRespToErrorResponse(resp, bucketName, objectName)
132 }

Callers 4

testRemoveObjectsFunction · 0.95
testRemoveObjectsIterFunction · 0.95
mainFunction · 0.80

Calls 10

executeMethodMethod · 0.95
CheckValidBucketNameFunction · 0.92
CheckValidObjectNameFunction · 0.92
newObjectRetentionFunction · 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