2020-09-21 14:31:31 +00:00
|
|
|
package putsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
2020-09-29 16:44:59 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
2020-09-21 14:31:31 +00:00
|
|
|
"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-21 14:31:31 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type remoteTarget struct {
|
|
|
|
transformer.ObjectTarget
|
|
|
|
|
|
|
|
ctx context.Context
|
|
|
|
|
2020-09-29 16:44:59 +00:00
|
|
|
keyStorage *util.KeyStorage
|
|
|
|
|
|
|
|
token *token.SessionToken
|
2020-09-21 14:31:31 +00:00
|
|
|
|
|
|
|
addr *network.Address
|
|
|
|
|
|
|
|
obj *object.Object
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *remoteTarget) WriteHeader(obj *object.RawObject) error {
|
|
|
|
t.obj = obj.Object()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
|
2020-09-29 16:44:59 +00:00
|
|
|
key, err := t.keyStorage.GetKey(t.token)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "(%T) could not receive private key", t)
|
|
|
|
}
|
|
|
|
|
2020-09-24 08:27:14 +00:00
|
|
|
addr, err := t.addr.IPAddrString()
|
2020-09-24 07:37:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-09-21 14:31:31 +00:00
|
|
|
|
2020-09-29 16:44:59 +00:00
|
|
|
c, err := client.New(key,
|
2020-09-21 14:31:31 +00:00
|
|
|
client.WithAddress(addr),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "(%T) could not create SDK client %s", t, addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err := c.PutObject(t.ctx, new(client.PutObjectParams).
|
|
|
|
WithObject(
|
|
|
|
t.obj.SDK(),
|
2020-09-29 09:02:21 +00:00
|
|
|
),
|
2020-09-21 14:31:31 +00:00
|
|
|
client.WithTTL(1), // FIXME: use constant
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "(%T) could not put object to %s", t, addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
return new(transformer.AccessIdentifiers).
|
|
|
|
WithSelfID(id), nil
|
|
|
|
}
|