[#1247] object: Return status errors from util.KeyStorage

Return `SessionTokenExpired`/`SessionTokenNotFound` error from
`apistatus` package if private session token is expired/missing. These
errors are returned by storage node's server as NeoFS API statuses.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-03-17 09:36:09 +03:00 committed by Alex Vanin
parent a4ee59977e
commit f32c9670ad

View file

@ -2,18 +2,13 @@ package util
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"errors"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-node/pkg/services/session/storage" "github.com/nspcc-dev/neofs-node/pkg/services/session/storage"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
"github.com/nspcc-dev/neofs-sdk-go/session" "github.com/nspcc-dev/neofs-sdk-go/session"
) )
var (
errNoSessionToken = errors.New("session token does not exist")
errSessionTokenExpired = errors.New("session token has been expired")
)
// KeyStorage represents private key storage of the local node. // KeyStorage represents private key storage of the local node.
type KeyStorage struct { type KeyStorage struct {
key *ecdsa.PrivateKey key *ecdsa.PrivateKey
@ -41,11 +36,16 @@ func (s *KeyStorage) GetKey(token *session.Token) (*ecdsa.PrivateKey, error) {
pToken := s.tokenStore.Get(token.OwnerID(), token.ID()) pToken := s.tokenStore.Get(token.OwnerID(), token.ID())
if pToken != nil { if pToken != nil {
if pToken.ExpiredAt() <= s.networkState.CurrentEpoch() { if pToken.ExpiredAt() <= s.networkState.CurrentEpoch() {
return nil, errSessionTokenExpired var errExpired apistatus.SessionTokenExpired
return nil, errExpired
} }
return pToken.SessionKey(), nil return pToken.SessionKey(), nil
} }
return nil, errNoSessionToken
var errNotFound apistatus.SessionTokenNotFound
return nil, errNotFound
} }
return s.key, nil return s.key, nil