auth

Paddy 2014-09-01 Parent:5bf0a5fd1d01 Child:607708cd8829

31:88523dab00a5 Go to Latest

auth/memstore.go

Implement ClientStore in Memstore. Add the ClientStore interface implementation to Memstore. Change the ClientStore interface's UpdateClient function to take a new type, ClientChange, rather than enumerating the arguments in the function signature, which is a much cleaner interface. Add tests for the successful (works-as-intended) scenarios involving ClientStores. Ignore UpdateClient for now--I want to do tests that test every combination of ClientUpdate attributes being specified, to be sure that only the attributes specified are updated and that all the attributes specified are updated.

History
paddy@28 1 package auth
paddy@28 2
paddy@31 3 import (
paddy@31 4 "sync"
paddy@31 5
paddy@31 6 "secondbit.org/uuid"
paddy@31 7 )
paddy@28 8
paddy@28 9 type Memstore struct {
paddy@28 10 tokens map[string]Token
paddy@28 11 refreshTokenLookup map[string]string
paddy@28 12 profileTokenLookup map[string][]string
paddy@28 13 tokenLock sync.RWMutex
paddy@29 14
paddy@29 15 grants map[string]Grant
paddy@29 16 grantLock sync.RWMutex
paddy@31 17
paddy@31 18 clients map[string]Client
paddy@31 19 profileClientLookup map[string][]uuid.ID
paddy@31 20 clientLock sync.RWMutex
paddy@28 21 }
paddy@28 22
paddy@28 23 func NewMemstore() *Memstore {
paddy@28 24 return &Memstore{
paddy@31 25 tokens: map[string]Token{},
paddy@31 26 refreshTokenLookup: map[string]string{},
paddy@31 27 profileTokenLookup: map[string][]string{},
paddy@31 28 grants: map[string]Grant{},
paddy@31 29 clients: map[string]Client{},
paddy@31 30 profileClientLookup: map[string][]uuid.ID{},
paddy@28 31 }
paddy@28 32 }
paddy@28 33
paddy@28 34 func (m *Memstore) lookupTokenByRefresh(token string) (string, error) {
paddy@28 35 m.tokenLock.RLock()
paddy@28 36 defer m.tokenLock.RUnlock()
paddy@28 37 t, ok := m.refreshTokenLookup[token]
paddy@28 38 if !ok {
paddy@28 39 return "", ErrTokenNotFound
paddy@28 40 }
paddy@28 41 return t, nil
paddy@28 42 }
paddy@28 43
paddy@28 44 func (m *Memstore) lookupTokensByProfileID(id string) ([]string, error) {
paddy@28 45 m.tokenLock.RLock()
paddy@28 46 defer m.tokenLock.RUnlock()
paddy@28 47 return m.profileTokenLookup[id], nil
paddy@28 48 }
paddy@31 49
paddy@31 50 func (m *Memstore) lookupClientsByProfileID(id string) ([]uuid.ID, error) {
paddy@31 51 m.clientLock.RLock()
paddy@31 52 defer m.clientLock.RUnlock()
paddy@31 53 return m.profileClientLookup[id], nil
paddy@31 54 }