2020-09-30 10:52:14 +00:00
|
|
|
package deletesvc
|
|
|
|
|
|
|
|
import (
|
2022-05-31 17:00:41 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
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"
|
2020-09-30 10:52:14 +00:00
|
|
|
)
|
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
type tombstoneBodyWriter struct {
|
|
|
|
body *objectV2.DeleteResponseBody
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) toPrm(req *objectV2.DeleteRequest, respBody *objectV2.DeleteResponseBody) (*deletesvc.Prm, error) {
|
2022-05-31 17:00:41 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2021-01-12 14:55:02 +00:00
|
|
|
commonPrm, err := util.CommonPrmFromV2(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
p := new(deletesvc.Prm)
|
2021-10-26 13:02:46 +00:00
|
|
|
p.SetCommonParameters(commonPrm)
|
2020-12-11 08:04:04 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
p.WithAddress(addr)
|
2020-12-11 08:04:04 +00:00
|
|
|
p.WithTombstoneAddressTarget(&tombstoneBodyWriter{
|
|
|
|
body: respBody,
|
|
|
|
})
|
2020-09-30 10:52:14 +00:00
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
return p, nil
|
2020-09-30 10:52:14 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (w *tombstoneBodyWriter) SetAddress(addr oid.Address) {
|
|
|
|
var addrV2 refs.Address
|
|
|
|
addr.WriteToV2(&addrV2)
|
|
|
|
|
|
|
|
w.body.SetTombstone(&addrV2)
|
2020-12-11 08:04:04 +00:00
|
|
|
}
|