this repo has no description

update init step

Akshay 35f33cfb 65342419

Changed files
+20 -33
knotserver
+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 + 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 - Did string `json:"did"` 403 - PublicKey string `json:"key"` 404 - Created string `json:"created"` 403 + Did string `json:"did"` 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 - did := data.Did 413 - key := data.PublicKey 414 - created := data.Created 415 - 416 - if did == "" { 412 + if data.Did == "" { 417 413 writeError(w, "did is empty", http.StatusBadRequest) 418 414 return 419 415 } 420 416 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 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 + } 441 428 } 442 429 } else { 443 430 writeError(w, err.Error(), http.StatusInternalServerError) 444 431 return 445 432 } 446 433 447 - h.js.UpdateDids([]string{did}) 434 + h.js.UpdateDids([]string{data.Did}) 448 435 // Signal that the knot is ready 449 436 close(h.init) 450 - w.WriteHeader(http.StatusNoContent) 451 - } 452 437 453 - func (h *Handle) Health(w http.ResponseWriter, r *http.Request) { 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 + w.WriteHeader(http.StatusNoContent) 443 + } 444 + 445 + func (h *Handle) Health(w http.ResponseWriter, r *http.Request) { 459 446 w.Write([]byte("ok")) 460 447 }