Monorepo for Tangled
0
fork

Configure Feed

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

knotserver: add owners public keys to database on startup

Signed-off-by: Will Andrews <did:plc:dadhhalkfcq3gucaq25hjqon>

+52
+52
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 + 239 + params := map[string]interface{}{} 240 + params["repo"] = owner 241 + params["collection"] = tangled.PublicKeyNSID 242 + 243 + resp, err := comatproto.RepoListRecords(context.Background(), &xrpcc, tangled.PublicKeyNSID, "", 50, owner, false) 244 + if err != nil { 245 + h.l.Error("fetching owners public key records from pds", "error", err) 246 + return 247 + } 248 + 249 + for _, record := range resp.Records { 250 + if record == nil { 251 + continue 252 + } 253 + key := record.Value.Val.(*tangled.PublicKey) 254 + if key == nil { 255 + continue 256 + } 257 + pk := db.PublicKey{ 258 + Did: owner, 259 + PublicKey: *key, 260 + } 261 + err = h.db.AddPublicKey(pk) 262 + if err != nil { 263 + h.l.Error("adding one of the owners public keys to db", "error", err) 264 + } 265 + } 266 + 267 + h.l.Info("finished adding owners public keys") 268 + }