From a5c171e750b14b222e567586b414e69a45ea2a67 Mon Sep 17 00:00:00 2001 From: Panagiotis Siatras Date: Tue, 22 Mar 2022 18:38:46 +0200 Subject: [PATCH] api: refactored to support the new signatures for read.JSON, read.AdminJSON & read.ProtoJSON --- api/rekey.go | 3 +-- api/revoke.go | 3 +-- api/sign.go | 3 +-- api/ssh.go | 12 ++++-------- api/sshRekey.go | 3 +-- api/sshRenew.go | 3 +-- api/sshRevoke.go | 3 +-- 7 files changed, 10 insertions(+), 20 deletions(-) diff --git a/api/rekey.go b/api/rekey.go index 3116cf74..b1a6c2fc 100644 --- a/api/rekey.go +++ b/api/rekey.go @@ -34,8 +34,7 @@ func (h *caHandler) Rekey(w http.ResponseWriter, r *http.Request) { } var body RekeyRequest - if err := read.JSON(r.Body, &body); err != nil { - render.Error(w, errs.BadRequestErr(err, "error reading request body")) + if !read.JSON(w, r, &body) { return } diff --git a/api/revoke.go b/api/revoke.go index c9da2c18..001b3624 100644 --- a/api/revoke.go +++ b/api/revoke.go @@ -51,8 +51,7 @@ func (r *RevokeRequest) Validate() (err error) { // TODO: Add CRL and OCSP support. func (h *caHandler) Revoke(w http.ResponseWriter, r *http.Request) { var body RevokeRequest - if err := read.JSON(r.Body, &body); err != nil { - render.Error(w, errs.BadRequestErr(err, "error reading request body")) + if !read.JSON(w, r, &body) { return } diff --git a/api/sign.go b/api/sign.go index b6bfcc8b..6d07029d 100644 --- a/api/sign.go +++ b/api/sign.go @@ -51,8 +51,7 @@ type SignResponse struct { // information in the certificate request. func (h *caHandler) Sign(w http.ResponseWriter, r *http.Request) { var body SignRequest - if err := read.JSON(r.Body, &body); err != nil { - render.Error(w, errs.BadRequestErr(err, "error reading request body")) + if !read.JSON(w, r, &body) { return } diff --git a/api/ssh.go b/api/ssh.go index 3b0de7c1..21d30ebc 100644 --- a/api/ssh.go +++ b/api/ssh.go @@ -252,8 +252,7 @@ type SSHBastionResponse struct { // the request. func (h *caHandler) SSHSign(w http.ResponseWriter, r *http.Request) { var body SSHSignRequest - if err := read.JSON(r.Body, &body); err != nil { - render.Error(w, errs.BadRequestErr(err, "error reading request body")) + if !read.JSON(w, r, &body) { return } @@ -396,8 +395,7 @@ func (h *caHandler) SSHFederation(w http.ResponseWriter, r *http.Request) { // and servers. func (h *caHandler) SSHConfig(w http.ResponseWriter, r *http.Request) { var body SSHConfigRequest - if err := read.JSON(r.Body, &body); err != nil { - render.Error(w, errs.BadRequestErr(err, "error reading request body")) + if !read.JSON(w, r, &body) { return } if err := body.Validate(); err != nil { @@ -428,8 +426,7 @@ func (h *caHandler) SSHConfig(w http.ResponseWriter, r *http.Request) { // SSHCheckHost is the HTTP handler that returns if a hosts certificate exists or not. func (h *caHandler) SSHCheckHost(w http.ResponseWriter, r *http.Request) { var body SSHCheckPrincipalRequest - if err := read.JSON(r.Body, &body); err != nil { - render.Error(w, errs.BadRequestErr(err, "error reading request body")) + if !read.JSON(w, r, &body) { return } if err := body.Validate(); err != nil { @@ -467,8 +464,7 @@ func (h *caHandler) SSHGetHosts(w http.ResponseWriter, r *http.Request) { // SSHBastion provides returns the bastion configured if any. func (h *caHandler) SSHBastion(w http.ResponseWriter, r *http.Request) { var body SSHBastionRequest - if err := read.JSON(r.Body, &body); err != nil { - render.Error(w, errs.BadRequestErr(err, "error reading request body")) + if !read.JSON(w, r, &body) { return } if err := body.Validate(); err != nil { diff --git a/api/sshRekey.go b/api/sshRekey.go index 92278950..acb17cca 100644 --- a/api/sshRekey.go +++ b/api/sshRekey.go @@ -41,8 +41,7 @@ type SSHRekeyResponse struct { // the request. func (h *caHandler) SSHRekey(w http.ResponseWriter, r *http.Request) { var body SSHRekeyRequest - if err := read.JSON(r.Body, &body); err != nil { - render.Error(w, errs.BadRequestErr(err, "error reading request body")) + if !read.JSON(w, r, &body) { return } diff --git a/api/sshRenew.go b/api/sshRenew.go index 78d16fa6..f85819b6 100644 --- a/api/sshRenew.go +++ b/api/sshRenew.go @@ -39,8 +39,7 @@ type SSHRenewResponse struct { // the request. func (h *caHandler) SSHRenew(w http.ResponseWriter, r *http.Request) { var body SSHRenewRequest - if err := read.JSON(r.Body, &body); err != nil { - render.Error(w, errs.BadRequestErr(err, "error reading request body")) + if read.JSON(w, r, &body) { return } diff --git a/api/sshRevoke.go b/api/sshRevoke.go index a33082cd..ba1a1de9 100644 --- a/api/sshRevoke.go +++ b/api/sshRevoke.go @@ -50,8 +50,7 @@ func (r *SSHRevokeRequest) Validate() (err error) { // NOTE: currently only Passive revocation is supported. func (h *caHandler) SSHRevoke(w http.ResponseWriter, r *http.Request) { var body SSHRevokeRequest - if err := read.JSON(r.Body, &body); err != nil { - render.Error(w, errs.BadRequestErr(err, "error reading request body")) + if !read.JSON(w, r, &body) { return }