this repo has no description

add public /keys/{user} endpoint

fetch keys like gh.com/user.keys

Akshay a0a7f683 05f2348d

Changed files
+41 -4
appview
state
knotserver
+31 -3
appview/state/state.go
··· 150 150 } 151 151 152 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) { 153 179 switch r.Method { 154 180 case http.MethodGet: 155 181 w.Write([]byte("unimplemented")) ··· 524 550 // r.Post("/import", s.ImportRepo) 525 551 }) 526 552 527 - r.Group(func(r chi.Router) { 553 + r.Route("/settings", func(r chi.Router) { 528 554 r.Use(AuthMiddleware(s)) 529 - r.Get("/settings", s.Settings) 530 - r.Put("/settings/keys", s.Keys) 555 + r.Get("/", s.Settings) 556 + r.Put("/keys", s.SettingsKeys) 531 557 }) 558 + 559 + r.Get("/keys/{user}", s.Keys) 532 560 533 561 return r 534 562 }
+10 -1
knotserver/routes.go
··· 381 381 did := data.Did 382 382 name := data.Name 383 383 384 - repoPath := filepath.Join(h.c.Repo.ScanPath, did, name) 384 + relativeRepoPath := filepath.Join(did, name) 385 + repoPath := filepath.Join(h.c.Repo.ScanPath, relativeRepoPath) 385 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) 386 395 if err != nil { 387 396 log.Println(err) 388 397 writeError(w, err.Error(), http.StatusInternalServerError)