MCPcopy Index your code
hub / github.com/koding/kite / HandleRegisterHTTP

Method HandleRegisterHTTP

kontrol/http.go:52–232  ·  view source on GitHub ↗
(rw http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

50}
51
52func (k *Kontrol) HandleRegisterHTTP(rw http.ResponseWriter, req *http.Request) {
53 var args protocol.RegisterArgs
54
55 if err := json.NewDecoder(req.Body).Decode(&args); err != nil {
56 errMsg := fmt.Errorf("wrong register input: '%s'", err)
57 http.Error(rw, jsonError(errMsg), http.StatusBadRequest)
58 return
59 }
60
61 k.log.Info("Register (via HTTP) request from: %s", args.Kite)
62
63 // Only accept requests with kiteKey, because that's the only way one can
64 // register itself to kontrol.
65 if args.Auth.Type != "kiteKey" {
66 err := fmt.Errorf("unexpected authentication type: %s", args.Auth.Type)
67 http.Error(rw, jsonError(err), http.StatusBadRequest)
68 return
69 }
70
71 // empty url is useless for us
72 if args.URL == "" {
73 err := errors.New("empty URL")
74 http.Error(rw, jsonError(err), http.StatusBadRequest)
75 return
76 }
77
78 // decode and authenticated the token key. We'll get the authenticated
79 // username
80 username, err := k.Kite.AuthenticateSimpleKiteKey(args.Auth.Key)
81 if err != nil {
82 http.Error(rw, jsonError(err), http.StatusUnauthorized)
83 return
84 }
85 args.Kite.Username = username
86
87 ex := &kitekey.Extractor{
88 Claims: &kitekey.KiteClaims{},
89 }
90
91 t, err := jwt.ParseWithClaims(args.Auth.Key, ex.Claims, ex.Extract)
92 if err != nil {
93 http.Error(rw, jsonError(err), http.StatusBadRequest)
94 return
95 }
96
97 var keyPair *KeyPair
98 resp := &protocol.RegisterResult{
99 URL: args.URL,
100 HeartbeatInterval: int64(HeartbeatInterval / time.Second),
101 }
102
103 // check if the key is valid and is stored in the key pair storage, if not
104 // found we don't allow to register anyone.
105 r := &kite.Request{
106 Username: username,
107 Auth: &kite.Auth{
108 Type: args.Auth.Type,
109 Key: args.Auth.Key,

Callers

nothing calls this directly

Calls 10

getOrUpdateKeyPubMethod · 0.95
jsonErrorFunction · 0.85
validateKiteKeyFunction · 0.85
InfoMethod · 0.80
ResetMethod · 0.80
DebugMethod · 0.80
ErrorMethod · 0.65
UpsertMethod · 0.65
UpdateMethod · 0.65

Tested by

no test coverage detected