From b94211bd6623ef8080de0c5424aca347caa0a61f Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 5 Oct 2016 20:12:47 -0700 Subject: [PATCH] api: ListObjectsV1 compliance with AWS S3. (#2856) XSD - xml schema definition for SOAP operations on S3 provides positional restrictions on XML output. Fix the response by re-arranging the positions in accordance with S3 behavior. Fixes #2849 --- cmd/api-response.go | 99 ++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 46 deletions(-) diff --git a/cmd/api-response.go b/cmd/api-response.go index ecffdbfd6..3bd14b676 100644 --- a/cmd/api-response.go +++ b/cmd/api-response.go @@ -40,20 +40,9 @@ type LocationResponse struct { type ListObjectsResponse struct { XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListBucketResult" json:"-"` - CommonPrefixes []CommonPrefix - Contents []Object - - Delimiter string - - // Encoding type used to encode object keys in the response. - EncodingType string - - // A flag that indicates whether or not ListObjects returned all of the results - // that satisfied the search criteria. - IsTruncated bool - Marker string - MaxKeys int - Name string + Name string + Prefix string + Marker string // When response is truncated (the IsTruncated element value in the response // is true), you can use the key name in this field as marker in the subsequent @@ -62,29 +51,28 @@ type ListObjectsResponse struct { // specified. If response does not include the NextMaker and it is truncated, // you can use the value of the last Key in the response as the marker in the // subsequent request to get the next set of object keys. - NextMarker string - Prefix string + NextMarker string `xml:"NextMarker,omitempty"` + + MaxKeys int + Delimiter string + // A flag that indicates whether or not ListObjects returned all of the results + // that satisfied the search criteria. + IsTruncated bool + + Contents []Object + CommonPrefixes []CommonPrefix + + // Encoding type used to encode object keys in the response. + EncodingType string `xml:"EncodingType,omitempty"` } // ListObjectsV2Response - format for list objects response. type ListObjectsV2Response struct { XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListBucketResult" json:"-"` - CommonPrefixes []CommonPrefix - Contents []Object - - Delimiter string - - // Encoding type used to encode object keys in the response. - EncodingType string - - // A flag that indicates whether or not ListObjects returned all of the results - // that satisfied the search criteria. - IsTruncated bool - StartAfter string - MaxKeys int - Name string - + Name string + Prefix string + StartAfter string `xml:"StartAfter,omitempty"` // When response is truncated (the IsTruncated element value in the response // is true), you can use the key name in this field as marker in the subsequent // request to get next set of objects. Server lists objects in alphabetical @@ -92,16 +80,28 @@ type ListObjectsV2Response struct { // specified. If response does not include the NextMaker and it is truncated, // you can use the value of the last Key in the response as the marker in the // subsequent request to get the next set of object keys. - ContinuationToken string - NextContinuationToken string - Prefix string + ContinuationToken string `xml:"ContinuationToken,omitempty"` + NextContinuationToken string `xml:"NextContinuationToken,omitempty"` + + KeyCount int + MaxKeys int + Delimiter string + // A flag that indicates whether or not ListObjects returned all of the results + // that satisfied the search criteria. + IsTruncated bool + + Contents []Object + CommonPrefixes []CommonPrefix + + // Encoding type used to encode object keys in the response. + EncodingType string `xml:"EncodingType,omitempty"` } // Part container for part metadata. type Part struct { PartNumber int - ETag string LastModified string + ETag string Size int64 } @@ -137,23 +137,29 @@ type ListMultipartUploadsResponse struct { UploadIDMarker string `xml:"UploadIdMarker"` NextKeyMarker string NextUploadIDMarker string `xml:"NextUploadIdMarker"` - EncodingType string + Delimiter string + Prefix string + EncodingType string `xml:"EncodingType,omitempty"` MaxUploads int IsTruncated bool - Uploads []Upload `xml:"Upload"` - Prefix string - Delimiter string - CommonPrefixes []CommonPrefix + + // List of pending uploads. + Uploads []Upload `xml:"Upload"` + + // Delimed common prefixes. + CommonPrefixes []CommonPrefix } // ListBucketsResponse - format for list buckets response type ListBucketsResponse struct { XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListAllMyBucketsResult" json:"-"` + + Owner Owner + // Container for one or more buckets. Buckets struct { Buckets []Bucket `xml:"Bucket"` } // Buckets are nested - Owner Owner } // Upload container for in progress multipart upload @@ -179,23 +185,23 @@ type Bucket struct { // Object container for object metadata type Object struct { - ETag string Key string LastModified string // time string of format "2006-01-02T15:04:05.000Z" + ETag string Size int64 + // Owner of the object. Owner Owner // The class of storage used to store the object. StorageClass string } -// CopyObjectResponse container returns ETag and LastModified of the -// successfully copied object +// CopyObjectResponse container returns ETag and LastModified of the successfully copied object type CopyObjectResponse struct { XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ CopyObjectResult" json:"-"` - ETag string - LastModified string // time string of format "2006-01-02T15:04:05.000Z" + LastModified string // time string of format "2006-01-02T15:04:05.000Z" + ETag string // md5sum of the copied object. } // Initiator inherit from Owner struct, fields are same @@ -370,6 +376,7 @@ func generateListObjectsV2Response(bucket, prefix, token, startAfter, delimiter prefixes = append(prefixes, prefixItem) } data.CommonPrefixes = prefixes + data.KeyCount = len(data.Contents) + len(data.CommonPrefixes) return data }