auth

Paddy 2014-09-18 Parent:607708cd8829 Child:113ccb15b919

39:690561c6619a Go to Latest

auth/client.go

Include client updates and tests. Flesh out updating clients, and include unit tests to ensure that clientstores actually update appropriately. Add TODO comments where functionality is planned but stubbed out.

History
     1.1 --- a/client.go	Sun Sep 07 19:09:01 2014 -0400
     1.2 +++ b/client.go	Thu Sep 18 19:33:49 2014 -0400
     1.3 @@ -24,6 +24,27 @@
     1.4  	Website     string
     1.5  }
     1.6  
     1.7 +func (c *Client) ApplyChange(change ClientChange) {
     1.8 +	if change.Secret != nil {
     1.9 +		c.Secret = *change.Secret
    1.10 +	}
    1.11 +	if change.RedirectURI != nil {
    1.12 +		c.RedirectURI = *change.RedirectURI
    1.13 +	}
    1.14 +	if change.OwnerID != nil {
    1.15 +		c.OwnerID = change.OwnerID
    1.16 +	}
    1.17 +	if change.Name != nil {
    1.18 +		c.Name = *change.Name
    1.19 +	}
    1.20 +	if change.Logo != nil {
    1.21 +		c.Logo = *change.Logo
    1.22 +	}
    1.23 +	if change.Website != nil {
    1.24 +		c.Website = *change.Website
    1.25 +	}
    1.26 +}
    1.27 +
    1.28  type ClientChange struct {
    1.29  	Secret      *string
    1.30  	RedirectURI *string
    1.31 @@ -33,6 +54,11 @@
    1.32  	Website     *string
    1.33  }
    1.34  
    1.35 +func (c ClientChange) Validate() error {
    1.36 +	// TODO: validate client changes
    1.37 +	return nil
    1.38 +}
    1.39 +
    1.40  // ClientStore abstracts the storage interface for
    1.41  // storing and retrieving Clients.
    1.42  type ClientStore interface {
    1.43 @@ -65,6 +91,14 @@
    1.44  }
    1.45  
    1.46  func (m *Memstore) UpdateClient(id uuid.ID, change ClientChange) error {
    1.47 +	m.clientLock.Lock()
    1.48 +	defer m.clientLock.Unlock()
    1.49 +	c, ok := m.clients[id.String()]
    1.50 +	if !ok {
    1.51 +		return ErrClientNotFound
    1.52 +	}
    1.53 +	c.ApplyChange(change)
    1.54 +	m.clients[id.String()] = c
    1.55  	return nil
    1.56  }
    1.57