forked from TrueCloudLab/frostfs-sdk-go
[#197] session: Refactor and document the package
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
497053c785
commit
552c7875bf
32 changed files with 1622 additions and 1358 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
v2session "github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
|
||||
|
@ -519,19 +520,31 @@ func (o *Object) resetRelations() {
|
|||
|
||||
// SessionToken returns token of the session
|
||||
// within which object was created.
|
||||
func (o *Object) SessionToken() *session.Token {
|
||||
return session.NewTokenFromV2(
|
||||
(*object.Object)(o).
|
||||
GetHeader().
|
||||
GetSessionToken(),
|
||||
)
|
||||
func (o *Object) SessionToken() *session.Object {
|
||||
tokv2 := (*object.Object)(o).GetHeader().GetSessionToken()
|
||||
if tokv2 == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var res session.Object
|
||||
|
||||
fmt.Println(res.ReadFromV2(*tokv2))
|
||||
|
||||
return &res
|
||||
}
|
||||
|
||||
// SetSessionToken sets token of the session
|
||||
// within which object was created.
|
||||
func (o *Object) SetSessionToken(v *session.Token) {
|
||||
func (o *Object) SetSessionToken(v *session.Object) {
|
||||
o.setHeaderField(func(h *object.Header) {
|
||||
h.SetSessionToken(v.ToV2())
|
||||
var tokv2 *v2session.Token
|
||||
|
||||
if v != nil {
|
||||
tokv2 = new(v2session.Token)
|
||||
v.WriteToV2(tokv2)
|
||||
}
|
||||
|
||||
h.SetSessionToken(tokv2)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ func TestObject_ToV2(t *testing.T) {
|
|||
func TestObject_SetSessionToken(t *testing.T) {
|
||||
obj := New()
|
||||
|
||||
tok := sessiontest.Token()
|
||||
tok := sessiontest.ObjectSigned()
|
||||
|
||||
obj.SetSessionToken(tok)
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ func generate(withParent bool) *object.Object {
|
|||
ver := version.Current()
|
||||
|
||||
x.SetID(oidtest.ID())
|
||||
x.SetSessionToken(sessiontest.Token())
|
||||
x.SetSessionToken(sessiontest.Object())
|
||||
x.SetPayload([]byte{1, 2, 3})
|
||||
x.SetOwnerID(usertest.ID())
|
||||
x.SetContainerID(cidtest.ID())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue