From 65a61a9f7de29ebf556de9a12d6792716a13a245 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 20 Jul 2021 15:40:38 +0300 Subject: [PATCH] [#159] Add fetch-owner param Signed-off-by: Denis Kirillov --- api/handler/object_list.go | 24 ++++++++++++++++-------- api/handler/response.go | 2 +- api/layer/object.go | 1 + 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/api/handler/object_list.go b/api/handler/object_list.go index 63eb69994..359e45c67 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 e64750906..da86c141b 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 9ae56cebf..54079b740 100644 --- a/api/layer/object.go +++ b/api/layer/object.go @@ -53,6 +53,7 @@ type ( ListObjectsParamsCommon ContinuationToken string StartAfter string + FetchOwner bool } allObjectParams struct {