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.1 --- a/memstore.go	Mon Sep 01 09:52:28 2014 -0400
     1.2 +++ b/memstore.go	Mon Sep 01 11:54:49 2014 -0400
     1.3 @@ -1,6 +1,10 @@
     1.4  package auth
     1.5  
     1.6 -import "sync"
     1.7 +import (
     1.8 +	"sync"
     1.9 +
    1.10 +	"secondbit.org/uuid"
    1.11 +)
    1.12  
    1.13  type Memstore struct {
    1.14  	tokens             map[string]Token
    1.15 @@ -10,14 +14,20 @@
    1.16  
    1.17  	grants    map[string]Grant
    1.18  	grantLock sync.RWMutex
    1.19 +
    1.20 +	clients             map[string]Client
    1.21 +	profileClientLookup map[string][]uuid.ID
    1.22 +	clientLock          sync.RWMutex
    1.23  }
    1.24  
    1.25  func NewMemstore() *Memstore {
    1.26  	return &Memstore{
    1.27 -		tokens:             map[string]Token{},
    1.28 -		refreshTokenLookup: map[string]string{},
    1.29 -		profileTokenLookup: map[string][]string{},
    1.30 -		grants:             map[string]Grant{},
    1.31 +		tokens:              map[string]Token{},
    1.32 +		refreshTokenLookup:  map[string]string{},
    1.33 +		profileTokenLookup:  map[string][]string{},
    1.34 +		grants:              map[string]Grant{},
    1.35 +		clients:             map[string]Client{},
    1.36 +		profileClientLookup: map[string][]uuid.ID{},
    1.37  	}
    1.38  }
    1.39  
    1.40 @@ -36,3 +46,9 @@
    1.41  	defer m.tokenLock.RUnlock()
    1.42  	return m.profileTokenLookup[id], nil
    1.43  }
    1.44 +
    1.45 +func (m *Memstore) lookupClientsByProfileID(id string) ([]uuid.ID, error) {
    1.46 +	m.clientLock.RLock()
    1.47 +	defer m.clientLock.RUnlock()
    1.48 +	return m.profileClientLookup[id], nil
    1.49 +}