Skip to content

Commit

Permalink
feat: Rejected handler (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
kayra1 committed Apr 24, 2024
1 parent f82ae0a commit 39f6d31
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
20 changes: 20 additions & 0 deletions internal/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func NewGoCertRouter(env *Environment) http.Handler {
router.HandleFunc("GET /certificate_requests/{id}", GetCertificateRequest(env))
router.HandleFunc("DELETE /certificate_requests/{id}", DeleteCertificateRequest(env))
router.HandleFunc("POST /certificate_requests/{id}/certificate", PostCertificate(env))
router.HandleFunc("POST /certificate_requests/{id}/certificate/reject", RejectCertificate(env))
router.HandleFunc("DELETE /certificate_requests/{id}/certificate", DeleteCertificate(env))

v1 := http.NewServeMux()
Expand Down Expand Up @@ -154,6 +155,25 @@ func PostCertificate(env *Environment) http.HandlerFunc {
}
}

func RejectCertificate(env *Environment) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
insertId, err := env.DB.Update(id, "rejected")
if err != nil {
if err.Error() == "csr id not found" {
logErrorAndWriteResponse(err.Error(), http.StatusBadRequest, w)
return
}
logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w)
return
}
w.WriteHeader(http.StatusAccepted)
if _, err := w.Write([]byte(strconv.FormatInt(insertId, 10))); err != nil {
logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w)
}
}
}

// DeleteCertificate handler receives an id as a path parameter,
// and attempts to add a given certificate to the corresponding certificate request
func DeleteCertificate(env *Environment) http.HandlerFunc {
Expand Down
Loading

0 comments on commit 39f6d31

Please sign in to comment.