forked from TrueCloudLab/frostfs-node
[#1255] node/session: Add persistent session storage
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
929c9851a6
commit
455b9fb325
7 changed files with 331 additions and 20 deletions
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/mr-tron/base58"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||
|
@ -18,30 +17,21 @@ func (s *TokenStore) Create(ctx context.Context, body *session.CreateRequestBody
|
|||
panic(err)
|
||||
}
|
||||
|
||||
uid, err := uuid.NewRandom()
|
||||
uidBytes, err := storage.NewTokenID()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not generate token ID: %w", err)
|
||||
}
|
||||
|
||||
uidBytes, err := uid.MarshalBinary()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not marshal token ID: %w", err)
|
||||
}
|
||||
|
||||
sk, err := keys.NewPrivateKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
privateToken := new(storage.PrivateToken)
|
||||
privateToken.SetSessionKey(&sk.PrivateKey)
|
||||
privateToken.SetExpiredAt(body.GetExpiration())
|
||||
|
||||
s.mtx.Lock()
|
||||
s.tokens[key{
|
||||
tokenID: base58.Encode(uidBytes),
|
||||
ownerID: base58.Encode(ownerBytes),
|
||||
}] = privateToken
|
||||
}] = storage.NewPrivateToken(&sk.PrivateKey, body.GetExpiration())
|
||||
s.mtx.Unlock()
|
||||
|
||||
res := new(session.CreateResponseBody)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue