Skip to content

Commit

Permalink
fix: acme ssl remove
Browse files Browse the repository at this point in the history
  • Loading branch information
pupilcc committed Jul 30, 2024
1 parent e715106 commit d5fb13d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
5 changes: 3 additions & 2 deletions application/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package application
import (
"autossl/domain/model"
"autossl/domain/service"
"autossl/infrastructure/acme"
"autossl/infrastructure/exception"
"autossl/infrastructure/util"
"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -74,7 +75,7 @@ func Upload(c echo.Context) error {

func Download(c echo.Context) error {
code := c.Param("code")
filePath := filepath.Join(service.CertPath, code)
filePath := filepath.Join(acme.CertPath, code)

etag, err := service.Etag(filePath)
if err != nil {
Expand All @@ -87,7 +88,7 @@ func Download(c echo.Context) error {

func DownloadHead(c echo.Context) error {
code := c.Param("code")
filePath := filepath.Join(service.CertPath, code)
filePath := filepath.Join(acme.CertPath, code)

etag, err := service.Etag(filePath)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions domain/repository/cert_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
type CertRepository interface {
Create(cert *model.Cert) error
FindByDomain(domain string) (*model.Cert, error)
FindByCode(code string) (*model.Cert, error)
List() ([]*model.Cert, error)
Delete(code string) error
}
14 changes: 13 additions & 1 deletion domain/service/cert_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,17 @@ func ListCert() ([]*model.Cert, error) {
}

func DeleteCert(code string) error {
var err error
repo := &repository.CertRepo{
Db: database.Init(),
}
err := repo.Delete(code)

byCode, err := repo.FindByCode(code)
if err != nil {
return err
}

err = acme.Remove(byCode.Domain)
if err != nil {
return err
}
Expand All @@ -113,6 +120,11 @@ func DeleteCert(code string) error {
return err
}

err = repo.Delete(code)
if err != nil {
return err
}

return nil
}

Expand Down
8 changes: 8 additions & 0 deletions infrastructure/repository/cert_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func (repo *CertRepo) FindByDomain(domain string) (*model.Cert, error) {
return ToModelCert(first), err
}

func (repo *CertRepo) FindByCode(code string) (*model.Cert, error) {
first, err := repo.Db.Cert.Query().Where(cert.CodeEQ(code)).Only(context.Background())
if err != nil {
return nil, err
}
return ToModelCert(first), err
}

func (repo *CertRepo) List() ([]*model.Cert, error) {
q := repo.Db.Cert.Query().
Order(ent.Desc(cert.FieldCreatedAt))
Expand Down

0 comments on commit d5fb13d

Please sign in to comment.