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

Method HandleRegister

kontrol/handlers.go:19–164  ·  view source on GitHub ↗
(r *kite.Request)

Source from the content-addressed store, hash-verified

17)
18
19func (k *Kontrol) HandleRegister(r *kite.Request) (interface{}, error) {
20 k.log.Info("Register request from: %s", r.Client.Kite)
21
22 // Only accept requests with kiteKey because we need this info
23 // for generating tokens for this kite.
24 if r.Auth.Type != "kiteKey" {
25 return nil, fmt.Errorf("Unexpected authentication type: %s", r.Auth.Type)
26 }
27
28 var args struct {
29 URL string `json:"url"`
30 }
31
32 if err := r.Args.One().Unmarshal(&args); err != nil {
33 return nil, err
34 }
35
36 if args.URL == "" {
37 return nil, errors.New("empty url")
38 }
39
40 if _, err := url.Parse(args.URL); err != nil {
41 return nil, fmt.Errorf("invalid register URL: %s", err)
42 }
43
44 res := &protocol.RegisterResult{
45 URL: args.URL,
46 }
47
48 ex := &kitekey.Extractor{
49 Claims: &kitekey.KiteClaims{},
50 }
51
52 t, err := jwt.ParseWithClaims(r.Auth.Key, ex.Claims, ex.Extract)
53 if err != nil {
54 return nil, err
55 }
56
57 var keyPair *KeyPair
58 var origKey = ex.Claims.KontrolKey
59
60 // check if the key is valid and is stored in the key pair storage, if not
61 // check if there is a new key we can use.
62 keyPair, res.KiteKey, err = k.getOrUpdateKeyPub(ex.Claims.KontrolKey, t, r)
63 if err != nil {
64 return nil, err
65 }
66
67 if origKey != keyPair.Public {
68 // NOTE(rjeczalik): updates public key for old kites, new kites
69 // expect kite key to be updated
70 res.PublicKey = keyPair.Public
71 }
72
73 if err := validateKiteKey(&r.Client.Kite); err != nil {
74 return nil, err
75 }
76

Callers

nothing calls this directly

Calls 15

getOrUpdateKeyPubMethod · 0.95
validateKiteKeyFunction · 0.85
InfoMethod · 0.80
UnmarshalMethod · 0.80
OneMethod · 0.80
DebugMethod · 0.80
DoMethod · 0.80
WarningMethod · 0.80
GoWithTimeoutMethod · 0.80
UpsertMethod · 0.65
ErrorMethod · 0.65
UpdateMethod · 0.65

Tested by

no test coverage detected