Implement postgres clientStore.
Stop requiring the client ID be passed to clientStore.addEndpoints and
context.AddEndpoints. The Endpoints themselves contain the client ID.
When using the authd server, set the log flags to include the file path and line
number.
Add an ErrEndpointAlreadyExists error, to return when creating an endpoint and
its ID already exists in the database.
Add a Deleted property to Clients and remove the clientStore.deleteClient and
context.DeleteClient methods. We're not going to actually remove that data, and
we want to be able to restore it, so include it in the ClientChange type and
call it using UpdateClient.
Create a ClientChange.Empty helper method that will return whether the
ClientChange has any changes to perform.
Return ErrClientNotFound from clientStore.getClient if the Client's Deleted
property is set to true. This also requires us to ignore ErrClientNotFound
errors when calling memstore.listClientsByOwner, as they should just be skipped
instead of returning an error.
Add the postgres type methods needed to implement clientStore.
Include postgres as a clientStore if the testing.Short() flag is not set.
Generate a new ID for the Client on every run in the tests, now that we can't
actually remove it from the database/memstore in code. We really just need a
*Store.Reset() function that erases all the data and starts over again, to give
the tests a clean execution environment (and so they can clean up after
themselves).
Add the CREATE TABLE statements for the Clients table and the Endpoints table to
sql/postgres_init.sql.
6 "code.secondbit.org/uuid.hg"
10 tokens map[string]Token
11 refreshTokenLookup map[string]string
12 profileTokenLookup map[string][]string
13 tokenLock sync.RWMutex
15 authCodes map[string]AuthorizationCode
16 authCodeLock sync.RWMutex
18 clients map[string]Client
19 profileClientLookup map[string][]uuid.ID
20 clientLock sync.RWMutex
22 endpoints map[string][]Endpoint
23 endpointLock sync.RWMutex
25 profiles map[string]Profile
26 profileLock sync.RWMutex
28 logins map[string]Login
29 profileLoginLookup map[string][]string
30 loginLock sync.RWMutex
32 sessions map[string]Session
33 sessionLock sync.RWMutex
35 scopes map[string]Scope
36 scopeLock sync.RWMutex
39 // NewMemstore returns an in-memory version of our datastores,
40 // which is handy for tests. Though the implementation is concurrency-safe,
41 // if makes no attempt to persist the data, and therefore it is inadvisable
42 // to use it in a production setting.
43 func NewMemstore() *memstore {
45 tokens: map[string]Token{},
46 refreshTokenLookup: map[string]string{},
47 profileTokenLookup: map[string][]string{},
48 authCodes: map[string]AuthorizationCode{},
49 clients: map[string]Client{},
50 profileClientLookup: map[string][]uuid.ID{},
51 endpoints: map[string][]Endpoint{},
52 profiles: map[string]Profile{},
53 logins: map[string]Login{},
54 profileLoginLookup: map[string][]string{},
55 sessions: map[string]Session{},
56 scopes: map[string]Scope{},
60 func (m *memstore) lookupTokenByRefresh(token string) (string, error) {
62 defer m.tokenLock.RUnlock()
63 t, ok := m.refreshTokenLookup[token]
65 return "", ErrTokenNotFound
70 func (m *memstore) lookupTokensByProfileID(id string) ([]string, error) {
72 defer m.tokenLock.RUnlock()
73 return m.profileTokenLookup[id], nil
76 func (m *memstore) lookupClientsByProfileID(id string) []uuid.ID {
78 defer m.clientLock.RUnlock()
79 c, ok := m.profileClientLookup[id]