[#159] Add fetch-owner param

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2021-07-20 15:40:38 +03:00
parent 642f8cc3eb
commit 65a61a9f7d
3 changed files with 18 additions and 9 deletions

View file

@ -44,7 +44,7 @@ func encodeV1(p *layer.ListObjectsParamsV1, list *layer.ListObjectsInfoV1) *List
res.CommonPrefixes = fillPrefixes(list.Prefixes, p.Encode) res.CommonPrefixes = fillPrefixes(list.Prefixes, p.Encode)
res.Contents = fillContents(list.Objects, p.Encode) res.Contents = fillContentsWithOwner(list.Objects, p.Encode)
return res return res
} }
@ -87,7 +87,7 @@ func encodeV2(p *layer.ListObjectsParamsV2, list *layer.ListObjectsInfoV2) *List
res.CommonPrefixes = fillPrefixes(list.Prefixes, p.Encode) 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 return res
} }
@ -123,6 +123,7 @@ func parseListObjectsArgsV2(r *http.Request) (*layer.ListObjectsParamsV2, error)
res.ContinuationToken = r.URL.Query().Get("continuation-token") res.ContinuationToken = r.URL.Query().Get("continuation-token")
res.StartAfter = r.URL.Query().Get("start-after") res.StartAfter = r.URL.Query().Get("start-after")
res.FetchOwner, _ = strconv.ParseBool(r.URL.Query().Get("fetch-owner"))
return &res, nil return &res, nil
} }
@ -160,21 +161,28 @@ func fillPrefixes(src []string, encode string) []CommonPrefix {
return dst 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 var dst []Object
for _, obj := range src { for _, obj := range src {
dst = append(dst, Object{ res := Object{
Key: s3PathEncode(obj.Name, encode), Key: s3PathEncode(obj.Name, encode),
Size: obj.Size, Size: obj.Size,
LastModified: obj.Created.Format(time.RFC3339), LastModified: obj.Created.Format(time.RFC3339),
ETag: obj.HashSum,
}
Owner: Owner{ if fetchOwner {
res.Owner = &Owner{
ID: obj.Owner.String(), ID: obj.Owner.String(),
DisplayName: obj.Owner.String(), DisplayName: obj.Owner.String(),
}, }
}
ETag: obj.HashSum, dst = append(dst, res)
})
} }
return dst return dst
} }

View file

@ -71,7 +71,7 @@ type Object struct {
Size int64 Size int64
// Owner of the object. // Owner of the object.
Owner Owner Owner *Owner `xml:"Owner,omitempty"`
// The class of storage used to store the object. // The class of storage used to store the object.
StorageClass string `xml:"StorageClass,omitempty"` StorageClass string `xml:"StorageClass,omitempty"`

View file

@ -53,6 +53,7 @@ type (
ListObjectsParamsCommon ListObjectsParamsCommon
ContinuationToken string ContinuationToken string
StartAfter string StartAfter string
FetchOwner bool
} }
allObjectParams struct { allObjectParams struct {