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

Method PutObjectLegalHold

api-object-legal-hold.go:93–144  ·  view source on GitHub ↗

PutObjectLegalHold sets the legal hold status for an object and specific version. Legal hold prevents an object version from being overwritten or deleted, regardless of retention settings. Parameters: - ctx: Context for request cancellation and timeout - bucketName: Name of the bucket - objectName:

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

Source from the content-addressed store, hash-verified

91//
92// Returns an error if the operation fails or if the status is invalid.
93func (c *Client) PutObjectLegalHold(ctx context.Context, bucketName, objectName string, opts PutObjectLegalHoldOptions) error {
94 // Input validation.
95 if err := s3utils.CheckValidBucketName(bucketName); err != nil {
96 return err
97 }
98
99 if err := s3utils.CheckValidObjectName(objectName); err != nil {
100 return err
101 }
102
103 // Get resources properly escaped and lined up before
104 // using them in http request.
105 urlValues := make(url.Values)
106 urlValues.Set("legal-hold", "")
107
108 if opts.VersionID != "" {
109 urlValues.Set("versionId", opts.VersionID)
110 }
111
112 lh, err := newObjectLegalHold(opts.Status)
113 if err != nil {
114 return err
115 }
116
117 lhData, err := xml.Marshal(lh)
118 if err != nil {
119 return err
120 }
121
122 reqMetadata := requestMetadata{
123 bucketName: bucketName,
124 objectName: objectName,
125 queryValues: urlValues,
126 contentBody: bytes.NewReader(lhData),
127 contentLength: int64(len(lhData)),
128 contentMD5Base64: sumMD5Base64(lhData),
129 contentSHA256Hex: sum256Hex(lhData),
130 }
131
132 // Execute PUT Object Legal Hold.
133 resp, err := c.executeMethod(ctx, http.MethodPut, reqMetadata)
134 defer closeResponse(resp)
135 if err != nil {
136 return err
137 }
138 if resp != nil {
139 if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent {
140 return httpRespToErrorResponse(resp, bucketName, objectName)
141 }
142 }
143 return nil
144}
145
146// GetObjectLegalHold retrieves the legal hold status for an object and specific version.
147//

Callers 1

mainFunction · 0.80

Calls 10

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