923f84722a
Signed-off-by: Pavel Karpy <p.karpy@yadro.com>
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package temporary
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/TrueCloudLab/frostfs-api-go/v2/session"
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/services/session/storage"
|
|
"github.com/TrueCloudLab/frostfs-sdk-go/user"
|
|
"github.com/mr-tron/base58"
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
)
|
|
|
|
func (s *TokenStore) Create(ctx context.Context, body *session.CreateRequestBody) (*session.CreateResponseBody, error) {
|
|
idV2 := body.GetOwnerID()
|
|
if idV2 == nil {
|
|
return nil, errors.New("missing owner")
|
|
}
|
|
|
|
var id user.ID
|
|
|
|
err := id.ReadFromV2(*idV2)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("invalid owner: %w", err)
|
|
}
|
|
|
|
uidBytes, err := storage.NewTokenID()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not generate token ID: %w", err)
|
|
}
|
|
|
|
sk, err := keys.NewPrivateKey()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
s.mtx.Lock()
|
|
s.tokens[key{
|
|
tokenID: base58.Encode(uidBytes),
|
|
ownerID: base58.Encode(id.WalletBytes()),
|
|
}] = storage.NewPrivateToken(&sk.PrivateKey, body.GetExpiration())
|
|
s.mtx.Unlock()
|
|
|
|
res := new(session.CreateResponseBody)
|
|
res.SetID(uidBytes)
|
|
res.SetSessionKey(sk.PublicKey().Bytes())
|
|
|
|
return res, nil
|
|
}
|
|
|
|
func (s *TokenStore) Close() error {
|
|
return nil
|
|
}
|