Dmitrii Stepanov
c516c7c5f4
All checks were successful
DCO action / DCO (pull_request) Successful in 3m45s
Build / Build Components (1.21) (pull_request) Successful in 5m18s
Build / Build Components (1.20) (pull_request) Successful in 5m28s
Tests and linters / Tests (1.20) (pull_request) Successful in 7m30s
Tests and linters / Tests (1.21) (pull_request) Successful in 7m42s
Tests and linters / Lint (pull_request) Successful in 8m25s
Vulncheck / Vulncheck (pull_request) Successful in 9m22s
Tests and linters / Staticcheck (pull_request) Successful in 10m57s
Tests and linters / Tests with -race (pull_request) Successful in 16m53s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
92 lines
1.9 KiB
Go
92 lines
1.9 KiB
Go
package v2
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl"
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
eaclSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/eacl"
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
)
|
|
|
|
type sysObjHdr struct {
|
|
k, v string
|
|
}
|
|
|
|
func (s sysObjHdr) Key() string {
|
|
return s.k
|
|
}
|
|
|
|
func (s sysObjHdr) Value() string {
|
|
return s.v
|
|
}
|
|
|
|
func u64Value(v uint64) string {
|
|
return strconv.FormatUint(v, 10)
|
|
}
|
|
|
|
func headersFromObject(obj *objectSDK.Object, cnr cid.ID, oid *oid.ID) []eaclSDK.Header {
|
|
var count int
|
|
for obj := obj; obj != nil; obj = obj.Parent() {
|
|
count += 9 + len(obj.Attributes())
|
|
}
|
|
|
|
res := make([]eaclSDK.Header, 0, count)
|
|
for ; obj != nil; obj = obj.Parent() {
|
|
res = append(res,
|
|
cidHeader(cnr),
|
|
// creation epoch
|
|
sysObjHdr{
|
|
k: acl.FilterObjectCreationEpoch,
|
|
v: u64Value(obj.CreationEpoch()),
|
|
},
|
|
// payload size
|
|
sysObjHdr{
|
|
k: acl.FilterObjectPayloadLength,
|
|
v: u64Value(obj.PayloadSize()),
|
|
},
|
|
// object version
|
|
sysObjHdr{
|
|
k: acl.FilterObjectVersion,
|
|
v: obj.Version().String(),
|
|
},
|
|
// object type
|
|
sysObjHdr{
|
|
k: acl.FilterObjectType,
|
|
v: obj.Type().String(),
|
|
},
|
|
)
|
|
|
|
if oid != nil {
|
|
res = append(res, oidHeader(*oid))
|
|
}
|
|
|
|
if idOwner := obj.OwnerID(); !idOwner.IsEmpty() {
|
|
res = append(res, ownerIDHeader(idOwner))
|
|
}
|
|
|
|
cs, ok := obj.PayloadChecksum()
|
|
if ok {
|
|
res = append(res, sysObjHdr{
|
|
k: acl.FilterObjectPayloadHash,
|
|
v: cs.String(),
|
|
})
|
|
}
|
|
|
|
cs, ok = obj.PayloadHomomorphicHash()
|
|
if ok {
|
|
res = append(res, sysObjHdr{
|
|
k: acl.FilterObjectHomomorphicHash,
|
|
v: cs.String(),
|
|
})
|
|
}
|
|
|
|
attrs := obj.Attributes()
|
|
for i := range attrs {
|
|
res = append(res, &attrs[i]) // only pointer attrs can implement eaclSDK.Header interface
|
|
}
|
|
}
|
|
|
|
return res
|
|
}
|