auth
2015-06-29
Parent:37a42585660e
auth/profile_verification.go
Add kubernetes definitions. Define a replication controller that will spin up authd servers (using Ducky right now--other instances should rename the ducky parts appropriately). Also, my understanding of which labels go where may be shaky, which is probably evidenced by the fact that all of these things share the same lables. _Whatever_. It also hooks the generated pods up to the JWT secret volume, so they can properly read the JWT secret. Also, created a LoadBalancer Service that will route traffic to the pods created by the Replication Controller.
1 package auth
3 import (
4 "log"
5 "time"
7 "code.secondbit.org/events.hg"
8 )
10 const (
11 EventSystem = "authd"
12 EventModelLogin = "login"
13 EventActionSendVerification = "send_verification"
14 EventTopicLoginVerification = "login_verification"
15 )
17 type loginVerificationNotifier interface {
18 SendLoginVerification(login Login)
19 }
21 type stdoutNotifier struct{}
23 func NewStdoutNotifier() stdoutNotifier {
24 return stdoutNotifier{}
25 }
27 func (s stdoutNotifier) SendLoginVerification(login Login) {
28 log.Printf("Use \"%s\" as the verification code for \"%s\"\n", login.Verification, login.Value)
29 }
31 type nsqNotifier struct {
32 *events.NSQPublisher
33 }
35 func NewNSQNotifier(address string) (*nsqNotifier, error) {
36 p, err := events.NewNSQPublisher(EventSystem+"/"+Version, address)
37 return &nsqNotifier{p}, err
38 }
40 func (n *nsqNotifier) SendLoginVerification(login Login) {
41 evt := events.Event{
42 System: EventSystem,
43 Model: EventModelLogin,
44 ID: login.Value,
45 Action: EventActionSendVerification,
46 Timestamp: time.Now(),
47 Data: map[string]string{
48 "verification": login.Verification,
49 },
50 }
51 err := n.Publish(EventTopicLoginVerification, evt)
52 if err != nil {
53 log.Printf("Error sending event: %#+v\n", err)
54 }
55 }