Skip to content

Commit

Permalink
slicer: Add SetSession to slicer.ObjectWriter interface
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
  • Loading branch information
smallhive committed Jul 18, 2023
1 parent a793d4c commit e4c00d7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
9 changes: 9 additions & 0 deletions client/object_put.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-sdk-go/object/slicer"
"github.com/nspcc-dev/neofs-sdk-go/session"
"github.com/nspcc-dev/neofs-sdk-go/stat"
"github.com/nspcc-dev/neofs-sdk-go/user"
)
Expand Down Expand Up @@ -303,10 +304,18 @@ func (c *Client) ObjectPutInit(ctx context.Context, hdr object.Object, signer ne
type objectWriter struct {
context context.Context
client *Client
sess *session.Object
}

func (x *objectWriter) SetSession(sess session.Object) {
x.sess = &sess
}

func (x *objectWriter) InitDataStream(header object.Object, signer neofscrypto.Signer) (io.Writer, error) {
var prm PrmObjectPutInit
if x.sess != nil {
prm.WithinSession(*x.sess)
}

stream, err := x.client.ObjectPutInit(x.context, header, signer, prm)
if err != nil {
Expand Down
10 changes: 9 additions & 1 deletion object/slicer/slicer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ type ObjectWriter interface {
// Signer is required and must not be nil. The operation is executed on behalf of
// the account corresponding to the specified Signer, which is taken into account, in particular, for access control.
InitDataStream(header object.Object, signer neofscrypto.Signer) (dataStream io.Writer, err error)

// SetSession pass session object to writer. It will be used for writing object routine.
// This method must be called before InitDataStream.
SetSession(sess session.Object)
}

// Slicer converts input raw data streams into NeoFS objects. Working Slicer
Expand Down Expand Up @@ -64,10 +68,14 @@ func New(w ObjectWriter) *Slicer {
// all resulting objects. In this case, the object is considered to be created
// by a proxy on behalf of the session issuer.
func NewSession(w ObjectWriter, token session.Object) *Slicer {
return &Slicer{
slicer := &Slicer{
w: w,
sessionToken: &token,
}

slicer.w.SetSession(token)

return slicer
}

const defaultPayloadSizeLimit = 1 << 20
Expand Down
9 changes: 9 additions & 0 deletions object/slicer/slicer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ func benchmarkSliceDataIntoObjects(b *testing.B, size, sizeLimit uint64) {

type discardObject struct{}

func (discardObject) SetSession(session.Object) {
}

func (discardObject) InitDataStream(object.Object, neofscrypto.Signer) (io.Writer, error) {
return discardPayload{}, nil
}
Expand Down Expand Up @@ -269,6 +272,9 @@ type slicedObjectChecker struct {
chainCollector *chainCollector
}

func (*slicedObjectChecker) SetSession(session.Object) {
}

func (x *slicedObjectChecker) InitDataStream(hdr object.Object, _ neofscrypto.Signer) (io.Writer, error) {
checkStaticMetadata(x.tb, hdr, x.input)

Expand Down Expand Up @@ -528,6 +534,9 @@ type memoryWriter struct {
splitID *object.SplitID
}

func (*memoryWriter) SetSession(session.Object) {
}

func (w *memoryWriter) InitDataStream(hdr object.Object, _ neofscrypto.Signer) (io.Writer, error) {
w.headers = append(w.headers, hdr)
if w.splitID == nil && hdr.SplitID() != nil {
Expand Down

0 comments on commit e4c00d7

Please sign in to comment.