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)
| 153 | // |
| 154 | // Returns the legal hold status (LegalHoldEnabled or LegalHoldDisabled) or an error if the operation fails. |
| 155 | func (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 | } |
no test coverage detected