auth

Paddy 2015-12-14 Parent:8267e1c8bcd1

181:b7e685839a1b Go to Latest

auth/postgres.go

Break out scopes and events. This repo has gotten unwieldy, and there are portions of it that need to be imported by a large number of other packages. For example, scopes will be used in almost every API we write. Rather than importing the entirety of this codebase into every API we write, I've opted to move the scope logic out into a scopes package, with a subpackage for the defined types, which is all most projects actually want to import. We also define some event type constants, and importing those shouldn't require a project to import all our dependencies, either. So I made an events subpackage that just holds those constants. This package has become a little bit of a red-headed stepchild and is do for a refactor, but I'm trying to put that off as long as I can. The refactoring of our scopes stuff has left a bug wherein a token can be granted for scopes that don't exist. I'm going to need to revisit that, and also how to limit scopes to only be granted to the users that should be able to request them. But that's a battle for another day.

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 }