From 2e729ebb262e81e870c785943611ff673b164e86 Mon Sep 17 00:00:00 2001 From: Panagiotis Siatras Date: Tue, 22 Mar 2022 18:39:13 +0200 Subject: [PATCH] authority/admin/api: refactored to support read.AdminJSON --- authority/admin/api/admin.go | 6 ++---- authority/admin/api/provisioner.go | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/authority/admin/api/admin.go b/authority/admin/api/admin.go index 5e4b9c30..6f6000e0 100644 --- a/authority/admin/api/admin.go +++ b/authority/admin/api/admin.go @@ -116,8 +116,7 @@ func (h *Handler) GetAdmins(w http.ResponseWriter, r *http.Request) { // CreateAdmin creates a new admin. func (h *Handler) CreateAdmin(w http.ResponseWriter, r *http.Request) { var body CreateAdminRequest - if err := read.JSON(r.Body, &body); err != nil { - render.Error(w, admin.WrapError(admin.ErrorBadRequestType, err, "error reading request body")) + if !read.AdminJSON(w, r, &body) { return } @@ -160,8 +159,7 @@ func (h *Handler) DeleteAdmin(w http.ResponseWriter, r *http.Request) { // UpdateAdmin updates an existing admin. func (h *Handler) UpdateAdmin(w http.ResponseWriter, r *http.Request) { var body UpdateAdminRequest - if err := read.JSON(r.Body, &body); err != nil { - render.Error(w, admin.WrapError(admin.ErrorBadRequestType, err, "error reading request body")) + if !read.AdminJSON(w, r, &body) { return } diff --git a/authority/admin/api/provisioner.go b/authority/admin/api/provisioner.go index 1cad62dd..540188f1 100644 --- a/authority/admin/api/provisioner.go +++ b/authority/admin/api/provisioner.go @@ -76,8 +76,7 @@ func (h *Handler) GetProvisioners(w http.ResponseWriter, r *http.Request) { // CreateProvisioner creates a new prov. func (h *Handler) CreateProvisioner(w http.ResponseWriter, r *http.Request) { var prov = new(linkedca.Provisioner) - if err := read.ProtoJSON(r.Body, prov); err != nil { - render.Error(w, err) + if !read.ProtoJSON(w, r, prov) { return } @@ -126,8 +125,7 @@ func (h *Handler) DeleteProvisioner(w http.ResponseWriter, r *http.Request) { // UpdateProvisioner updates an existing prov. func (h *Handler) UpdateProvisioner(w http.ResponseWriter, r *http.Request) { var nu = new(linkedca.Provisioner) - if err := read.ProtoJSON(r.Body, nu); err != nil { - render.Error(w, err) + if !read.ProtoJSON(w, r, nu) { return }