chore: setup key upper case

This commit is contained in:
braginini 2021-08-19 20:07:12 +02:00
parent 1dfa99d07c
commit c68d9dff4a
2 changed files with 5 additions and 4 deletions

View File

@ -6,6 +6,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"net"
"strings"
"sync"
)
@ -175,7 +176,7 @@ func (manager *AccountManager) AddPeer(setupKey string, peerKey string) (*Peer,
// Empty setup key, create a new account for it.
account, sk = newAccount()
} else {
sk = &SetupKey{Key: setupKey}
sk = &SetupKey{Key: strings.ToUpper(setupKey)}
account, err = manager.Store.GetAccountBySetupKey(sk.Key)
if err != nil {
return nil, status.Errorf(codes.NotFound, "unknown setupKey %s", setupKey)
@ -211,7 +212,7 @@ func newAccountWithId(accountId string) (*Account, *SetupKey) {
log.Debugf("creating new account")
setupKeyId := uuid.New().String()
setupKeyId := strings.ToUpper(uuid.New().String())
setupKeys := make(map[string]*SetupKey)
setupKey := &SetupKey{Key: setupKeyId}
setupKeys[setupKeyId] = setupKey

View File

@ -67,7 +67,7 @@ func restore(file string) (*FileStore, error) {
store.PeerKeyId2AccountId = make(map[string]string)
for accountId, account := range store.Accounts {
for setupKeyId := range account.SetupKeys {
store.SetupKeyId2AccountId[strings.ToLower(setupKeyId)] = accountId
store.SetupKeyId2AccountId[strings.ToUpper(setupKeyId)] = accountId
}
for _, peer := range account.Peers {
store.PeerKeyId2AccountId[peer.Key] = accountId
@ -133,7 +133,7 @@ func (s *FileStore) SaveAccount(account *Account) error {
func (s *FileStore) GetAccountBySetupKey(setupKey string) (*Account, error) {
accountId, accountIdFound := s.SetupKeyId2AccountId[strings.ToLower(setupKey)]
accountId, accountIdFound := s.SetupKeyId2AccountId[strings.ToUpper(setupKey)]
if !accountIdFound {
return nil, status.Errorf(codes.NotFound, "provided setup key doesn't exists")
}