From c66b23995c0c4d9285254b08c44d113fc1a0862b Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 22 Sep 2020 13:53:10 +0300 Subject: [PATCH] [#155] sdk/object: Add session token getter/setter Signed-off-by: Leonard Lyubich --- pkg/object/raw.go | 7 +++++++ pkg/object/raw_test.go | 12 ++++++++++++ pkg/object/rw.go | 19 +++++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/pkg/object/raw.go b/pkg/object/raw.go index 0878f486..b4d40638 100644 --- a/pkg/object/raw.go +++ b/pkg/object/raw.go @@ -4,6 +4,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/owner" + "github.com/nspcc-dev/neofs-api-go/pkg/token" "github.com/nspcc-dev/neofs-api-go/v2/object" ) @@ -108,3 +109,9 @@ func (o *RawObject) SetChildren(v ...*ID) { func (o *RawObject) SetParent(v *Object) { o.setParent(v) } + +// SetSessionToken sets token of the session +// within which object was created. +func (o *RawObject) SetSessionToken(v *token.SessionToken) { + o.setSessionToken(v) +} diff --git a/pkg/object/raw_test.go b/pkg/object/raw_test.go index e585d133..fe0f2366 100644 --- a/pkg/object/raw_test.go +++ b/pkg/object/raw_test.go @@ -8,6 +8,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/owner" + "github.com/nspcc-dev/neofs-api-go/pkg/token" "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/stretchr/testify/require" ) @@ -202,3 +203,14 @@ func TestRawObject_ToV2(t *testing.T) { require.Equal(t, objV2, obj.ToV2()) } + +func TestRawObject_SetSessionToken(t *testing.T) { + obj := NewRaw() + + tok := token.NewSessionToken() + tok.SetID([]byte{1, 2, 3}) + + obj.SetSessionToken(tok) + + require.Equal(t, tok, obj.GetSessionToken()) +} diff --git a/pkg/object/rw.go b/pkg/object/rw.go index 5ed9f5e0..5332d14e 100644 --- a/pkg/object/rw.go +++ b/pkg/object/rw.go @@ -4,6 +4,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/owner" + "github.com/nspcc-dev/neofs-api-go/pkg/token" "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-api-go/v2/refs" ) @@ -12,8 +13,6 @@ import ( // public getter and private setters. type rwObject object.Object -// TODO: add session token methods - // ToV2 converts Object to v2 Object message. func (o *rwObject) ToV2() *object.Object { return (*object.Object)(o) @@ -273,3 +272,19 @@ func (o *rwObject) setParent(v *Object) { split.SetParentHeader((*object.Object)(v.rwObject).GetHeader()) }) } + +// GetSessionToken returns token of the session +// within which object was created. +func (o *rwObject) GetSessionToken() *token.SessionToken { + return token.NewSessionTokenFromV2( + (*object.Object)(o). + GetHeader(). + GetSessionToken(), + ) +} + +func (o *rwObject) setSessionToken(v *token.SessionToken) { + o.setHeaderField(func(h *object.Header) { + h.SetSessionToken(v.ToV2()) + }) +}