Fix Retention, ObjectLock, LegalHold struct namespaces correctly. (#8909)

Reverts #8903 to allow structs to be unmarshalled 
even if the namespace is missing.
master
poornas 5 years ago committed by GitHub
parent f6a7d4d29b
commit 881e983ed9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      cmd/bucket-notification-handlers.go
  2. 16
      pkg/bucket/object/lock/lock.go
  3. 8
      pkg/event/config.go
  4. 2
      pkg/event/config_test.go

@ -85,6 +85,7 @@ func (api objectAPIHandlers) GetBucketNotificationHandler(w http.ResponseWriter,
return return
} }
config.SetRegion(globalServerRegion) config.SetRegion(globalServerRegion)
config.XMLNS = "http://s3.amazonaws.com/doc/2006-03-01/"
notificationBytes, err := xml.Marshal(config) 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))
@ -126,6 +127,11 @@ func (api objectAPIHandlers) GetBucketNotificationHandler(w http.ResponseWriter,
} }
} }
// If xml namespace is empty, set a default value before returning.
if config.XMLNS == "" {
config.XMLNS = "http://s3.amazonaws.com/doc/2006-03-01/"
}
notificationBytes, err := xml.Marshal(config) 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))

@ -233,7 +233,8 @@ func (dr *DefaultRetention) UnmarshalXML(d *xml.Decoder, start xml.StartElement)
// Config - object lock configuration specified in // Config - object lock configuration specified in
// https://docs.aws.amazon.com/AmazonS3/latest/API/Type_API_ObjectLockConfiguration.html // https://docs.aws.amazon.com/AmazonS3/latest/API/Type_API_ObjectLockConfiguration.html
type Config struct { type Config struct {
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ObjectLockConfiguration"` XMLNS string `xml:"xmlns,attr,omitempty"`
XMLName xml.Name `xml:"ObjectLockConfiguration"`
ObjectLockEnabled string `xml:"ObjectLockEnabled"` ObjectLockEnabled string `xml:"ObjectLockEnabled"`
Rule *struct { Rule *struct {
DefaultRetention DefaultRetention `xml:"DefaultRetention"` DefaultRetention DefaultRetention `xml:"DefaultRetention"`
@ -335,7 +336,8 @@ func (rDate *RetentionDate) MarshalXML(e *xml.Encoder, startElement xml.StartEle
// ObjectRetention specified in // ObjectRetention specified in
// https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectRetention.html // https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectRetention.html
type ObjectRetention struct { type ObjectRetention struct {
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ Retention"` XMLNS string `xml:"xmlns,attr,omitempty"`
XMLName xml.Name `xml:"Retention"`
Mode Mode `xml:"Mode,omitempty"` Mode Mode `xml:"Mode,omitempty"`
RetainUntilDate RetentionDate `xml:"RetainUntilDate,omitempty"` RetainUntilDate RetentionDate `xml:"RetainUntilDate,omitempty"`
} }
@ -438,7 +440,7 @@ func GetObjectRetentionMeta(meta map[string]string) ObjectRetention {
retainTill = RetentionDate{t.UTC()} retainTill = RetentionDate{t.UTC()}
} }
} }
return ObjectRetention{Mode: mode, RetainUntilDate: retainTill} return ObjectRetention{XMLNS: "http://s3.amazonaws.com/doc/2006-03-01/", Mode: mode, RetainUntilDate: retainTill}
} }
// GetObjectLegalHoldMeta constructs ObjectLegalHold from metadata // GetObjectLegalHoldMeta constructs ObjectLegalHold from metadata
@ -446,7 +448,7 @@ func GetObjectLegalHoldMeta(meta map[string]string) ObjectLegalHold {
holdStr, ok := meta[strings.ToLower(xhttp.AmzObjectLockLegalHold)] holdStr, ok := meta[strings.ToLower(xhttp.AmzObjectLockLegalHold)]
if ok { if ok {
return ObjectLegalHold{Status: parseLegalHoldStatus(holdStr)} return ObjectLegalHold{XMLNS: "http://s3.amazonaws.com/doc/2006-03-01/", Status: parseLegalHoldStatus(holdStr)}
} }
return ObjectLegalHold{} return ObjectLegalHold{}
} }
@ -468,7 +470,8 @@ func ParseObjectLockLegalHoldHeaders(h http.Header) (lhold ObjectLegalHold, err
// ObjectLegalHold specified in // ObjectLegalHold specified in
// https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectLegalHold.html // https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectLegalHold.html
type ObjectLegalHold struct { type ObjectLegalHold struct {
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ LegalHold"` XMLNS string `xml:"xmlns,attr,omitempty"`
XMLName xml.Name `xml:"LegalHold"`
Status LegalHoldStatus `xml:"Status,omitempty"` Status LegalHoldStatus `xml:"Status,omitempty"`
} }
@ -481,6 +484,9 @@ func ParseObjectLegalHold(reader io.Reader) (hold *ObjectLegalHold, err error) {
if hold.Status != ON && hold.Status != OFF { if hold.Status != ON && hold.Status != OFF {
return nil, ErrMalformedXML return nil, ErrMalformedXML
} }
if hold.XMLNS == "" {
hold.XMLNS = "http://s3.amazonaws.com/doc/2006-03-01/"
}
return return
} }

@ -209,7 +209,8 @@ type topic struct {
// Config - notification configuration described in // Config - notification configuration described in
// http://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html // http://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html
type Config struct { type Config struct {
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ NotificationConfiguration"` XMLNS string `xml:"xmlns,attr,omitempty"`
XMLName xml.Name `xml:"NotificationConfiguration"`
QueueList []Queue `xml:"QueueConfiguration,omitempty"` QueueList []Queue `xml:"QueueConfiguration,omitempty"`
LambdaList []lambda `xml:"CloudFunctionConfiguration,omitempty"` LambdaList []lambda `xml:"CloudFunctionConfiguration,omitempty"`
TopicList []topic `xml:"TopicConfiguration,omitempty"` TopicList []topic `xml:"TopicConfiguration,omitempty"`
@ -290,6 +291,9 @@ func ParseConfig(reader io.Reader, region string, targetList *TargetList) (*Conf
} }
config.SetRegion(region) config.SetRegion(region)
//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, nil return &config, nil
} }

@ -433,7 +433,7 @@ func TestConfigUnmarshalXML(t *testing.T) {
`) `)
dataCase3 := []byte(` dataCase3 := []byte(`
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <NotificationConfiguration>
<QueueConfiguration> <QueueConfiguration>
<Id>1</Id> <Id>1</Id>
<Filter></Filter> <Filter></Filter>

Loading…
Cancel
Save