auth
auth/profile.go
Do a first, naive pass at storing profiles in Postgres. This is untested against an actual database. It's a best-guess attempt at SQL. It _should_ work. I think. Start storing things in Postgres, starting with Profiles and Logins. This necessitates the addition of a Deleted property to the Profile type, because I'm not deleting those in case of accidental deletion. Logins, though, we'll delete. This also necessitates updating the profileStore interface to no longer have a deleteProfile method, because we're tracking that through updates now. Then we need to update our profileStore tests, because they no longer clean up after themselves. Which, come to think of it, may cause some problems later.
1.1 --- a/profile.go Fri Mar 20 23:03:21 2015 -0400 1.2 +++ b/profile.go Sat Mar 21 01:23:33 2015 -0400 1.3 @@ -82,6 +82,7 @@ 1.4 PassphraseResetCreated time.Time `json:"-"` 1.5 Created time.Time `json:"created,omitempty"` 1.6 LastSeen time.Time `json:"last_seen,omitempty"` 1.7 + Deleted bool `json:"deleted,omitempty"` 1.8 } 1.9 1.10 // ApplyChange applies the properties of the passed ProfileChange 1.11 @@ -117,6 +118,9 @@ 1.12 if change.LastSeen != nil { 1.13 p.LastSeen = *change.LastSeen 1.14 } 1.15 + if change.Deleted != nil { 1.16 + p.Deleted = *change.Deleted 1.17 + } 1.18 } 1.19 1.20 // ApplyBulkChange applies the properties of the passed BulkProfileChange 1.21 @@ -139,6 +143,7 @@ 1.22 PassphraseReset *string 1.23 PassphraseResetCreated *time.Time 1.24 LastSeen *time.Time 1.25 + Deleted *bool 1.26 } 1.27 1.28 // Validate checks the ProfileChange it is called on 1.29 @@ -146,7 +151,7 @@ 1.30 // A descriptive error will be returned in the case of 1.31 // an invalid change. 1.32 func (c ProfileChange) Validate() error { 1.33 - if c.Name == nil && c.Passphrase == nil && c.Iterations == nil && c.Salt == nil && c.PassphraseScheme == nil && c.Compromised == nil && c.LockedUntil == nil && c.PassphraseReset == nil && c.PassphraseResetCreated == nil && c.LastSeen == nil { 1.34 + if c.Name == nil && c.Passphrase == nil && c.Iterations == nil && c.Salt == nil && c.PassphraseScheme == nil && c.Compromised == nil && c.LockedUntil == nil && c.PassphraseReset == nil && c.PassphraseResetCreated == nil && c.LastSeen == nil && c.Deleted == nil { 1.35 return ErrEmptyChange 1.36 } 1.37 if c.PassphraseScheme != nil && c.Passphrase == nil { 1.38 @@ -260,7 +265,6 @@ 1.39 saveProfile(profile Profile) error 1.40 updateProfile(id uuid.ID, change ProfileChange) error 1.41 updateProfiles(ids []uuid.ID, change BulkProfileChange) error 1.42 - deleteProfile(id uuid.ID) error 1.43 1.44 addLogin(login Login) error 1.45 removeLogin(value string, profile uuid.ID) error 1.46 @@ -275,6 +279,9 @@ 1.47 if !ok { 1.48 return Profile{}, ErrProfileNotFound 1.49 } 1.50 + if p.Deleted { 1.51 + return Profile{}, ErrProfileNotFound 1.52 + } 1.53 return p, nil 1.54 } 1.55 1.56 @@ -291,6 +298,9 @@ 1.57 if !ok { 1.58 return Profile{}, ErrProfileNotFound 1.59 } 1.60 + if profile.Deleted { 1.61 + return Profile{}, ErrProfileNotFound 1.62 + } 1.63 return profile, nil 1.64 } 1.65 1.66 @@ -332,17 +342,6 @@ 1.67 return nil 1.68 } 1.69 1.70 -func (m *memstore) deleteProfile(id uuid.ID) error { 1.71 - m.profileLock.Lock() 1.72 - defer m.profileLock.Unlock() 1.73 - _, ok := m.profiles[id.String()] 1.74 - if !ok { 1.75 - return ErrProfileNotFound 1.76 - } 1.77 - delete(m.profiles, id.String()) 1.78 - return nil 1.79 -} 1.80 - 1.81 func (m *memstore) addLogin(login Login) error { 1.82 m.loginLock.Lock() 1.83 defer m.loginLock.Unlock()