auth

Paddy 2015-04-07 Parent:8267e1c8bcd1

155:762953f6a7f2 Go to Latest

auth/postgres.go

Implement postgres version of the tokenStore. Create a postgres implementation for the tokenStore. Note that because pq doesn't support Postgres' array types (see https://github.com/lib/pq/issues/49), we couldn't just store the token.Scopes field as a Postgres array of varchars, which would have been the ideal. Instead, we need a many-to-many table that maps tokens to scopes. This meant we needed a special tokenScope type for our database mapping, and we needed to complicate the token storage/retrieval functions a little bit. It's kind of ugly, I'm not a huge fan of it, and I'd much rather be using the Postgres array types, but... well, here we are. We also added the postgres tokenStore to our slice of tokenStores to test when the correct environment variables are present. We wrote initialization SQL for the tables required by the postgres tokenStore. Also, added a helper script for emptying the test database, because I got tired of doing it by hand. We should be doing that in an automated fashion in the tests themselves, but that would mean extending the *Store interfaces.

History
paddy@148 1 package auth
paddy@148 2
paddy@148 3 import (
paddy@148 4 "database/sql"
paddy@149 5 )
paddy@148 6
paddy@149 7 func NewPostgres(conn string) (postgres, error) {
paddy@149 8 db, err := sql.Open("postgres", conn)
paddy@149 9 if err != nil {
paddy@149 10 return postgres{}, err
paddy@149 11 }
paddy@149 12 return postgres{db: db}, nil
paddy@149 13 }
paddy@148 14
paddy@148 15 type postgres struct {
paddy@148 16 db *sql.DB
paddy@148 17 }