diff options
author | Julio Capote <jcapote@gmail.com> | 2023-01-04 01:29:50 +0000 |
---|---|---|
committer | Julio Capote <jcapote@gmail.com> | 2023-01-04 01:29:50 +0000 |
commit | 54b85678185008a4f6b5778460228788e2dd970d (patch) | |
tree | bcce8ac619da7c438518801df4a57be2401f7596 /registry | |
parent | a40781358984f651214e53ba000ccc288c56d4f1 (diff) | |
download | communique-54b85678185008a4f6b5778460228788e2dd970d.tar.gz |
start of keypair model and persisting keypairs
Diffstat (limited to 'registry')
-rw-r--r-- | registry/registry.go | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/registry/registry.go b/registry/registry.go index 16ae828..bbe3f1c 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -3,6 +3,7 @@ package registry import ( "bytes" "encoding/gob" + "net/http" "net/url" "strings" @@ -23,13 +24,29 @@ type Registry struct { handlerMap map[string]Handler } -func NewRegistry(cfg config.Config, persister *models.Persister) *Registry { +func NewRegistry(cfg config.Config, persister *models.Persister) (*Registry, error) { reg := Registry{cfg: cfg, persister: persister} reg.handlerMap = make(map[string]Handler) for _, v := range cfg.Handlers { reg.handlerMap[v.Name] = Handler{handlerCfg: v} + err := generateKeypairIfNeeded(v, persister) + if err != nil { + return nil, err + } } - return ® + return ®, nil +} + +func generateKeypairIfNeeded(v config.Handler, p *models.Persister) error { + kp, err := models.CreateKeypair(v) + if err != nil { + return err + } + err = p.Store(kp) + if err != nil { + return err + } + return nil } func (r *Registry) Actor(name string) (map[string]interface{}, error) { @@ -51,7 +68,7 @@ func (r *Registry) OutboxCollection(name string) (map[string]interface{}, error) return nil, err } var outboxItems []models.OutboxItem - for _, v := range page[0:20] { //TODO pagination + for _, v := range page { //TODO pagination buf := bytes.NewBuffer(v) dec := gob.NewDecoder(buf) var outboxItem models.OutboxItem @@ -109,6 +126,18 @@ func (r *Registry) Followers(name string) (map[string]interface{}, error) { return result, nil } +func (r *Registry) Inbox(name string, req *http.Request) error { + handler := r.findByName(name) + if handler == nil { + return nil + } + // verifier, err := httpsig.NewVerifier(req) + // if err != nil { + // return err + // } + return nil +} + func (r *Registry) ActivityOrNote(activityOrNote, name, id string) (map[string]interface{}, error) { handler := r.findByName(name) if handler == nil { |