34 lines
888 B
Go
34 lines
888 B
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"scm/model"
|
|
)
|
|
|
|
func DeleteCert(w http.ResponseWriter, r *http.Request) {
|
|
var requestData model.DeleteCertRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&requestData); err != nil {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
return
|
|
}
|
|
_, err := os.Stat(fmt.Sprintf("%s/%s", os.Getenv("CERTS_PATH"), requestData.Domain))
|
|
if err == nil {
|
|
err = os.RemoveAll(fmt.Sprintf("%s/%s", os.Getenv("CERTS_PATH"), requestData.Domain))
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
fmt.Fprintf(w, "%s", `{"status": "success"}`)
|
|
} else if !os.IsNotExist(err) {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
} else {
|
|
http.Error(w, "Certificate not found", http.StatusNotFound)
|
|
return
|
|
}
|
|
// TODO: Implement delete certificate functionality
|
|
}
|