feat: implement POST /s5/registry
This commit is contained in:
parent
cde3f90d2d
commit
acb9604b02
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue