Monorepo for Tangled tangled.org
758
fork

Configure Feed

Select the types of activity you want to include in your feed.

knotserver: add owners public keys to database on startup #270

open opened by willdot.net targeting master from willdot.net/tangled-fork: knot-owner-keys

When a knot is first created, the owners public keys are not available unless the owner manually adds them again via the appview.

This change will automatically get all the owners public keys from their PDS record and add them to the knotservers public keys database.

Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:dadhhalkfcq3gucaq25hjqon/sh.tangled.repo.pull/3mknyooc7l422
+47
Diff #1
+47
knotserver/router.go
··· 9 9 "strings" 10 10 "sync" 11 11 12 + comatproto "github.com/bluesky-social/indigo/api/atproto" 13 + "github.com/bluesky-social/indigo/atproto/syntax" 14 + indigoxrpc "github.com/bluesky-social/indigo/xrpc" 12 15 "github.com/go-chi/chi/v5" 16 + "tangled.org/core/api/tangled" 13 17 "tangled.org/core/idresolver" 14 18 "tangled.org/core/jetstream" 15 19 "tangled.org/core/knotserver/config" ··· 212 216 return fmt.Errorf("failed to add owner to RBAC: %w", err) 213 217 } 214 218 219 + h.addOwnersKeys(cfgOwner) 220 + 215 221 return nil 216 222 } 223 + 224 + func (h *Knot) addOwnersKeys(owner string) { 225 + id, err := h.resolver.Directory().LookupDID(context.Background(), syntax.DID(owner)) 226 + if err != nil { 227 + h.l.Warn("failed to lookup owners did while adding their keys") 228 + return 229 + } 230 + 231 + serviceEndpoint, ok := id.Services["atproto_pds"] 232 + if !ok { 233 + h.l.Warn("owners identity did not contain atproto_pds service while adding their keys") 234 + return 235 + } 236 + 237 + xrpcc := indigoxrpc.Client{Host: serviceEndpoint.URL} 238 + resp, err := comatproto.RepoListRecords(context.Background(), &xrpcc, tangled.PublicKeyNSID, "", 50, owner, false) 239 + if err != nil { 240 + h.l.Error("fetching owners public key records from pds", "error", err) 241 + return 242 + } 243 + 244 + for _, record := range resp.Records { 245 + if record == nil { 246 + continue 247 + } 248 + key := record.Value.Val.(*tangled.PublicKey) 249 + if key == nil { 250 + continue 251 + } 252 + pk := db.PublicKey{ 253 + Did: owner, 254 + PublicKey: *key, 255 + } 256 + err = h.db.AddPublicKey(pk) 257 + if err != nil { 258 + h.l.Error("adding one of the owners public keys to db", "error", err) 259 + } 260 + } 261 + 262 + h.l.Info("finished adding owners public keys") 263 + }

History

2 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
knotserver: add owners public keys to database on startup
no conflicts, ready to merge
expand 0 comments
1 commit
expand
knotserver: add owners public keys to database on startup
expand 0 comments