auth

Paddy 2015-05-17 Parent:37a42585660e Child:807d20a0b197

170:bdb83e88e1da Browse Files

Instantiate a login verification handler. When starting up the authd binary, get our login verification handler set up. We're going to use environment variables to detect if NSQ is configured. If it is, that'll be used. Otherwise, fall back on logging to stdout.

authd/server.go

     1.1 --- a/authd/server.go	Sun May 17 00:53:45 2015 -0400
     1.2 +++ b/authd/server.go	Sun May 17 02:17:09 2015 -0400
     1.3 @@ -12,6 +12,7 @@
     1.4  
     1.5  func main() {
     1.6  	log.SetFlags(log.LstdFlags | log.Llongfile)
     1.7 +	log.Printf("Running version '%s'\n", auth.Version)
     1.8  	var config auth.Config
     1.9  	if os.Getenv("AUTH_PG_DB") != "" {
    1.10  		p, err := auth.NewPostgres(os.Getenv("AUTH_PG_DB"))
    1.11 @@ -36,6 +37,15 @@
    1.12  	config.Template = template.Must(template.New("base").ParseGlob("./templates/*.gotmpl"))
    1.13  	config.LoginURI = "/login"
    1.14  	config.JWTPrivateKey = []byte(`secret`)
    1.15 +	if os.Getenv("AUTH_NSQD_ADDR") != "" {
    1.16 +		n, err := auth.NewNSQNotifier(os.Getenv("AUTH_NSQD_ADDR"))
    1.17 +		if err != nil {
    1.18 +			log.Fatal(err)
    1.19 +		}
    1.20 +		config.LoginVerificationNotifier = n
    1.21 +	} else {
    1.22 +		config.LoginVerificationNotifier = auth.NewStdoutNotifier()
    1.23 +	}
    1.24  	err := config.Init()
    1.25  	if err != nil {
    1.26  		log.Fatal(err)