-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
104 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package acme | ||
|
||
import ( | ||
"autossl/internal/service" | ||
"fmt" | ||
"go.uber.org/zap" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func Issue(name string) error { | ||
dns := os.Getenv("ACME_DNS") | ||
alias := os.Getenv("ACME_ALIAS") | ||
|
||
cmd := exec.Command(filepath.Join(usr.HomeDir, ".acme.sh/acme.sh"), "--issue", "--dns", dns, "-d", name, "--challenge-alias", alias, "--keylength", "2048") | ||
return execIssue(cmd) | ||
} | ||
|
||
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")) | ||
logger.Info("command", zap.String("Running command:", strings.Join(cmd.Args, " "))) | ||
return execIssue(cmd) | ||
} | ||
|
||
func Remove(name string) error { | ||
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, " "))) | ||
return execIssue(cmd) | ||
} | ||
|
||
func execIssue(cmd *exec.Cmd) error { | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package acme | ||
|
||
import ( | ||
"autossl/middleware" | ||
"go.uber.org/zap" | ||
"os" | ||
"os/exec" | ||
"os/user" | ||
"path/filepath" | ||
) | ||
|
||
var usr, _ = user.Current() | ||
var logger = middleware.GetLogger() | ||
|
||
func InitAcme() { | ||
ca() | ||
email() | ||
upgrade() | ||
} | ||
|
||
func ca() { | ||
ca := os.Getenv("ACME_CA") | ||
cmd := exec.Command(filepath.Join(usr.HomeDir, ".acme.sh/acme.sh"), "--set-default-ca", "--server", ca) | ||
execSetting(cmd) | ||
} | ||
|
||
func email() { | ||
email := os.Getenv("ACME_EMAIL") | ||
cmd := exec.Command(filepath.Join(usr.HomeDir, ".acme.sh/acme.sh"), "--update-account", "--email", email) | ||
execSetting(cmd) | ||
} | ||
|
||
func upgrade() { | ||
cmd := exec.Command(filepath.Join(usr.HomeDir, ".acme.sh/acme.sh"), "--upgrade", "--auto-upgrade") | ||
execSetting(cmd) | ||
} | ||
|
||
func execSetting(cmd *exec.Cmd) { | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stdout | ||
err := cmd.Start() | ||
if err != nil { | ||
logger.Error("cmd.Start() failed: ", zap.String("error", err.Error())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters