diff --git a/api/handler/object_list.go b/api/handler/object_list.go index 63eb6999..359e45c6 100644 --- a/api/handler/object_list.go +++ b/api/handler/object_list.go @@ -44,7 +44,7 @@ func encodeV1(p *layer.ListObjectsParamsV1, list *layer.ListObjectsInfoV1) *List res.CommonPrefixes = fillPrefixes(list.Prefixes, p.Encode) - res.Contents = fillContents(list.Objects, p.Encode) + res.Contents = fillContentsWithOwner(list.Objects, p.Encode) return res } @@ -87,7 +87,7 @@ func encodeV2(p *layer.ListObjectsParamsV2, list *layer.ListObjectsInfoV2) *List res.CommonPrefixes = fillPrefixes(list.Prefixes, p.Encode) - res.Contents = fillContents(list.Objects, p.Encode) + res.Contents = fillContents(list.Objects, p.Encode, p.FetchOwner) return res } @@ -123,6 +123,7 @@ func parseListObjectsArgsV2(r *http.Request) (*layer.ListObjectsParamsV2, error) res.ContinuationToken = r.URL.Query().Get("continuation-token") res.StartAfter = r.URL.Query().Get("start-after") + res.FetchOwner, _ = strconv.ParseBool(r.URL.Query().Get("fetch-owner")) return &res, nil } @@ -160,21 +161,28 @@ func fillPrefixes(src []string, encode string) []CommonPrefix { return dst } -func fillContents(src []*layer.ObjectInfo, encode string) []Object { +func fillContentsWithOwner(src []*layer.ObjectInfo, encode string) []Object { + return fillContents(src, encode, true) +} + +func fillContents(src []*layer.ObjectInfo, encode string, fetchOwner bool) []Object { var dst []Object for _, obj := range src { - dst = append(dst, Object{ + res := Object{ Key: s3PathEncode(obj.Name, encode), Size: obj.Size, LastModified: obj.Created.Format(time.RFC3339), + ETag: obj.HashSum, + } - Owner: Owner{ + if fetchOwner { + res.Owner = &Owner{ ID: obj.Owner.String(), DisplayName: obj.Owner.String(), - }, + } + } - ETag: obj.HashSum, - }) + dst = append(dst, res) } return dst } diff --git a/api/handler/response.go b/api/handler/response.go index e6475090..da86c141 100644 --- a/api/handler/response.go +++ b/api/handler/response.go @@ -71,7 +71,7 @@ type Object struct { Size int64 // Owner of the object. - Owner Owner + Owner *Owner `xml:"Owner,omitempty"` // The class of storage used to store the object. StorageClass string `xml:"StorageClass,omitempty"` diff --git a/api/layer/object.go b/api/layer/object.go index fb31e220..e0060570 100644 --- a/api/layer/object.go +++ b/api/layer/object.go @@ -51,6 +51,7 @@ type ( ListObjectsParamsCommon ContinuationToken string StartAfter string + FetchOwner bool } allObjectParams struct {