auth

Paddy 2015-06-29 Parent:37a42585660e

175:aa14e29b666f Go to Latest

auth/profile_verification.go

Create Docker image for authd. Create a Dockerfile for authd, which will wrap the compiled Go binary up into a tiny little Docker image. Create an authd/build-docker.sh script that will build the statically-linked binary in a Docker container, so the authd Docker image can use it. We had to include ca-certificates.crt in the Dockerfile, as well, so we could communicate over SSL with things. A wrapper.sh file is included that will pull the JWT_SECRET environment variable out of a kubernetes secrets file, which is a handy wrapper to have. Finally, we added the authd/docker-authd binary to the .hgignore.

History
paddy@169 1 package auth
paddy@169 2
paddy@169 3 import (
paddy@169 4 "log"
paddy@169 5 "time"
paddy@169 6
paddy@169 7 "code.secondbit.org/events.hg"
paddy@169 8 )
paddy@169 9
paddy@169 10 const (
paddy@169 11 EventSystem = "authd"
paddy@169 12 EventModelLogin = "login"
paddy@169 13 EventActionSendVerification = "send_verification"
paddy@169 14 EventTopicLoginVerification = "login_verification"
paddy@169 15 )
paddy@169 16
paddy@169 17 type loginVerificationNotifier interface {
paddy@169 18 SendLoginVerification(login Login)
paddy@169 19 }
paddy@169 20
paddy@169 21 type stdoutNotifier struct{}
paddy@169 22
paddy@169 23 func NewStdoutNotifier() stdoutNotifier {
paddy@169 24 return stdoutNotifier{}
paddy@169 25 }
paddy@169 26
paddy@169 27 func (s stdoutNotifier) SendLoginVerification(login Login) {
paddy@169 28 log.Printf("Use \"%s\" as the verification code for \"%s\"\n", login.Verification, login.Value)
paddy@169 29 }
paddy@169 30
paddy@169 31 type nsqNotifier struct {
paddy@169 32 *events.NSQPublisher
paddy@169 33 }
paddy@169 34
paddy@169 35 func NewNSQNotifier(address string) (*nsqNotifier, error) {
paddy@169 36 p, err := events.NewNSQPublisher(EventSystem+"/"+Version, address)
paddy@169 37 return &nsqNotifier{p}, err
paddy@169 38 }
paddy@169 39
paddy@169 40 func (n *nsqNotifier) SendLoginVerification(login Login) {
paddy@169 41 evt := events.Event{
paddy@169 42 System: EventSystem,
paddy@169 43 Model: EventModelLogin,
paddy@169 44 ID: login.Value,
paddy@169 45 Action: EventActionSendVerification,
paddy@169 46 Timestamp: time.Now(),
paddy@169 47 Data: map[string]string{
paddy@169 48 "verification": login.Verification,
paddy@169 49 },
paddy@169 50 }
paddy@169 51 err := n.Publish(EventTopicLoginVerification, evt)
paddy@169 52 if err != nil {
paddy@169 53 log.Printf("Error sending event: %#+v\n", err)
paddy@169 54 }
paddy@169 55 }