2016-07-24 01:51:12 -04:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-07-24 01:51:12 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2016-08-05 01:01:58 -04:00
|
|
|
"encoding/json"
|
2016-07-24 01:51:12 -04:00
|
|
|
"encoding/xml"
|
2016-09-27 15:50:32 -04:00
|
|
|
"fmt"
|
2016-07-24 01:51:12 -04:00
|
|
|
"io"
|
|
|
|
"net/http"
|
2016-08-05 01:01:58 -04:00
|
|
|
"time"
|
2016-07-24 01:51:12 -04:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
bucketConfigPrefix = "buckets"
|
|
|
|
bucketNotificationConfig = "notification.xml"
|
2016-10-12 04:03:50 -04:00
|
|
|
bucketListenerConfig = "listener.json"
|
2016-07-24 01:51:12 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetBucketNotificationHandler - This implementation of the GET
|
|
|
|
// operation uses the notification subresource to return the
|
|
|
|
// notification configuration of a bucket. If notifications are
|
|
|
|
// not enabled on the bucket, the operation returns an empty
|
|
|
|
// NotificationConfiguration element.
|
|
|
|
func (api objectAPIHandlers) GetBucketNotificationHandler(w http.ResponseWriter, r *http.Request) {
|
2016-08-10 21:47:49 -04:00
|
|
|
objAPI := api.ObjectAPI()
|
|
|
|
if objAPI == nil {
|
|
|
|
writeErrorResponse(w, r, ErrServerNotInitialized, r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:51:05 -05:00
|
|
|
if s3Error := checkRequestAuthType(r, "", "", serverConfig.GetRegion()); s3Error != ErrNone {
|
2016-07-24 01:51:12 -04:00
|
|
|
writeErrorResponse(w, r, s3Error, r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
2016-11-21 16:51:05 -05:00
|
|
|
|
2016-07-24 01:51:12 -04:00
|
|
|
vars := mux.Vars(r)
|
|
|
|
bucket := vars["bucket"]
|
2016-11-14 18:45:00 -05:00
|
|
|
|
|
|
|
_, err := objAPI.GetBucketInfo(bucket)
|
|
|
|
if err != nil {
|
|
|
|
errorIf(err, "Unable to find bucket info.")
|
|
|
|
writeErrorResponse(w, r, toAPIErrorCode(err), r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-08-05 01:01:58 -04:00
|
|
|
// Attempt to successfully load notification config.
|
2016-07-31 17:11:14 -04:00
|
|
|
nConfig, err := loadNotificationConfig(bucket, objAPI)
|
2016-08-05 01:01:58 -04:00
|
|
|
if err != nil && err != errNoSuchNotifications {
|
|
|
|
errorIf(err, "Unable to read notification configuration.")
|
2016-07-24 01:51:12 -04:00
|
|
|
writeErrorResponse(w, r, toAPIErrorCode(err), r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
2016-08-05 01:01:58 -04:00
|
|
|
// For no notifications we write a dummy XML.
|
|
|
|
if err == errNoSuchNotifications {
|
|
|
|
// Complies with the s3 behavior in this regard.
|
|
|
|
nConfig = ¬ificationConfig{}
|
|
|
|
}
|
|
|
|
notificationBytes, err := xml.Marshal(nConfig)
|
2016-07-24 01:51:12 -04:00
|
|
|
if err != nil {
|
2016-08-05 01:01:58 -04:00
|
|
|
// For any marshalling failure.
|
|
|
|
errorIf(err, "Unable to marshal notification configuration into XML.", err)
|
|
|
|
writeErrorResponse(w, r, toAPIErrorCode(err), r.URL.Path)
|
2016-07-24 01:51:12 -04:00
|
|
|
return
|
|
|
|
}
|
2016-08-05 01:01:58 -04:00
|
|
|
// Success.
|
|
|
|
writeSuccessResponse(w, notificationBytes)
|
2016-07-24 01:51:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// PutBucketNotificationHandler - Minio notification feature enables
|
|
|
|
// you to receive notifications when certain events happen in your bucket.
|
|
|
|
// Using this API, you can replace an existing notification configuration.
|
|
|
|
// The configuration is an XML file that defines the event types that you
|
|
|
|
// want Minio to publish and the destination where you want Minio to publish
|
|
|
|
// an event notification when it detects an event of the specified type.
|
|
|
|
// By default, your bucket has no event notifications configured. That is,
|
|
|
|
// the notification configuration will be an empty NotificationConfiguration.
|
|
|
|
func (api objectAPIHandlers) PutBucketNotificationHandler(w http.ResponseWriter, r *http.Request) {
|
2016-08-10 21:47:49 -04:00
|
|
|
objectAPI := api.ObjectAPI()
|
|
|
|
if objectAPI == nil {
|
|
|
|
writeErrorResponse(w, r, ErrServerNotInitialized, r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:51:05 -05:00
|
|
|
if s3Error := checkRequestAuthType(r, "", "", serverConfig.GetRegion()); s3Error != ErrNone {
|
2016-07-24 01:51:12 -04:00
|
|
|
writeErrorResponse(w, r, s3Error, r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
2016-11-21 16:51:05 -05:00
|
|
|
|
2016-07-24 01:51:12 -04:00
|
|
|
vars := mux.Vars(r)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
|
2016-07-31 17:11:14 -04:00
|
|
|
_, err := objectAPI.GetBucketInfo(bucket)
|
2016-07-24 01:51:12 -04:00
|
|
|
if err != nil {
|
2016-08-21 15:06:53 -04:00
|
|
|
errorIf(err, "Unable to find bucket info.")
|
2016-07-24 01:51:12 -04:00
|
|
|
writeErrorResponse(w, r, toAPIErrorCode(err), r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// If Content-Length is unknown or zero, deny the request. PutBucketNotification
|
|
|
|
// always needs a Content-Length if incoming request is not chunked.
|
|
|
|
if !contains(r.TransferEncoding, "chunked") {
|
|
|
|
if r.ContentLength == -1 {
|
|
|
|
writeErrorResponse(w, r, ErrMissingContentLength, r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reads the incoming notification configuration.
|
|
|
|
var buffer bytes.Buffer
|
|
|
|
if r.ContentLength >= 0 {
|
2016-10-12 04:03:50 -04:00
|
|
|
_, err = io.CopyN(&buffer, r.Body, r.ContentLength)
|
2016-07-24 01:51:12 -04:00
|
|
|
} else {
|
2016-10-12 04:03:50 -04:00
|
|
|
_, err = io.Copy(&buffer, r.Body)
|
2016-07-24 01:51:12 -04:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
errorIf(err, "Unable to read incoming body.")
|
|
|
|
writeErrorResponse(w, r, toAPIErrorCode(err), r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var notificationCfg notificationConfig
|
|
|
|
// Unmarshal notification bytes.
|
|
|
|
notificationConfigBytes := buffer.Bytes()
|
|
|
|
if err = xml.Unmarshal(notificationConfigBytes, ¬ificationCfg); err != nil {
|
|
|
|
errorIf(err, "Unable to parse notification configuration XML.")
|
|
|
|
writeErrorResponse(w, r, ErrMalformedXML, r.URL.Path)
|
|
|
|
return
|
|
|
|
} // Successfully marshalled notification configuration.
|
|
|
|
|
|
|
|
// Validate unmarshalled bucket notification configuration.
|
|
|
|
if s3Error := validateNotificationConfig(notificationCfg); s3Error != ErrNone {
|
|
|
|
writeErrorResponse(w, r, s3Error, r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
// Put bucket notification config.
|
|
|
|
err = PutBucketNotificationConfig(bucket, ¬ificationCfg, objectAPI)
|
2016-07-24 01:51:12 -04:00
|
|
|
if err != nil {
|
|
|
|
writeErrorResponse(w, r, toAPIErrorCode(err), r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Success.
|
|
|
|
writeSuccessResponse(w, nil)
|
|
|
|
}
|
2016-08-05 01:01:58 -04:00
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
// PutBucketNotificationConfig - Put a new notification config for a
|
|
|
|
// bucket (overwrites any previous config) persistently, updates
|
|
|
|
// global in-memory state, and notify other nodes in the cluster (if
|
|
|
|
// any)
|
|
|
|
func PutBucketNotificationConfig(bucket string, ncfg *notificationConfig, objAPI ObjectLayer) error {
|
|
|
|
if ncfg == nil {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
|
2016-10-24 22:52:24 -04:00
|
|
|
// Acquire a write lock on bucket before modifying its
|
|
|
|
// configuration.
|
2016-12-10 19:15:12 -05:00
|
|
|
bucketLock := globalNSMutex.NewNSLock(bucket, "")
|
2016-11-09 13:58:41 -05:00
|
|
|
bucketLock.Lock()
|
2016-10-24 22:52:24 -04:00
|
|
|
// Release lock after notifying peers
|
2016-11-09 13:58:41 -05:00
|
|
|
defer bucketLock.Unlock()
|
2016-10-24 22:52:24 -04:00
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
// persist config to disk
|
|
|
|
err := persistNotificationConfig(bucket, ncfg, objAPI)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Unable to persist Bucket notification config to object layer - config=%v errMsg=%v", *ncfg, err)
|
|
|
|
}
|
|
|
|
|
2016-11-14 18:45:00 -05:00
|
|
|
// All servers (including local) are told to update in-memory config
|
2016-10-12 04:03:50 -04:00
|
|
|
S3PeersUpdateBucketNotification(bucket, ncfg)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-05 01:01:58 -04:00
|
|
|
// writeNotification marshals notification message before writing to client.
|
|
|
|
func writeNotification(w http.ResponseWriter, notification map[string][]NotificationEvent) error {
|
|
|
|
// Invalid response writer.
|
|
|
|
if w == nil {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
// Invalid notification input.
|
|
|
|
if notification == nil {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
2016-10-12 04:03:50 -04:00
|
|
|
// Marshal notification data into JSON and write to client.
|
2016-08-05 01:01:58 -04:00
|
|
|
notificationBytes, err := json.Marshal(¬ification)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Add additional CRLF characters for client to
|
|
|
|
// differentiate the individual events properly.
|
|
|
|
_, err = w.Write(append(notificationBytes, crlf...))
|
|
|
|
// Make sure we have flushed, this would set Transfer-Encoding: chunked.
|
|
|
|
w.(http.Flusher).Flush()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CRLF character used for chunked transfer in accordance with HTTP standards.
|
|
|
|
var crlf = []byte("\r\n")
|
|
|
|
|
|
|
|
// sendBucketNotification - writes notification back to client on the response writer
|
|
|
|
// for each notification input, otherwise writes whitespace characters periodically
|
|
|
|
// to keep the connection active. Each notification messages are terminated by CRLF
|
|
|
|
// character. Upon any error received on response writer the for loop exits.
|
|
|
|
func sendBucketNotification(w http.ResponseWriter, arnListenerCh <-chan []NotificationEvent) {
|
|
|
|
var dummyEvents = map[string][]NotificationEvent{"Records": nil}
|
|
|
|
// Continuously write to client either timely empty structures
|
|
|
|
// every 5 seconds, or return back the notifications.
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case events := <-arnListenerCh:
|
|
|
|
if err := writeNotification(w, map[string][]NotificationEvent{"Records": events}); err != nil {
|
|
|
|
errorIf(err, "Unable to write notification to client.")
|
|
|
|
return
|
|
|
|
}
|
2016-10-22 01:56:27 -04:00
|
|
|
case <-time.After(globalSNSConnAlive): // Wait for global conn active seconds.
|
2016-08-05 01:01:58 -04:00
|
|
|
if err := writeNotification(w, dummyEvents); err != nil {
|
2016-10-22 01:56:27 -04:00
|
|
|
// FIXME - do not log for all errors.
|
2016-08-05 01:01:58 -04:00
|
|
|
errorIf(err, "Unable to write notification to client.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListenBucketNotificationHandler - list bucket notifications.
|
|
|
|
func (api objectAPIHandlers) ListenBucketNotificationHandler(w http.ResponseWriter, r *http.Request) {
|
2016-08-10 21:47:49 -04:00
|
|
|
// Validate if bucket exists.
|
|
|
|
objAPI := api.ObjectAPI()
|
|
|
|
if objAPI == nil {
|
|
|
|
writeErrorResponse(w, r, ErrServerNotInitialized, r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:51:05 -05:00
|
|
|
if s3Error := checkRequestAuthType(r, "", "", serverConfig.GetRegion()); s3Error != ErrNone {
|
2016-08-05 01:01:58 -04:00
|
|
|
writeErrorResponse(w, r, s3Error, r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
2016-11-21 16:51:05 -05:00
|
|
|
|
2016-08-05 01:01:58 -04:00
|
|
|
vars := mux.Vars(r)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
|
2016-09-27 15:50:32 -04:00
|
|
|
// Parse listen bucket notification resources.
|
2016-10-12 14:02:15 -04:00
|
|
|
prefixes, suffixes, events := getListenBucketNotificationResources(r.URL.Query())
|
|
|
|
|
|
|
|
if err := validateFilterValues(prefixes); err != ErrNone {
|
|
|
|
writeErrorResponse(w, r, err, r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := validateFilterValues(suffixes); err != ErrNone {
|
|
|
|
writeErrorResponse(w, r, err, r.URL.Path)
|
2016-08-05 01:01:58 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-09-27 15:50:32 -04:00
|
|
|
// Validate all the resource events.
|
|
|
|
for _, event := range events {
|
|
|
|
if errCode := checkEvent(event); errCode != ErrNone {
|
|
|
|
writeErrorResponse(w, r, errCode, r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-31 17:11:14 -04:00
|
|
|
_, err := objAPI.GetBucketInfo(bucket)
|
2016-08-05 01:01:58 -04:00
|
|
|
if err != nil {
|
2016-10-12 04:03:50 -04:00
|
|
|
errorIf(err, "Unable to get bucket info.")
|
2016-08-05 01:01:58 -04:00
|
|
|
writeErrorResponse(w, r, toAPIErrorCode(err), r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-09-27 15:50:32 -04:00
|
|
|
accountID := fmt.Sprintf("%d", time.Now().UTC().UnixNano())
|
2016-10-12 04:03:50 -04:00
|
|
|
accountARN := fmt.Sprintf(
|
2016-10-21 04:25:17 -04:00
|
|
|
"%s:%s:%s:%s-%s",
|
|
|
|
minioTopic,
|
2016-10-12 04:03:50 -04:00
|
|
|
serverConfig.GetRegion(),
|
|
|
|
accountID,
|
2016-10-21 04:25:17 -04:00
|
|
|
snsTypeMinio,
|
2016-10-12 04:03:50 -04:00
|
|
|
globalMinioAddr,
|
|
|
|
)
|
2016-09-27 15:50:32 -04:00
|
|
|
var filterRules []filterRule
|
2016-10-12 14:02:15 -04:00
|
|
|
|
|
|
|
for _, prefix := range prefixes {
|
2016-09-27 15:50:32 -04:00
|
|
|
filterRules = append(filterRules, filterRule{
|
|
|
|
Name: "prefix",
|
|
|
|
Value: prefix,
|
|
|
|
})
|
|
|
|
}
|
2016-10-12 14:02:15 -04:00
|
|
|
|
|
|
|
for _, suffix := range suffixes {
|
2016-09-27 15:50:32 -04:00
|
|
|
filterRules = append(filterRules, filterRule{
|
|
|
|
Name: "suffix",
|
|
|
|
Value: suffix,
|
|
|
|
})
|
2016-08-05 01:01:58 -04:00
|
|
|
}
|
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
// Make topic configuration corresponding to this
|
|
|
|
// ListenBucketNotification request.
|
2016-09-29 01:46:19 -04:00
|
|
|
topicCfg := &topicConfig{
|
|
|
|
TopicARN: accountARN,
|
2016-10-12 04:03:50 -04:00
|
|
|
ServiceConfig: ServiceConfig{
|
2016-09-29 01:46:19 -04:00
|
|
|
Events: events,
|
|
|
|
Filter: struct {
|
2016-10-12 04:03:50 -04:00
|
|
|
Key keyFilter `xml:"S3Key,omitempty" json:"S3Key,omitempty"`
|
2016-09-29 01:46:19 -04:00
|
|
|
}{
|
|
|
|
Key: keyFilter{
|
|
|
|
FilterRules: filterRules,
|
2016-09-27 15:50:32 -04:00
|
|
|
},
|
|
|
|
},
|
2016-09-29 01:46:19 -04:00
|
|
|
ID: "sns-" + accountID,
|
|
|
|
},
|
2016-09-27 15:50:32 -04:00
|
|
|
}
|
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
// Setup a listening channel that will receive notifications
|
|
|
|
// from the RPC handler.
|
|
|
|
nEventCh := make(chan []NotificationEvent)
|
|
|
|
defer close(nEventCh)
|
|
|
|
// Add channel for listener events
|
2016-10-16 23:52:10 -04:00
|
|
|
if err = globalEventNotifier.AddListenerChan(accountARN, nEventCh); err != nil {
|
|
|
|
errorIf(err, "Error adding a listener!")
|
|
|
|
writeErrorResponse(w, r, toAPIErrorCode(err), r.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
2016-10-12 04:03:50 -04:00
|
|
|
// Remove listener channel after the writer has closed or the
|
|
|
|
// client disconnected.
|
|
|
|
defer globalEventNotifier.RemoveListenerChan(accountARN)
|
|
|
|
|
|
|
|
// Update topic config to bucket config and persist - as soon
|
|
|
|
// as this call compelets, events may start appearing in
|
|
|
|
// nEventCh
|
|
|
|
lc := listenerConfig{
|
|
|
|
TopicConfig: *topicCfg,
|
|
|
|
TargetServer: globalMinioAddr,
|
|
|
|
}
|
2016-10-21 04:25:17 -04:00
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
err = AddBucketListenerConfig(bucket, &lc, objAPI)
|
|
|
|
if err != nil {
|
2016-09-27 15:50:32 -04:00
|
|
|
writeErrorResponse(w, r, toAPIErrorCode(err), r.URL.Path)
|
2016-08-05 01:01:58 -04:00
|
|
|
return
|
|
|
|
}
|
2016-10-12 04:03:50 -04:00
|
|
|
defer RemoveBucketListenerConfig(bucket, &lc, objAPI)
|
2016-08-05 01:01:58 -04:00
|
|
|
|
|
|
|
// Add all common headers.
|
|
|
|
setCommonHeaders(w)
|
|
|
|
|
|
|
|
// Start sending bucket notifications.
|
|
|
|
sendBucketNotification(w, nEventCh)
|
|
|
|
}
|
2016-08-09 14:33:45 -04:00
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
// AddBucketListenerConfig - Updates on disk state of listeners, and
|
|
|
|
// updates all peers with the change in listener config.
|
|
|
|
func AddBucketListenerConfig(bucket string, lcfg *listenerConfig, objAPI ObjectLayer) error {
|
|
|
|
if lcfg == nil {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
listenerCfgs := globalEventNotifier.GetBucketListenerConfig(bucket)
|
|
|
|
|
|
|
|
// add new lid to listeners and persist to object layer.
|
|
|
|
listenerCfgs = append(listenerCfgs, *lcfg)
|
|
|
|
|
2016-10-24 22:52:24 -04:00
|
|
|
// Acquire a write lock on bucket before modifying its
|
|
|
|
// configuration.
|
2016-12-10 19:15:12 -05:00
|
|
|
bucketLock := globalNSMutex.NewNSLock(bucket, "")
|
2016-11-09 13:58:41 -05:00
|
|
|
bucketLock.Lock()
|
2016-10-24 22:52:24 -04:00
|
|
|
// Release lock after notifying peers
|
2016-11-09 13:58:41 -05:00
|
|
|
defer bucketLock.Unlock()
|
2016-10-24 22:52:24 -04:00
|
|
|
|
2016-10-26 23:13:00 -04:00
|
|
|
// update persistent config if dist XL
|
2016-11-07 15:09:24 -05:00
|
|
|
if globalIsDistXL {
|
2016-10-26 23:13:00 -04:00
|
|
|
err := persistListenerConfig(bucket, listenerCfgs, objAPI)
|
|
|
|
if err != nil {
|
|
|
|
errorIf(err, "Error persisting listener config when adding a listener.")
|
|
|
|
return err
|
|
|
|
}
|
2016-10-12 04:03:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// persistence success - now update in-memory globals on all
|
|
|
|
// peers (including local)
|
|
|
|
S3PeersUpdateBucketListener(bucket, listenerCfgs)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveBucketListenerConfig - removes a given bucket notification config
|
|
|
|
func RemoveBucketListenerConfig(bucket string, lcfg *listenerConfig, objAPI ObjectLayer) {
|
|
|
|
listenerCfgs := globalEventNotifier.GetBucketListenerConfig(bucket)
|
|
|
|
|
|
|
|
// remove listener with matching ARN - if not found ignore and
|
|
|
|
// exit.
|
|
|
|
var updatedLcfgs []listenerConfig
|
|
|
|
found := false
|
|
|
|
for k, configuredLcfg := range listenerCfgs {
|
|
|
|
if configuredLcfg.TopicConfig.TopicARN == lcfg.TopicConfig.TopicARN {
|
|
|
|
updatedLcfgs = append(listenerCfgs[:k],
|
|
|
|
listenerCfgs[k+1:]...)
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-10-24 22:52:24 -04:00
|
|
|
// Acquire a write lock on bucket before modifying its
|
|
|
|
// configuration.
|
2016-12-10 19:15:12 -05:00
|
|
|
bucketLock := globalNSMutex.NewNSLock(bucket, "")
|
2016-11-09 13:58:41 -05:00
|
|
|
bucketLock.Lock()
|
2016-10-24 22:52:24 -04:00
|
|
|
// Release lock after notifying peers
|
2016-11-09 13:58:41 -05:00
|
|
|
defer bucketLock.Unlock()
|
2016-10-24 22:52:24 -04:00
|
|
|
|
2016-10-26 23:13:00 -04:00
|
|
|
// update persistent config if dist XL
|
2016-11-07 15:09:24 -05:00
|
|
|
if globalIsDistXL {
|
2016-10-26 23:13:00 -04:00
|
|
|
err := persistListenerConfig(bucket, updatedLcfgs, objAPI)
|
|
|
|
if err != nil {
|
|
|
|
errorIf(err, "Error persisting listener config when removing a listener.")
|
|
|
|
return
|
|
|
|
}
|
2016-10-12 04:03:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// persistence success - now update in-memory globals on all
|
|
|
|
// peers (including local)
|
|
|
|
S3PeersUpdateBucketListener(bucket, updatedLcfgs)
|
|
|
|
}
|