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