auth

Paddy 2015-04-11 Parent:202e991accc2 Child:0ff23f3a4ede

161:849f3820b164 Go to Latest

auth/authd/server.go

Stop soft-deleting Profiles and actually delete them. The information we're storing in Profiles isn't unique enough that we should go through the hassle we're going through to soft-delete it. Add a deleteProfile method to our profileStore, and implement it for our postgres and memstore implementations. Add a DeleteProfile wrapper for our Context. Remove the Deleted property from the Profile type and the ProfileChange type, and update references to it. Stop cleaning up after our Profile in the UpdateProfileHandler, because there's no longer any way to delete the Profile from the UpdateProfileHandler. Update our get/list* methods so they don't filter on the non-existent Deleted property anymore. Update our SQL schema definition to not include the deleted column. Update our profile tests to use the DeleteProfile method and stop comparing the no-longer-existing Deleted property.

History
1 package main
3 import (
4 "html/template"
5 "log"
6 "net/http"
7 "os"
9 "code.secondbit.org/auth.hg"
10 "github.com/gorilla/mux"
11 )
13 func main() {
14 log.SetFlags(log.LstdFlags | log.Llongfile)
15 var config auth.Config
16 if os.Getenv("AUTH_PG_DB") != "" {
17 p, err := auth.NewPostgres(os.Getenv("AUTH_PG_DB"))
18 if err != nil {
19 panic(err)
20 }
21 config.ClientStore = &p
22 config.AuthCodeStore = &p
23 config.ProfileStore = &p
24 config.TokenStore = &p
25 config.SessionStore = &p
26 config.ScopeStore = &p
27 } else {
28 store := auth.NewMemstore()
29 config.ClientStore = store
30 config.AuthCodeStore = store
31 config.ProfileStore = store
32 config.TokenStore = store
33 config.SessionStore = store
34 config.ScopeStore = store
35 }
36 config.Template = template.Must(template.New("base").ParseGlob("./templates/*.gotmpl"))
37 config.LoginURI = "/login"
38 err := config.Init()
39 if err != nil {
40 log.Fatal(err)
41 }
42 context, err := auth.NewContext(config)
43 if err != nil {
44 panic(err)
45 }
46 err = context.CreateScopes([]auth.Scope{
47 {ID: "testscope", Name: "Test Scope"},
48 })
49 if err != nil && err != auth.ErrScopeAlreadyExists {
50 log.Fatal(err)
51 }
53 router := mux.NewRouter()
54 auth.RegisterOAuth2(router, context)
55 auth.RegisterSessionHandlers(router, context)
56 auth.RegisterProfileHandlers(router, context)
57 auth.RegisterClientHandlers(router, context)
58 http.Handle("/", router)
59 log.Fatal(http.ListenAndServe(":8080", nil))
60 }