frostfs-node/pkg/services/object/delete/v2/util.go
Alex Vanin 20de74a505 Rename package name
Due to source code relocation from GitHub.

Signed-off-by: Alex Vanin <a.vanin@yadro.com>
2023-03-07 16:38:26 +03:00

54 lines
1.2 KiB
Go

package deletesvc
import (
"errors"
"fmt"
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
deletesvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/delete"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
)
type tombstoneBodyWriter struct {
body *objectV2.DeleteResponseBody
}
func (s *Service) toPrm(req *objectV2.DeleteRequest, respBody *objectV2.DeleteResponseBody) (*deletesvc.Prm, error) {
body := req.GetBody()
addrV2 := body.GetAddress()
if addrV2 == nil {
return nil, errors.New("missing object address")
}
var addr oid.Address
err := addr.ReadFromV2(*addrV2)
if err != nil {
return nil, fmt.Errorf("invalid object address: %w", err)
}
commonPrm, err := util.CommonPrmFromV2(req)
if err != nil {
return nil, err
}
p := new(deletesvc.Prm)
p.SetCommonParameters(commonPrm)
p.WithAddress(addr)
p.WithTombstoneAddressTarget(&tombstoneBodyWriter{
body: respBody,
})
return p, nil
}
func (w *tombstoneBodyWriter) SetAddress(addr oid.Address) {
var addrV2 refs.Address
addr.WriteToV2(&addrV2)
w.body.SetTombstone(&addrV2)
}