mirror of
https://github.com/minio/minio.git
synced 2024-12-25 06:35:56 -05:00
Set default namespace for necessary structs (#8903)
This commit is contained in:
parent
0414f01b6e
commit
5bd0e95eef
@ -84,7 +84,6 @@ func (api objectAPIHandlers) GetBucketNotificationHandler(w http.ResponseWriter,
|
|||||||
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
config.XMLNS = "http://s3.amazonaws.com/doc/2006-03-01/"
|
|
||||||
config.SetRegion(globalServerRegion)
|
config.SetRegion(globalServerRegion)
|
||||||
notificationBytes, err := xml.Marshal(config)
|
notificationBytes, err := xml.Marshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -127,11 +126,6 @@ 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,8 +233,7 @@ 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 {
|
||||||
XMLNS string `xml:"xmlns,attr,omitempty"`
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ObjectLockConfiguration"`
|
||||||
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"`
|
||||||
@ -336,8 +335,7 @@ 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 {
|
||||||
XMLNS string `xml:"xmlns,attr,omitempty"`
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ Retention"`
|
||||||
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"`
|
||||||
}
|
}
|
||||||
@ -470,8 +468,7 @@ 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 {
|
||||||
XMLNS string `xml:"xmlns,attr,omitempty"`
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ LegalHold"`
|
||||||
XMLName xml.Name `xml:"LegalHold"`
|
|
||||||
Status LegalHoldStatus `xml:"Status,omitempty"`
|
Status LegalHoldStatus `xml:"Status,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,17 +154,17 @@ func TestParseObjectLockConfig(t *testing.T) {
|
|||||||
expectErr bool
|
expectErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
value: "<ObjectLockConfiguration><ObjectLockEnabled>yes</ObjectLockEnabled></ObjectLockConfiguration>",
|
value: "<ObjectLockConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\" ><ObjectLockEnabled>yes</ObjectLockEnabled></ObjectLockConfiguration>",
|
||||||
expectedErr: fmt.Errorf("only 'Enabled' value is allowd to ObjectLockEnabled element"),
|
expectedErr: fmt.Errorf("only 'Enabled' value is allowd to ObjectLockEnabled element"),
|
||||||
expectErr: true,
|
expectErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "<ObjectLockConfiguration><ObjectLockEnabled>Enabled</ObjectLockEnabled><Rule><DefaultRetention><Mode>COMPLIANCE</Mode><Days>0</Days></DefaultRetention></Rule></ObjectLockConfiguration>",
|
value: "<ObjectLockConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><ObjectLockEnabled>Enabled</ObjectLockEnabled><Rule><DefaultRetention><Mode>COMPLIANCE</Mode><Days>0</Days></DefaultRetention></Rule></ObjectLockConfiguration>",
|
||||||
expectedErr: fmt.Errorf("Default retention period must be a positive integer value for 'Days'"),
|
expectedErr: fmt.Errorf("Default retention period must be a positive integer value for 'Days'"),
|
||||||
expectErr: true,
|
expectErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "<ObjectLockConfiguration><ObjectLockEnabled>Enabled</ObjectLockEnabled><Rule><DefaultRetention><Mode>COMPLIANCE</Mode><Days>30</Days></DefaultRetention></Rule></ObjectLockConfiguration>",
|
value: "<ObjectLockConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><ObjectLockEnabled>Enabled</ObjectLockEnabled><Rule><DefaultRetention><Mode>COMPLIANCE</Mode><Days>30</Days></DefaultRetention></Rule></ObjectLockConfiguration>",
|
||||||
expectedErr: nil,
|
expectedErr: nil,
|
||||||
expectErr: false,
|
expectErr: false,
|
||||||
},
|
},
|
||||||
|
@ -209,8 +209,7 @@ 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 {
|
||||||
XMLNS string `xml:"xmlns,attr,omitempty"`
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ NotificationConfiguration"`
|
||||||
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"`
|
||||||
@ -292,10 +291,5 @@ 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
|
||||||
}
|
}
|
||||||
|
@ -398,7 +398,7 @@ func TestQueueToRulesMap(t *testing.T) {
|
|||||||
|
|
||||||
func TestConfigUnmarshalXML(t *testing.T) {
|
func TestConfigUnmarshalXML(t *testing.T) {
|
||||||
dataCase1 := []byte(`
|
dataCase1 := []byte(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter></Filter>
|
<Filter></Filter>
|
||||||
@ -411,7 +411,7 @@ func TestConfigUnmarshalXML(t *testing.T) {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
dataCase2 := []byte(`
|
dataCase2 := []byte(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter>
|
<Filter>
|
||||||
@ -433,7 +433,7 @@ func TestConfigUnmarshalXML(t *testing.T) {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
dataCase3 := []byte(`
|
dataCase3 := []byte(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter></Filter>
|
<Filter></Filter>
|
||||||
@ -463,7 +463,7 @@ func TestConfigUnmarshalXML(t *testing.T) {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
dataCase4 := []byte(`
|
dataCase4 := []byte(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter></Filter>
|
<Filter></Filter>
|
||||||
@ -492,7 +492,7 @@ func TestConfigUnmarshalXML(t *testing.T) {
|
|||||||
</NotificationConfiguration>
|
</NotificationConfiguration>
|
||||||
`)
|
`)
|
||||||
|
|
||||||
dataCase5 := []byte(`<NotificationConfiguration></NotificationConfiguration>`)
|
dataCase5 := []byte(`<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/" ></NotificationConfiguration>`)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
data []byte
|
data []byte
|
||||||
@ -518,7 +518,7 @@ func TestConfigUnmarshalXML(t *testing.T) {
|
|||||||
|
|
||||||
func TestConfigValidate(t *testing.T) {
|
func TestConfigValidate(t *testing.T) {
|
||||||
data := []byte(`
|
data := []byte(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter></Filter>
|
<Filter></Filter>
|
||||||
@ -535,7 +535,7 @@ func TestConfigValidate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data = []byte(`
|
data = []byte(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter>
|
<Filter>
|
||||||
@ -561,7 +561,7 @@ func TestConfigValidate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data = []byte(`
|
data = []byte(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter></Filter>
|
<Filter></Filter>
|
||||||
@ -625,7 +625,7 @@ func TestConfigValidate(t *testing.T) {
|
|||||||
|
|
||||||
func TestConfigSetRegion(t *testing.T) {
|
func TestConfigSetRegion(t *testing.T) {
|
||||||
data := []byte(`
|
data := []byte(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter></Filter>
|
<Filter></Filter>
|
||||||
@ -642,7 +642,7 @@ func TestConfigSetRegion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data = []byte(`
|
data = []byte(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter>
|
<Filter>
|
||||||
@ -668,7 +668,7 @@ func TestConfigSetRegion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data = []byte(`
|
data = []byte(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter></Filter>
|
<Filter></Filter>
|
||||||
@ -729,7 +729,7 @@ func TestConfigSetRegion(t *testing.T) {
|
|||||||
|
|
||||||
func TestConfigToRulesMap(t *testing.T) {
|
func TestConfigToRulesMap(t *testing.T) {
|
||||||
data := []byte(`
|
data := []byte(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter></Filter>
|
<Filter></Filter>
|
||||||
@ -746,7 +746,7 @@ func TestConfigToRulesMap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data = []byte(`
|
data = []byte(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter>
|
<Filter>
|
||||||
@ -772,7 +772,7 @@ func TestConfigToRulesMap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data = []byte(`
|
data = []byte(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter></Filter>
|
<Filter></Filter>
|
||||||
@ -832,7 +832,7 @@ func TestConfigToRulesMap(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseConfig(t *testing.T) {
|
func TestParseConfig(t *testing.T) {
|
||||||
reader1 := strings.NewReader(`
|
reader1 := strings.NewReader(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter></Filter>
|
<Filter></Filter>
|
||||||
@ -845,7 +845,7 @@ func TestParseConfig(t *testing.T) {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
reader2 := strings.NewReader(`
|
reader2 := strings.NewReader(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter>
|
<Filter>
|
||||||
@ -867,7 +867,7 @@ func TestParseConfig(t *testing.T) {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
reader3 := strings.NewReader(`
|
reader3 := strings.NewReader(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter></Filter>
|
<Filter></Filter>
|
||||||
@ -897,7 +897,7 @@ func TestParseConfig(t *testing.T) {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
reader4 := strings.NewReader(`
|
reader4 := strings.NewReader(`
|
||||||
<NotificationConfiguration>
|
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<QueueConfiguration>
|
<QueueConfiguration>
|
||||||
<Id>1</Id>
|
<Id>1</Id>
|
||||||
<Filter></Filter>
|
<Filter></Filter>
|
||||||
|
Loading…
Reference in New Issue
Block a user