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

Method RestoreObject

api-restore.go:144–182  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

142
143// RestoreObject is a implementation of https://docs.aws.amazon.com/AmazonS3/latest/API/API_RestoreObject.html AWS S3 API
144func (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}

Callers 2

mainFunction · 0.80
mainFunction · 0.80

Calls 9

executeMethodMethod · 0.95
CheckValidBucketNameFunction · 0.92
CheckValidObjectNameFunction · 0.92
sumMD5Base64Function · 0.85
sum256HexFunction · 0.85
httpRespToErrorResponseFunction · 0.85
closeResponseFunction · 0.70
MarshalMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected