RestoreObject is a implementation of https://docs.aws.amazon.com/AmazonS3/latest/API/API_RestoreObject.html AWS S3 API
(ctx context.Context, bucketName, objectName, versionID string, req RestoreRequest)
| 142 | |
| 143 | // RestoreObject is a implementation of https://docs.aws.amazon.com/AmazonS3/latest/API/API_RestoreObject.html AWS S3 API |
| 144 | func (c *Client) RestoreObject(ctx context.Context, bucketName, objectName, versionID string, req RestoreRequest) error { |
| 145 | // Input validation. |
| 146 | if err := s3utils.CheckValidBucketName(bucketName); err != nil { |
| 147 | return err |
| 148 | } |
| 149 | if err := s3utils.CheckValidObjectName(objectName); err != nil { |
| 150 | return err |
| 151 | } |
| 152 | |
| 153 | restoreRequestBytes, err := xml.Marshal(req) |
| 154 | if err != nil { |
| 155 | return err |
| 156 | } |
| 157 | |
| 158 | urlValues := make(url.Values) |
| 159 | urlValues.Set("restore", "") |
| 160 | if versionID != "" { |
| 161 | urlValues.Set("versionId", versionID) |
| 162 | } |
| 163 | |
| 164 | // Execute POST on bucket/object. |
| 165 | resp, err := c.executeMethod(ctx, http.MethodPost, requestMetadata{ |
| 166 | bucketName: bucketName, |
| 167 | objectName: objectName, |
| 168 | queryValues: urlValues, |
| 169 | contentMD5Base64: sumMD5Base64(restoreRequestBytes), |
| 170 | contentSHA256Hex: sum256Hex(restoreRequestBytes), |
| 171 | contentBody: bytes.NewReader(restoreRequestBytes), |
| 172 | contentLength: int64(len(restoreRequestBytes)), |
| 173 | }) |
| 174 | defer closeResponse(resp) |
| 175 | if err != nil { |
| 176 | return err |
| 177 | } |
| 178 | if resp.StatusCode != http.StatusAccepted && resp.StatusCode != http.StatusOK { |
| 179 | return httpRespToErrorResponse(resp, bucketName, "") |
| 180 | } |
| 181 | return nil |
| 182 | } |
no test coverage detected