this repo has no description

add public /keys/{user} endpoint

fetch keys like gh.com/user.keys

Akshay 85599f51 13f15cf2

Changed files
+41 -4
appview
state
knotserver
+31 -3
appview/state/state.go
··· 150 } 151 152 func (s *State) Keys(w http.ResponseWriter, r *http.Request) { 153 switch r.Method { 154 case http.MethodGet: 155 w.Write([]byte("unimplemented")) ··· 524 // r.Post("/import", s.ImportRepo) 525 }) 526 527 - r.Group(func(r chi.Router) { 528 r.Use(AuthMiddleware(s)) 529 - r.Get("/settings", s.Settings) 530 - r.Put("/settings/keys", s.Keys) 531 }) 532 533 return r 534 }
··· 150 } 151 152 func (s *State) Keys(w http.ResponseWriter, r *http.Request) { 153 + user := chi.URLParam(r, "user") 154 + user = strings.TrimPrefix(user, "@") 155 + 156 + if user == "" { 157 + w.Write([]byte("not found")) 158 + return 159 + } 160 + 161 + id, err := auth.ResolveIdent(r.Context(), user) 162 + if err != nil { 163 + w.Write([]byte("not found")) 164 + return 165 + } 166 + 167 + pubKeys, err := s.db.GetPublicKeys(id.DID.String()) 168 + if err != nil { 169 + w.Write([]byte("not found")) 170 + return 171 + } 172 + 173 + for _, k := range pubKeys { 174 + w.Write([]byte(fmt.Sprintln(k.Key))) 175 + } 176 + } 177 + 178 + func (s *State) SettingsKeys(w http.ResponseWriter, r *http.Request) { 179 switch r.Method { 180 case http.MethodGet: 181 w.Write([]byte("unimplemented")) ··· 550 // r.Post("/import", s.ImportRepo) 551 }) 552 553 + r.Route("/settings", func(r chi.Router) { 554 r.Use(AuthMiddleware(s)) 555 + r.Get("/", s.Settings) 556 + r.Put("/keys", s.SettingsKeys) 557 }) 558 + 559 + r.Get("/keys/{user}", s.Keys) 560 561 return r 562 }
+10 -1
knotserver/routes.go
··· 381 did := data.Did 382 name := data.Name 383 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)
··· 381 did := data.Did 382 name := data.Name 383 384 + relativeRepoPath := filepath.Join(did, name) 385 + repoPath := filepath.Join(h.c.Repo.ScanPath, relativeRepoPath) 386 err := git.InitBare(repoPath) 387 + if err != nil { 388 + log.Println(err) 389 + writeError(w, err.Error(), http.StatusInternalServerError) 390 + return 391 + } 392 + 393 + // add perms for this user to access the repo 394 + err = h.e.AddRepo(did, ThisServer, relativeRepoPath) 395 if err != nil { 396 log.Println(err) 397 writeError(w, err.Error(), http.StatusInternalServerError)