SetBucketNotification saves a new bucket notification with a context to control cancellations and timeouts.
(ctx context.Context, bucketName string, config notification.Configuration)
| 33 | |
| 34 | // SetBucketNotification saves a new bucket notification with a context to control cancellations and timeouts. |
| 35 | func (c *Client) SetBucketNotification(ctx context.Context, bucketName string, config notification.Configuration) error { |
| 36 | // Input validation. |
| 37 | if err := s3utils.CheckValidBucketName(bucketName); err != nil { |
| 38 | return err |
| 39 | } |
| 40 | |
| 41 | // Get resources properly escaped and lined up before |
| 42 | // using them in http request. |
| 43 | urlValues := make(url.Values) |
| 44 | urlValues.Set("notification", "") |
| 45 | |
| 46 | notifBytes, err := xml.Marshal(&config) |
| 47 | if err != nil { |
| 48 | return err |
| 49 | } |
| 50 | |
| 51 | notifBuffer := bytes.NewReader(notifBytes) |
| 52 | reqMetadata := requestMetadata{ |
| 53 | bucketName: bucketName, |
| 54 | queryValues: urlValues, |
| 55 | contentBody: notifBuffer, |
| 56 | contentLength: int64(len(notifBytes)), |
| 57 | contentMD5Base64: sumMD5Base64(notifBytes), |
| 58 | contentSHA256Hex: sum256Hex(notifBytes), |
| 59 | } |
| 60 | |
| 61 | // Execute PUT to upload a new bucket notification. |
| 62 | resp, err := c.executeMethod(ctx, http.MethodPut, reqMetadata) |
| 63 | defer closeResponse(resp) |
| 64 | if err != nil { |
| 65 | return err |
| 66 | } |
| 67 | if resp != nil { |
| 68 | if resp.StatusCode != http.StatusOK { |
| 69 | return httpRespToErrorResponse(resp, bucketName, "") |
| 70 | } |
| 71 | } |
| 72 | return nil |
| 73 | } |
| 74 | |
| 75 | // RemoveAllBucketNotification - Remove bucket notification clears all previously specified config |
| 76 | func (c *Client) RemoveAllBucketNotification(ctx context.Context, bucketName string) error { |
no test coverage detected