auth

Paddy 2015-03-22 Parent:d103a598548c Child:581c60f8dd23

151:77db7c65216c Go to Latest

auth/config.go

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.

History
paddy@96 1 package auth
paddy@96 2
paddy@96 3 import (
paddy@96 4 "errors"
paddy@96 5 "html/template"
paddy@101 6 "log"
paddy@96 7 )
paddy@96 8
paddy@96 9 var (
paddy@96 10 // ErrInvalidLoginURI is returned when a Context is instantiated with a Config object that specifies a LoginURI that can't be parsed as a URL.
paddy@96 11 ErrInvalidLoginURI = errors.New("invalid login URI")
paddy@102 12 // ErrConfigNotInitialized is returned when a Context is instantiated with a Config object that hasn't had its Init function called.
paddy@102 13 ErrConfigNotInitialized = errors.New("config not initialized")
paddy@96 14 )
paddy@96 15
paddy@96 16 // Config holds the configuration values necessary to run a server. A Config
paddy@96 17 // instance is the only way to instantiate a Context variable.
paddy@96 18 type Config struct {
paddy@96 19 ClientStore clientStore
paddy@96 20 AuthCodeStore authorizationCodeStore
paddy@96 21 ProfileStore profileStore
paddy@96 22 TokenStore tokenStore
paddy@96 23 SessionStore sessionStore
paddy@134 24 ScopeStore scopeStore
paddy@96 25 Template *template.Template
paddy@96 26 LoginURI string
paddy@96 27 iterations int
paddy@132 28 secureCookie bool
paddy@96 29 }
paddy@101 30
paddy@102 31 // Init is a function that preps the Config object to be used for Context creation, setting variables
paddy@102 32 // that are determined at the beginning of program execution.
paddy@101 33 func (c *Config) Init() error {
paddy@101 34 scheme, ok := passphraseSchemes[CurPassphraseScheme]
paddy@101 35 if !ok {
paddy@101 36 return ErrInvalidPassphraseScheme
paddy@101 37 }
paddy@101 38 var err error
paddy@101 39 c.iterations, err = scheme.calculateIterations()
paddy@101 40 if err != nil {
paddy@101 41 return err
paddy@101 42 }
paddy@101 43 log.Printf("Generating passphrases with %d iterations...\n", c.iterations)
paddy@101 44 return nil
paddy@101 45 }