feat: implement POST /s5/registry

This commit is contained in:
Derrick Hammer 2024-01-17 16:20:51 -05:00
parent cde3f90d2d
commit acb9604b02
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 39 additions and 1 deletions

View File

@ -50,5 +50,6 @@ func getRoutes(h *s5.HttpHandler, portal interfaces.Portal) map[string]jape.Hand
//Registry API
"GET /s5/registry": s5.AuthMiddleware(h.RegistryQuery, portal),
"POST /s5/registry": s5.AuthMiddleware(h.RegistrySet, portal),
}
}

View File

@ -11,6 +11,7 @@ import (
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
s5interfaces "git.lumeweb.com/LumeWeb/libs5-go/interfaces"
"git.lumeweb.com/LumeWeb/libs5-go/metadata"
s5protocol "git.lumeweb.com/LumeWeb/libs5-go/protocol"
s5storage "git.lumeweb.com/LumeWeb/libs5-go/storage"
"git.lumeweb.com/LumeWeb/libs5-go/types"
"git.lumeweb.com/LumeWeb/portal/db/models"
@ -971,6 +972,35 @@ func (h *HttpHandler) RegistryQuery(jc jape.Context) {
Signature: base64.RawURLEncoding.EncodeToString(entry.Signature()),
})
}
func (h *HttpHandler) RegistrySet(jc jape.Context) {
var request RegistrySetRequest
if jc.Decode(&request) != nil {
return
}
pk, err := base64.RawURLEncoding.DecodeString(request.Pk)
if jc.Check("error decoding pk", err) != nil {
return
}
data, err := base64.RawURLEncoding.DecodeString(request.Data)
if jc.Check("error decoding data", err) != nil {
return
}
signature, err := base64.RawURLEncoding.DecodeString(request.Signature)
if jc.Check("error decoding signature", err) != nil {
return
}
entry := s5protocol.NewSignedRegistryEntry(pk, request.Revision, data, signature)
err = h.getNode().Services().Registry().Set(entry, false, nil)
if jc.Check("error setting registry entry", err) != nil {
return
}
}
func (h *HttpHandler) getNode() s5interfaces.Node {
proto, _ := h.portal.ProtocolRegistry().Get("s5")

View File

@ -59,3 +59,10 @@ type RegistryQueryResponse struct {
Data string `json:"data"`
Signature string `json:"signature"`
}
type RegistrySetRequest struct {
Pk string `json:"pk"`
Revision uint64 `json:"revision"`
Data string `json:"data"`
Signature string `json:"signature"`
}