Skip to content

Commit

Permalink
feat: acme.sh remove certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
pupilcc committed Jan 10, 2024
1 parent 9e5d258 commit e813cd5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
26 changes: 26 additions & 0 deletions middleware/acme.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,29 @@ func Install(name string, id string) error {
}
return err
}

func Remove(name string) error {
logger := GetLogger()

cmd := exec.Command(filepath.Join(usr.HomeDir, ".acme.sh/acme.sh"), "--remove", "--domain", name)
logger.Info("command", zap.String("Running command:", strings.Join(cmd.Args, " ")))
stdout, err := cmd.StdoutPipe()
if err != nil {
logger.Error("cmd.StdoutPipe() running command failed", zap.String("error:", err.Error()))
}
if err = cmd.Start(); err != nil {
logger.Error("cmd.Start() running command failed", zap.String("error:", err.Error()))
}
for {
tmp := make([]byte, 1024)
_, err := stdout.Read(tmp)
fmt.Print(string(tmp))
if err != nil {
break
}
}
if err := cmd.Wait(); err != nil {
logger.Error("cmd.Wait() running command failed", zap.String("error:", err.Error()))
}
return err
}
14 changes: 14 additions & 0 deletions web/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,27 @@ func generate(c echo.Context) error {

func remove(c echo.Context) error {
uuid := c.Param("uuid")

err := service.RemoveUUID(uuid)
if err != nil {
return c.JSON(http.StatusBadRequest, response.Message(err.Error()))
}

err = service.RemoveFiles(uuid)
if err != nil {
return c.JSON(http.StatusBadRequest, response.Message(err.Error()))
}

certs := service.GetCerts()
certMap := make(map[string]domain.Cert)
for _, cert := range certs {
certMap[cert.Id] = cert
}
if cert, exists := certMap[uuid]; exists {
if err := middleware.Remove(cert.Name); err != nil {
return c.JSON(http.StatusBadRequest, response.Message(err.Error()))
}
}

return c.JSON(http.StatusOK, response.Message("Certificate removed successfully."))
}

0 comments on commit e813cd5

Please sign in to comment.