2020-10-02 12:23:52 +00:00
|
|
|
package v2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
2024-11-07 14:32:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/acl"
|
2023-03-07 13:38:26 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
eaclSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/eacl"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-10-02 12:23:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type sysObjHdr struct {
|
|
|
|
k, v string
|
|
|
|
}
|
|
|
|
|
2022-05-17 13:32:03 +00:00
|
|
|
func (s sysObjHdr) Key() string {
|
2020-10-02 12:23:52 +00:00
|
|
|
return s.k
|
|
|
|
}
|
|
|
|
|
2022-05-17 13:32:03 +00:00
|
|
|
func (s sysObjHdr) Value() string {
|
2020-10-02 12:23:52 +00:00
|
|
|
return s.v
|
|
|
|
}
|
|
|
|
|
|
|
|
func u64Value(v uint64) string {
|
|
|
|
return strconv.FormatUint(v, 10)
|
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func headersFromObject(obj *objectSDK.Object, cnr cid.ID, oid *oid.ID) []eaclSDK.Header {
|
2022-01-19 11:32:10 +00:00
|
|
|
var count int
|
2022-03-03 14:19:05 +00:00
|
|
|
for obj := obj; obj != nil; obj = obj.Parent() {
|
2022-01-19 11:32:10 +00:00
|
|
|
count += 9 + len(obj.Attributes())
|
|
|
|
}
|
2020-10-02 12:23:52 +00:00
|
|
|
|
2022-01-19 11:32:10 +00:00
|
|
|
res := make([]eaclSDK.Header, 0, count)
|
2022-03-03 14:19:05 +00:00
|
|
|
for ; obj != nil; obj = obj.Parent() {
|
2020-10-02 12:23:52 +00:00
|
|
|
res = append(res,
|
2022-05-31 17:00:41 +00:00
|
|
|
cidHeader(cnr),
|
2020-10-02 12:23:52 +00:00
|
|
|
// creation epoch
|
2022-05-17 13:32:03 +00:00
|
|
|
sysObjHdr{
|
2020-10-29 15:01:58 +00:00
|
|
|
k: acl.FilterObjectCreationEpoch,
|
2020-11-16 09:43:52 +00:00
|
|
|
v: u64Value(obj.CreationEpoch()),
|
2020-10-02 12:23:52 +00:00
|
|
|
},
|
|
|
|
// payload size
|
2022-05-17 13:32:03 +00:00
|
|
|
sysObjHdr{
|
2020-10-29 15:01:58 +00:00
|
|
|
k: acl.FilterObjectPayloadLength,
|
2020-11-16 09:43:52 +00:00
|
|
|
v: u64Value(obj.PayloadSize()),
|
2020-10-02 12:23:52 +00:00
|
|
|
},
|
2021-08-25 11:26:41 +00:00
|
|
|
// object version
|
2022-05-17 13:32:03 +00:00
|
|
|
sysObjHdr{
|
2021-08-25 11:26:41 +00:00
|
|
|
k: acl.FilterObjectVersion,
|
|
|
|
v: obj.Version().String(),
|
|
|
|
},
|
|
|
|
// object type
|
2022-05-17 13:32:03 +00:00
|
|
|
sysObjHdr{
|
2021-08-25 11:26:41 +00:00
|
|
|
k: acl.FilterObjectType,
|
|
|
|
v: obj.Type().String(),
|
|
|
|
},
|
2020-10-02 12:23:52 +00:00
|
|
|
)
|
|
|
|
|
2022-05-24 18:47:21 +00:00
|
|
|
if oid != nil {
|
|
|
|
res = append(res, oidHeader(*oid))
|
|
|
|
}
|
|
|
|
|
2023-11-21 08:42:30 +00:00
|
|
|
if idOwner := obj.OwnerID(); !idOwner.IsEmpty() {
|
|
|
|
res = append(res, ownerIDHeader(idOwner))
|
2022-05-17 13:59:46 +00:00
|
|
|
}
|
|
|
|
|
2022-05-11 16:35:01 +00:00
|
|
|
cs, ok := obj.PayloadChecksum()
|
|
|
|
if ok {
|
2022-05-17 13:32:03 +00:00
|
|
|
res = append(res, sysObjHdr{
|
2022-05-11 16:35:01 +00:00
|
|
|
k: acl.FilterObjectPayloadHash,
|
|
|
|
v: cs.String(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
cs, ok = obj.PayloadHomomorphicHash()
|
|
|
|
if ok {
|
2022-05-17 13:32:03 +00:00
|
|
|
res = append(res, sysObjHdr{
|
2022-05-11 16:35:01 +00:00
|
|
|
k: acl.FilterObjectHomomorphicHash,
|
|
|
|
v: cs.String(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-16 09:43:52 +00:00
|
|
|
attrs := obj.Attributes()
|
2020-10-02 12:23:52 +00:00
|
|
|
for i := range attrs {
|
2022-03-15 12:11:35 +00:00
|
|
|
res = append(res, &attrs[i]) // only pointer attrs can implement eaclSDK.Header interface
|
2020-10-02 12:23:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|