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

Method SetBucketNotification

api-bucket-notification.go:35–73  ·  view source on GitHub ↗

SetBucketNotification saves a new bucket notification with a context to control cancellations and timeouts.

(ctx context.Context, bucketName string, config notification.Configuration)

Source from the content-addressed store, hash-verified

33
34// SetBucketNotification saves a new bucket notification with a context to control cancellations and timeouts.
35func (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
76func (c *Client) RemoveAllBucketNotification(ctx context.Context, bucketName string) error {

Callers 3

testBucketNotificationFunction · 0.95
mainFunction · 0.80

Calls 8

executeMethodMethod · 0.95
CheckValidBucketNameFunction · 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