Parcourir la source

authority/admin/api: refactored to support read.AdminJSON

Panagiotis Siatras il y a 4 ans
Parent
commit
2e729ebb26
2 fichiers modifiés avec 4 ajouts et 8 suppressions
  1. 2 4
      authority/admin/api/admin.go
  2. 2 4
      authority/admin/api/provisioner.go

+ 2 - 4
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
 	}
 

+ 2 - 4
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
 	}