+20
-33
knotserver/routes.go
+20
-33
knotserver/routes.go
···
384
repoPath := filepath.Join(h.c.Repo.ScanPath, did, name)
385
err := git.InitBare(repoPath)
386
if err != nil {
387
writeError(w, err.Error(), http.StatusInternalServerError)
388
return
389
}
···
399
}
400
401
data := struct {
402
-
Did string `json:"did"`
403
-
PublicKey string `json:"key"`
404
-
Created string `json:"created"`
405
}{}
406
407
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
···
409
return
410
}
411
412
-
did := data.Did
413
-
key := data.PublicKey
414
-
created := data.Created
415
-
416
-
if did == "" {
417
writeError(w, "did is empty", http.StatusBadRequest)
418
return
419
}
420
421
-
if key == "" {
422
-
writeError(w, "key is empty", http.StatusBadRequest)
423
-
return
424
-
}
425
-
426
-
if created == "" {
427
-
writeError(w, "created timestamp is empty", http.StatusBadRequest)
428
-
return
429
-
}
430
-
431
-
if err := h.db.AddDid(did); err == nil {
432
-
pk := db.PublicKey{
433
-
Did: did,
434
-
}
435
-
pk.Key = key
436
-
pk.Created = created
437
-
err := h.db.AddPublicKey(pk)
438
-
if err != nil {
439
-
writeError(w, err.Error(), http.StatusInternalServerError)
440
-
return
441
}
442
} else {
443
writeError(w, err.Error(), http.StatusInternalServerError)
444
return
445
}
446
447
-
h.js.UpdateDids([]string{did})
448
// Signal that the knot is ready
449
close(h.init)
450
-
w.WriteHeader(http.StatusNoContent)
451
-
}
452
453
-
func (h *Handle) Health(w http.ResponseWriter, r *http.Request) {
454
-
log.Println("got health check")
455
mac := hmac.New(sha256.New, []byte(h.c.Server.Secret))
456
mac.Write([]byte("ok"))
457
w.Header().Add("X-Signature", hex.EncodeToString(mac.Sum(nil)))
458
459
w.Write([]byte("ok"))
460
}
···
384
repoPath := filepath.Join(h.c.Repo.ScanPath, did, name)
385
err := git.InitBare(repoPath)
386
if err != nil {
387
+
log.Println(err)
388
writeError(w, err.Error(), http.StatusInternalServerError)
389
return
390
}
···
400
}
401
402
data := struct {
403
+
Did string `json:"did"`
404
+
PublicKeys []string `json:"keys"`
405
}{}
406
407
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
···
409
return
410
}
411
412
+
if data.Did == "" {
413
writeError(w, "did is empty", http.StatusBadRequest)
414
return
415
}
416
417
+
if err := h.db.AddDid(data.Did); err == nil {
418
+
for _, k := range data.PublicKeys {
419
+
pk := db.PublicKey{
420
+
Did: data.Did,
421
+
}
422
+
pk.Key = k
423
+
err := h.db.AddPublicKey(pk)
424
+
if err != nil {
425
+
writeError(w, err.Error(), http.StatusInternalServerError)
426
+
return
427
+
}
428
}
429
} else {
430
writeError(w, err.Error(), http.StatusInternalServerError)
431
return
432
}
433
434
+
h.js.UpdateDids([]string{data.Did})
435
// Signal that the knot is ready
436
close(h.init)
437
438
mac := hmac.New(sha256.New, []byte(h.c.Server.Secret))
439
mac.Write([]byte("ok"))
440
w.Header().Add("X-Signature", hex.EncodeToString(mac.Sum(nil)))
441
442
+
w.WriteHeader(http.StatusNoContent)
443
+
}
444
+
445
+
func (h *Handle) Health(w http.ResponseWriter, r *http.Request) {
446
w.Write([]byte("ok"))
447
}