[#155] sdk/object: Add session token getter/setter

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-09-22 13:53:10 +03:00 committed by Leonard Lyubich
parent 3347e53cde
commit c66b23995c
3 changed files with 36 additions and 2 deletions

View file

@ -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)
}

View file

@ -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())
}

View file

@ -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())
})
}