2020-09-22 15:04:08 +00:00
|
|
|
package headsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
2020-09-29 16:44:59 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
2020-09-22 15:04:08 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type remoteHeader struct {
|
2020-09-29 16:44:59 +00:00
|
|
|
keyStorage *util.KeyStorage
|
2020-09-22 15:04:08 +00:00
|
|
|
|
|
|
|
node *network.Address
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *remoteHeader) head(ctx context.Context, prm *Prm, handler func(*object.Object)) error {
|
2020-09-29 16:44:59 +00:00
|
|
|
key, err := h.keyStorage.GetKey(prm.common.SessionToken())
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "(%T) could not receive private key", h)
|
|
|
|
}
|
|
|
|
|
2020-09-22 15:04:08 +00:00
|
|
|
addr := h.node.NetAddr()
|
|
|
|
|
2020-09-29 16:44:59 +00:00
|
|
|
c, err := client.New(key,
|
2020-09-22 15:04:08 +00:00
|
|
|
client.WithAddress(addr),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "(%T) could not create SDK client %s", h, addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
p := new(client.ObjectHeaderParams).
|
|
|
|
WithAddress(prm.addr)
|
|
|
|
|
|
|
|
if prm.short {
|
|
|
|
p = p.WithMainFields()
|
|
|
|
}
|
|
|
|
|
|
|
|
hdr, err := c.GetObjectHeader(ctx, p,
|
|
|
|
client.WithTTL(1), // FIXME: use constant
|
2020-09-29 16:44:59 +00:00
|
|
|
client.WithSession(prm.common.SessionToken()),
|
2020-09-22 15:04:08 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "(%T) could not head object in %s", h, addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
handler(object.NewFromSDK(hdr))
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|