Skip to content

Commit 3dbe5a3

Browse files
authored
Add API for bucket resync cancellation (#2101)
1 parent e994501 commit 3dbe5a3

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

api-bucket-replication.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,42 @@ func (c *Client) GetBucketReplicationResyncStatus(ctx context.Context, bucketNam
290290
return rinfo, nil
291291
}
292292

293+
// CancelBucketReplicationResync cancels in progress replication resync
294+
func (c *Client) CancelBucketReplicationResync(ctx context.Context, bucketName string, tgtArn string) (id string, err error) {
295+
// Input validation.
296+
if err = s3utils.CheckValidBucketName(bucketName); err != nil {
297+
return
298+
}
299+
// Get resources properly escaped and lined up before
300+
// using them in http request.
301+
urlValues := make(url.Values)
302+
urlValues.Set("replication-reset-cancel", "")
303+
if tgtArn != "" {
304+
urlValues.Set("arn", tgtArn)
305+
}
306+
// Execute GET on bucket to get replication config.
307+
resp, err := c.executeMethod(ctx, http.MethodPut, requestMetadata{
308+
bucketName: bucketName,
309+
queryValues: urlValues,
310+
})
311+
312+
defer closeResponse(resp)
313+
if err != nil {
314+
return id, err
315+
}
316+
317+
if resp.StatusCode != http.StatusOK {
318+
return id, httpRespToErrorResponse(resp, bucketName, "")
319+
}
320+
strBuf, err := io.ReadAll(resp.Body)
321+
if err != nil {
322+
return "", err
323+
}
324+
325+
id = string(strBuf)
326+
return id, nil
327+
}
328+
293329
// GetBucketReplicationMetricsV2 fetches bucket replication status metrics
294330
func (c *Client) GetBucketReplicationMetricsV2(ctx context.Context, bucketName string) (s replication.MetricsV2, err error) {
295331
// Input validation.

0 commit comments

Comments
 (0)