this repo has no description

add publickeys to pdses

Akshay daa22356 96840b4d

+22
cmd/gen.go
··· 1 + package main 2 + 3 + import ( 4 + shbild "github.com/icyphox/bild/api/bild" 5 + cbg "github.com/whyrusleeping/cbor-gen" 6 + ) 7 + 8 + func main() { 9 + 10 + genCfg := cbg.Gen{ 11 + MaxStringLength: 1_000_000, 12 + } 13 + 14 + if err := genCfg.WriteMapEncodersToFile( 15 + "api/bild/cbor_gen.go", 16 + "bild", 17 + shbild.PublicKey{}, 18 + ); err != nil { 19 + panic(err) 20 + } 21 + 22 + }
+1
flake.nix
··· 49 49 pkgs.gopls 50 50 pkgs.httpie 51 51 pkgs.indigo-lexgen 52 + pkgs.litecli 52 53 ]; 53 54 }; 54 55 });
+1 -1
go.mod
··· 38 38 github.com/go-logr/stdr v1.2.2 // indirect 39 39 github.com/gogo/protobuf v1.3.2 // indirect 40 40 github.com/google/go-cmp v0.6.0 // indirect 41 - github.com/google/uuid v1.4.0 // indirect 41 + github.com/google/uuid v1.6.0 // indirect 42 42 github.com/gorilla/css v1.0.1 // indirect 43 43 github.com/gorilla/securecookie v1.1.2 // indirect 44 44 github.com/gorilla/sessions v1.4.0 // indirect
+2
go.sum
··· 80 80 github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= 81 81 github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= 82 82 github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 83 + github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= 84 + github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 83 85 github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= 84 86 github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8= 85 87 github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
+9
lexicon-build-config.json
··· 1 + [ 2 + { 3 + "package": "bild", 4 + "prefix": "sh.bild", 5 + "outdir": "api/bild", 6 + "import": "github.com/icyphox/bild/api/bild", 7 + "gen-server": true 8 + } 9 + ]
+38
lexicons/publicKey.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "sh.bild.publicKey", 4 + "needsCbor": true, 5 + "needsType": true, 6 + "defs": { 7 + "main": { 8 + "type": "record", 9 + "key": "tid", 10 + "record": { 11 + "type": "object", 12 + "required": [ 13 + "key", 14 + "name", 15 + "created" 16 + ], 17 + "properties": { 18 + "key": { 19 + "type": "string", 20 + "maxLength": 4096, 21 + "maxGraphemes": 4096, 22 + "description": "public key contents" 23 + }, 24 + "name": { 25 + "type": "string", 26 + "format": "string", 27 + "description": "human-readable name for this key" 28 + }, 29 + "created": { 30 + "type": "string", 31 + "format": "datetime", 32 + "description": "key upload timestamp" 33 + } 34 + } 35 + } 36 + } 37 + } 38 + }
+24
routes/auth/auth.go
··· 31 31 return dir.Lookup(ctx, *id) 32 32 } 33 33 34 + func (a *Auth) AuthorizedClient(r *http.Request) (*xrpc.Client, error) { 35 + clientSession, err := a.s.Get(r, "bild-session") 36 + 37 + if err != nil || clientSession.IsNew { 38 + return nil, err 39 + } 40 + 41 + did := clientSession.Values["did"].(string) 42 + pdsUrl := clientSession.Values["pds"].(string) 43 + accessJwt := clientSession.Values["accessJwt"].(string) 44 + refreshJwt := clientSession.Values["refreshJwt"].(string) 45 + 46 + client := &xrpc.Client{ 47 + Host: pdsUrl, 48 + Auth: &xrpc.AuthInfo{ 49 + AccessJwt: accessJwt, 50 + RefreshJwt: refreshJwt, 51 + Did: did, 52 + }, 53 + } 54 + 55 + return client, nil 56 + } 57 + 34 58 func (a *Auth) CreateInitialSession(w http.ResponseWriter, r *http.Request, username, appPassword string) (AtSessionCreate, error) { 35 59 ctx := r.Context() 36 60 resolved, err := resolveIdent(ctx, username)
+26
routes/routes.go
··· 14 14 "strings" 15 15 "time" 16 16 17 + comatproto "github.com/bluesky-social/indigo/api/atproto" 18 + lexutil "github.com/bluesky-social/indigo/lex/util" 17 19 "github.com/dustin/go-humanize" 18 20 "github.com/go-chi/chi/v5" 19 21 "github.com/go-git/go-git/v5/plumbing" 22 + "github.com/google/uuid" 20 23 "github.com/gorilla/sessions" 24 + shbild "github.com/icyphox/bild/api/bild" 21 25 "github.com/icyphox/bild/config" 22 26 "github.com/icyphox/bild/db" 23 27 "github.com/icyphox/bild/git" ··· 490 494 case http.MethodPut: 491 495 key := r.FormValue("key") 492 496 name := r.FormValue("name") 497 + client, _ := h.auth.AuthorizedClient(r) 493 498 494 499 _, _, _, _, err := ssh.ParseAuthorizedKey([]byte(key)) 495 500 if err != nil { ··· 503 508 log.Printf("adding public key: %s", err) 504 509 return 505 510 } 511 + 512 + // store in pds too 513 + resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 514 + Collection: "sh.bild.publicKey", 515 + Repo: did, 516 + Rkey: uuid.New().String(), 517 + Record: &lexutil.LexiconTypeDecoder{Val: &shbild.PublicKey{ 518 + Created: time.Now().String(), 519 + Key: key, 520 + Name: name, 521 + }}, 522 + }) 523 + 524 + // invalid record 525 + if err != nil { 526 + h.WriteOOBNotice(w, "keys", "Invalid inputs. Check your formatting and try again.") 527 + log.Printf("failed to create record: %s", err) 528 + return 529 + } 530 + 531 + log.Println("created atproto record: ", resp.Uri) 506 532 507 533 h.WriteOOBNotice(w, "keys", "Key added!") 508 534 return