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

Method GetObjectLegalHold

api-object-legal-hold.go:155–193  ·  view source on GitHub ↗

GetObjectLegalHold retrieves the legal hold status for an object and specific version. Parameters: - ctx: Context for request cancellation and timeout - bucketName: Name of the bucket - objectName: Name of the object - opts: Options including optional VersionID to target a specific version Returns

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

Source from the content-addressed store, hash-verified

153//
154// Returns the legal hold status (LegalHoldEnabled or LegalHoldDisabled) or an error if the operation fails.
155func (c *Client) GetObjectLegalHold(ctx context.Context, bucketName, objectName string, opts GetObjectLegalHoldOptions) (status *LegalHoldStatus, err error) {
156 // Input validation.
157 if err := s3utils.CheckValidBucketName(bucketName); err != nil {
158 return nil, err
159 }
160
161 if err := s3utils.CheckValidObjectName(objectName); err != nil {
162 return nil, err
163 }
164 urlValues := make(url.Values)
165 urlValues.Set("legal-hold", "")
166
167 if opts.VersionID != "" {
168 urlValues.Set("versionId", opts.VersionID)
169 }
170
171 // Execute GET on bucket to list objects.
172 resp, err := c.executeMethod(ctx, http.MethodGet, requestMetadata{
173 bucketName: bucketName,
174 objectName: objectName,
175 queryValues: urlValues,
176 contentSHA256Hex: emptySHA256Hex,
177 })
178 defer closeResponse(resp)
179 if err != nil {
180 return nil, err
181 }
182 if resp != nil {
183 if resp.StatusCode != http.StatusOK {
184 return nil, httpRespToErrorResponse(resp, bucketName, objectName)
185 }
186 }
187 lh := &objectLegalHold{}
188 if err = xml.NewDecoder(resp.Body).Decode(lh); err != nil {
189 return nil, err
190 }
191
192 return &lh.Status, nil
193}

Callers 1

mainFunction · 0.80

Calls 6

executeMethodMethod · 0.95
CheckValidBucketNameFunction · 0.92
CheckValidObjectNameFunction · 0.92
httpRespToErrorResponseFunction · 0.85
closeResponseFunction · 0.70
SetMethod · 0.45

Tested by

no test coverage detected