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