This commit is contained in:
Kegan Dougal 2021-07-09 16:26:38 +01:00
parent 6e04b8022d
commit 02a6f9b8ec
2 changed files with 5 additions and 3 deletions

View file

@ -1,6 +1,7 @@
package routing package routing
import ( import (
"context"
"crypto/hmac" "crypto/hmac"
"crypto/sha1" "crypto/sha1"
"encoding/hex" "encoding/hex"
@ -11,6 +12,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/util" "github.com/matrix-org/util"
cache "github.com/patrickmn/go-cache" cache "github.com/patrickmn/go-cache"
) )
@ -25,7 +27,7 @@ type SharedSecretRegistrationRequest struct {
} }
func NewSharedSecretRegistrationRequest(reader io.ReadCloser) (*SharedSecretRegistrationRequest, error) { func NewSharedSecretRegistrationRequest(reader io.ReadCloser) (*SharedSecretRegistrationRequest, error) {
defer reader.Close() defer internal.CloseAndLogIfError(context.Background(), reader, "NewSharedSecretRegistrationRequest: failed to close request body")
var ssrr SharedSecretRegistrationRequest var ssrr SharedSecretRegistrationRequest
err := json.NewDecoder(reader).Decode(&ssrr) err := json.NewDecoder(reader).Decode(&ssrr)
if err != nil { if err != nil {

View file

@ -94,7 +94,7 @@ func Setup(
sr := NewSharedSecretRegistration(cfg.RegistrationSharedSecret) sr := NewSharedSecretRegistration(cfg.RegistrationSharedSecret)
synapseAdminRouter.Handle("/admin/v1/register", synapseAdminRouter.Handle("/admin/v1/register",
httputil.MakeExternalAPI("shared_secret_registration", func(req *http.Request) util.JSONResponse { httputil.MakeExternalAPI("shared_secret_registration", func(req *http.Request) util.JSONResponse {
if req.Method == "GET" { if req.Method == http.MethodGet {
return util.JSONResponse{ return util.JSONResponse{
Code: 200, Code: 200,
JSON: struct { JSON: struct {
@ -104,7 +104,7 @@ func Setup(
}, },
} }
} }
if req.Method == "POST" { if req.Method == http.MethodPost {
return handleSharedSecretRegistration(userAPI, sr, req) return handleSharedSecretRegistration(userAPI, sr, req)
} }
return util.JSONResponse{ return util.JSONResponse{