Return Owner information in ListObjectV2 only when fetch-owner is specified (#2654)

This commit is contained in:
Anis Elleuch 2016-09-10 18:44:38 +01:00 committed by Harshavardhana
parent e6abfb3b67
commit 8acf4d112a
5 changed files with 35 additions and 10 deletions

View File

@ -36,7 +36,7 @@ func getListObjectsV1Args(values url.Values) (prefix, marker, delimiter string,
} }
// Parse bucket url queries for ListObjects V2. // Parse bucket url queries for ListObjects V2.
func getListObjectsV2Args(values url.Values) (prefix, token, startAfter, delimiter string, maxkeys int, encodingType string) { func getListObjectsV2Args(values url.Values) (prefix, token, startAfter, delimiter string, fetchOwner bool, maxkeys int, encodingType string) {
prefix = values.Get("prefix") prefix = values.Get("prefix")
startAfter = values.Get("start-after") startAfter = values.Get("start-after")
delimiter = values.Get("delimiter") delimiter = values.Get("delimiter")
@ -47,6 +47,9 @@ func getListObjectsV2Args(values url.Values) (prefix, token, startAfter, delimit
} }
encodingType = values.Get("encoding-type") encodingType = values.Get("encoding-type")
token = values.Get("continuation-token") token = values.Get("continuation-token")
if values.Get("fetch-owner") == "true" {
fetchOwner = true
}
return return
} }

View File

@ -327,14 +327,16 @@ func generateListObjectsV1Response(bucket, prefix, marker, delimiter string, max
} }
// generates an ListObjectsV2 response for the said bucket with other enumerated options. // generates an ListObjectsV2 response for the said bucket with other enumerated options.
func generateListObjectsV2Response(bucket, prefix, token, startAfter, delimiter string, maxKeys int, resp ListObjectsInfo) ListObjectsV2Response { func generateListObjectsV2Response(bucket, prefix, token, startAfter, delimiter string, fetchOwner bool, maxKeys int, resp ListObjectsInfo) ListObjectsV2Response {
var contents []Object var contents []Object
var prefixes []CommonPrefix var prefixes []CommonPrefix
var owner = Owner{} var owner = Owner{}
var data = ListObjectsV2Response{} var data = ListObjectsV2Response{}
if fetchOwner {
owner.ID = "minio" owner.ID = "minio"
owner.DisplayName = "minio" owner.DisplayName = "minio"
}
for _, object := range resp.Objects { for _, object := range resp.Objects {
var content = Object{} var content = Object{}

View File

@ -82,7 +82,7 @@ func (api objectAPIHandlers) ListObjectsV2Handler(w http.ResponseWriter, r *http
} }
} }
// Extract all the listObjectsV2 query params to their native values. // Extract all the listObjectsV2 query params to their native values.
prefix, token, startAfter, delimiter, maxKeys, _ := getListObjectsV2Args(r.URL.Query()) prefix, token, startAfter, delimiter, fetchOwner, maxKeys, _ := getListObjectsV2Args(r.URL.Query())
// In ListObjectsV2 'continuation-token' is the marker. // In ListObjectsV2 'continuation-token' is the marker.
marker := token marker := token
@ -91,7 +91,8 @@ func (api objectAPIHandlers) ListObjectsV2Handler(w http.ResponseWriter, r *http
// Then we need to use 'start-after' as marker instead. // Then we need to use 'start-after' as marker instead.
marker = startAfter marker = startAfter
} }
// Validate all the query params before beginning to serve the request. // Validate the query params before beginning to serve the request.
// fetch-owner is not validated since it is a boolean
if s3Error := listObjectsValidateArgs(prefix, marker, delimiter, maxKeys); s3Error != ErrNone { if s3Error := listObjectsValidateArgs(prefix, marker, delimiter, maxKeys); s3Error != ErrNone {
writeErrorResponse(w, r, s3Error, r.URL.Path) writeErrorResponse(w, r, s3Error, r.URL.Path)
return return
@ -106,7 +107,7 @@ func (api objectAPIHandlers) ListObjectsV2Handler(w http.ResponseWriter, r *http
return return
} }
response := generateListObjectsV2Response(bucket, prefix, token, startAfter, delimiter, maxKeys, listObjectsInfo) response := generateListObjectsV2Response(bucket, prefix, token, startAfter, delimiter, fetchOwner, maxKeys, listObjectsInfo)
// Write headers // Write headers
setCommonHeaders(w) setCommonHeaders(w)
// Write success response. // Write success response.

View File

@ -1367,7 +1367,7 @@ func (s *TestSuiteCommon) TestListObjectsHandler(c *C) {
c.Assert(strings.Contains(string(getContent), "<Key>bar</Key>"), Equals, true) c.Assert(strings.Contains(string(getContent), "<Key>bar</Key>"), Equals, true)
// create listObjectsV2 request with valid parameters // create listObjectsV2 request with valid parameters
request, err = newTestSignedRequest("GET", getListObjectsV2URL(s.endPoint, bucketName, "1000"), request, err = newTestSignedRequest("GET", getListObjectsV2URL(s.endPoint, bucketName, "1000", ""),
0, nil, s.accessKey, s.secretKey) 0, nil, s.accessKey, s.secretKey)
c.Assert(err, IsNil) c.Assert(err, IsNil)
client = http.Client{} client = http.Client{}
@ -1378,6 +1378,22 @@ func (s *TestSuiteCommon) TestListObjectsHandler(c *C) {
getContent, err = ioutil.ReadAll(response.Body) getContent, err = ioutil.ReadAll(response.Body)
c.Assert(strings.Contains(string(getContent), "<Key>bar</Key>"), Equals, true) c.Assert(strings.Contains(string(getContent), "<Key>bar</Key>"), Equals, true)
c.Assert(strings.Contains(string(getContent), "<Owner><ID></ID><DisplayName></DisplayName></Owner>"), Equals, true)
// create listObjectsV2 request with valid parameters and fetch-owner activated
request, err = newTestSignedRequest("GET", getListObjectsV2URL(s.endPoint, bucketName, "1000", "true"),
0, nil, s.accessKey, s.secretKey)
c.Assert(err, IsNil)
client = http.Client{}
// execute the HTTP request.
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
getContent, err = ioutil.ReadAll(response.Body)
c.Assert(strings.Contains(string(getContent), "<Key>bar</Key>"), Equals, true)
c.Assert(strings.Contains(string(getContent), "<Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner>"), Equals, true)
} }
// TestListObjectsHandlerErrors - Setting invalid parameters to List Objects // TestListObjectsHandlerErrors - Setting invalid parameters to List Objects
@ -1408,7 +1424,7 @@ func (s *TestSuiteCommon) TestListObjectsHandlerErrors(c *C) {
verifyError(c, response, "InvalidArgument", "Argument maxKeys must be an integer between 0 and 2147483647", http.StatusBadRequest) verifyError(c, response, "InvalidArgument", "Argument maxKeys must be an integer between 0 and 2147483647", http.StatusBadRequest)
// create listObjectsV2 request with invalid value of max-keys parameter. max-keys is set to -2. // create listObjectsV2 request with invalid value of max-keys parameter. max-keys is set to -2.
request, err = newTestSignedRequest("GET", getListObjectsV2URL(s.endPoint, bucketName, "-2"), request, err = newTestSignedRequest("GET", getListObjectsV2URL(s.endPoint, bucketName, "-2", ""),
0, nil, s.accessKey, s.secretKey) 0, nil, s.accessKey, s.secretKey)
c.Assert(err, IsNil) c.Assert(err, IsNil)
client = http.Client{} client = http.Client{}

View File

@ -706,12 +706,15 @@ func getListObjectsV1URL(endPoint, bucketName string, maxKeys string) string {
} }
// return URL for listing objects in the bucket with V2 API. // return URL for listing objects in the bucket with V2 API.
func getListObjectsV2URL(endPoint, bucketName string, maxKeys string) string { func getListObjectsV2URL(endPoint, bucketName string, maxKeys string, fetchOwner string) string {
queryValue := url.Values{} queryValue := url.Values{}
queryValue.Set("list-type", "2") // Enables list objects V2 URL. queryValue.Set("list-type", "2") // Enables list objects V2 URL.
if maxKeys != "" { if maxKeys != "" {
queryValue.Set("max-keys", maxKeys) queryValue.Set("max-keys", maxKeys)
} }
if fetchOwner != "" {
queryValue.Set("fetch-owner", fetchOwner)
}
return makeTestTargetURL(endPoint, bucketName, "", queryValue) return makeTestTargetURL(endPoint, bucketName, "", queryValue)
} }