Ignore stale notification queues in notification.xml (#7673)

Allow renaming/editing a notification config. By replying with 
a successful GetBucketNotification response, without checking 
for any missing config ARN in targetList.

Fixes #7650
master
Praveen raj Mani 5 years ago committed by Nitish Tiwari
parent 8d47ef503c
commit 63e0a81760
  1. 35
      cmd/bucket-notification-handlers.go
  2. 15
      pkg/event/config.go

@ -17,10 +17,12 @@
package cmd package cmd
import ( import (
"bytes"
"encoding/xml" "encoding/xml"
"errors" "errors"
"io" "io"
"net/http" "net/http"
"path"
"github.com/gorilla/mux" "github.com/gorilla/mux"
xhttp "github.com/minio/minio/cmd/http" xhttp "github.com/minio/minio/cmd/http"
@ -49,6 +51,7 @@ func (api objectAPIHandlers) GetBucketNotificationHandler(w http.ResponseWriter,
vars := mux.Vars(r) vars := mux.Vars(r)
bucketName := vars["bucket"] bucketName := vars["bucket"]
var config *event.Config
objAPI := api.ObjectAPI() objAPI := api.ObjectAPI()
if objAPI == nil { if objAPI == nil {
@ -72,24 +75,31 @@ func (api objectAPIHandlers) GetBucketNotificationHandler(w http.ResponseWriter,
return return
} }
// Attempt to successfully load notification config. // Construct path to notification.xml for the given bucket.
nConfig, err := readNotificationConfig(ctx, objAPI, bucketName) configFile := path.Join(bucketConfigPrefix, bucketName, bucketNotificationConfig)
configData, err := readConfig(ctx, objAPI, configFile)
if err != nil { if err != nil {
// Ignore errNoSuchNotifications to comply with AWS S3. if err != errConfigNotFound {
if err != errNoSuchNotifications { writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
return
}
config = &event.Config{}
} else {
if err = xml.NewDecoder(bytes.NewReader(configData)).Decode(&config); err != nil {
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
return return
} }
nConfig = &event.Config{}
} }
config.SetRegion(globalServerConfig.GetRegion())
// If xml namespace is empty, set a default value before returning. // If xml namespace is empty, set a default value before returning.
if nConfig.XMLNS == "" { if config.XMLNS == "" {
nConfig.XMLNS = "http://s3.amazonaws.com/doc/2006-03-01/" config.XMLNS = "http://s3.amazonaws.com/doc/2006-03-01/"
} }
notificationBytes, err := xml.Marshal(nConfig) notificationBytes, err := xml.Marshal(config)
if err != nil { if err != nil {
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
return return
@ -143,9 +153,10 @@ func (api objectAPIHandlers) PutBucketNotificationHandler(w http.ResponseWriter,
if event.IsEventError(err) { if event.IsEventError(err) {
apiErr = toAPIError(ctx, err) apiErr = toAPIError(ctx, err)
} }
if _, ok := err.(*event.ErrARNNotFound); !ok {
writeErrorResponse(ctx, w, apiErr, r.URL, guessIsBrowserReq(r)) writeErrorResponse(ctx, w, apiErr, r.URL, guessIsBrowserReq(r))
return return
}
} }
if err = saveNotificationConfig(ctx, objectAPI, bucketName, config); err != nil { if err = saveNotificationConfig(ctx, objectAPI, bucketName, config); err != nil {

@ -276,15 +276,20 @@ func (conf *Config) ToRulesMap() RulesMap {
// ParseConfig - parses data in reader to notification configuration. // ParseConfig - parses data in reader to notification configuration.
func ParseConfig(reader io.Reader, region string, targetList *TargetList) (*Config, error) { func ParseConfig(reader io.Reader, region string, targetList *TargetList) (*Config, error) {
var config Config var config Config
if err := xml.NewDecoder(reader).Decode(&config); err != nil { var err error
return nil, err
}
if err := config.Validate(region, targetList); err != nil { if err = xml.NewDecoder(reader).Decode(&config); err != nil {
return nil, err return nil, err
} }
err = config.Validate(region, targetList)
config.SetRegion(region) config.SetRegion(region)
return &config, nil // If xml namespace is empty, set a default value before returning.
if config.XMLNS == "" {
config.XMLNS = "http://s3.amazonaws.com/doc/2006-03-01/"
}
return &config, err
} }

Loading…
Cancel
Save