DodoApp: Implement API to add new admin public key

Change-Id: Ieb411a932bfa87900c27591f372c8f4b91d7c2e3
diff --git a/core/installer/welcome/dodo_app.go b/core/installer/welcome/dodo_app.go
index 251a379..7ca9198 100644
--- a/core/installer/welcome/dodo_app.go
+++ b/core/installer/welcome/dodo_app.go
@@ -44,6 +44,7 @@
 func (s *DodoAppServer) Start() error {
 	http.HandleFunc("/update", s.handleUpdate)
 	http.HandleFunc("/register-worker", s.handleRegisterWorker)
+	http.HandleFunc("/api/add-admin-key", s.handleAddAdminKey)
 	return http.ListenAndServe(fmt.Sprintf(":%d", s.port), nil)
 }
 
@@ -93,6 +94,22 @@
 	fmt.Printf("registered worker: %s\n", req.Address)
 }
 
+type addAdminKeyReq struct {
+	Public string `json:"public"`
+}
+
+func (s *DodoAppServer) handleAddAdminKey(w http.ResponseWriter, r *http.Request) {
+	var req addAdminKeyReq
+	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
+		http.Error(w, err.Error(), http.StatusBadRequest)
+		return
+	}
+	if err := s.client.AddPublicKey("admin", req.Public); err != nil {
+		http.Error(w, err.Error(), http.StatusInternalServerError)
+		return
+	}
+}
+
 func UpdateDodoApp(client soft.Client, namespace string, sshKey string, jc installer.JobCreator, env *installer.EnvConfig) error {
 	repo, err := client.GetRepo("app")
 	if err != nil {