From 221e756f4098032b7f899497710602e862d13314 Mon Sep 17 00:00:00 2001 From: Mariano Cano Date: Wed, 14 Sep 2022 11:50:11 -0700 Subject: [PATCH] Use render.Error on crl endpoint --- api/crl.go | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/api/crl.go b/api/crl.go index ce0d8f73..1a4d309a 100644 --- a/api/crl.go +++ b/api/crl.go @@ -2,35 +2,20 @@ package api import ( "encoding/pem" - "fmt" - "github.com/pkg/errors" - "github.com/smallstep/certificates/errs" "net/http" + + "github.com/smallstep/certificates/api/render" ) // CRL is an HTTP handler that returns the current CRL in DER or PEM format func CRL(w http.ResponseWriter, r *http.Request) { crlBytes, err := mustAuthority(r.Context()).GetCertificateRevocationList() - - _, formatAsPEM := r.URL.Query()["pem"] - if err != nil { - - caErr, isCaErr := err.(*errs.Error) - - if isCaErr { - http.Error(w, caErr.Msg, caErr.Status) - return - } - - w.WriteHeader(500) - _, err = fmt.Fprintf(w, "%v\n", err) - if err != nil { - panic(errors.Wrap(err, "error writing http response")) - } + render.Error(w, err) return } + _, formatAsPEM := r.URL.Query()["pem"] if formatAsPEM { pemBytes := pem.EncodeToMemory(&pem.Block{ Type: "X509 CRL", @@ -38,15 +23,10 @@ func CRL(w http.ResponseWriter, r *http.Request) { }) w.Header().Add("Content-Type", "application/x-pem-file") w.Header().Add("Content-Disposition", "attachment; filename=\"crl.pem\"") - _, err = w.Write(pemBytes) + w.Write(pemBytes) } else { w.Header().Add("Content-Type", "application/pkix-crl") w.Header().Add("Content-Disposition", "attachment; filename=\"crl.der\"") - _, err = w.Write(crlBytes) + w.Write(crlBytes) } - - if err != nil { - panic(errors.Wrap(err, "error writing http response")) - } - }