Skip to content

Commit

Permalink
fix: import cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
pupilcc committed Jul 30, 2024
1 parent 0a80a2a commit e715106
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
14 changes: 6 additions & 8 deletions domain/service/cert_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"path/filepath"
)

var CertPath = "./data/cert"

func ExistCert(domain string) bool {
repo := &repository.CertRepo{
Db: database.Init(),
Expand All @@ -30,7 +28,7 @@ func ExistCert(domain string) bool {
}

func CreateCert(domain string, code string) error {
err := os.MkdirAll(CertPath, 0755)
err := os.MkdirAll(acme.CertPath, 0755)
if err != nil {
return err
}
Expand Down Expand Up @@ -135,8 +133,8 @@ func Etag(filePath string) (string, error) {
}

func deleteFiles(code string) error {
certPath := filepath.Join(CertPath, code+".crt")
keyPath := filepath.Join(CertPath, code+".key")
certPath := filepath.Join(acme.CertPath, code+".crt")
keyPath := filepath.Join(acme.CertPath, code+".key")

filePaths := []string{certPath, keyPath}

Expand All @@ -162,14 +160,14 @@ func uploadFile(code string, certFile *multipart.FileHeader, keyFile *multipart.
}
defer keySrc.Close()

_ = os.MkdirAll(CertPath, 0755)
certDst, err := os.Create(filepath.Join(CertPath, code+".crt"))
_ = os.MkdirAll(acme.CertPath, 0755)
certDst, err := os.Create(filepath.Join(acme.CertPath, code+".crt"))
if err != nil {
return err
}
defer certDst.Close()

keyDst, err := os.Create(filepath.Join(CertPath, code+".key"))
keyDst, err := os.Create(filepath.Join(acme.CertPath, code+".key"))
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions infrastructure/acme/issue.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package acme

import (
"autossl/domain/service"
"fmt"
"go.uber.org/zap"
"os"
Expand All @@ -10,6 +9,8 @@ import (
"strings"
)

var CertPath = "./data/cert"

func Issue(name string) error {
dns := os.Getenv("ACME_DNS")
alias := os.Getenv("ACME_ALIAS")
Expand All @@ -19,7 +20,7 @@ func Issue(name string) error {
}

func Install(name string, id string) error {
cmd := exec.Command(filepath.Join(usr.HomeDir, ".acme.sh/acme.sh"), "--install-cert", "-d", name, "--key-file", filepath.Join(service.CertPath, id+".key"), "--fullchain-file", filepath.Join(service.CertPath, id+".crt"))
cmd := exec.Command(filepath.Join(usr.HomeDir, ".acme.sh/acme.sh"), "--install-cert", "-d", name, "--key-file", filepath.Join(CertPath, id+".key"), "--fullchain-file", filepath.Join(CertPath, id+".crt"))
logger.Info("command", zap.String("Running command:", strings.Join(cmd.Args, " ")))
return execIssue(cmd)
}
Expand Down

0 comments on commit e715106

Please sign in to comment.