Simplify some code
This commit is contained in:
parent
f8040df68d
commit
5fae49a971
|
@ -201,16 +201,11 @@ func main() {
|
||||||
Verbose: flags.verbose,
|
Verbose: flags.verbose,
|
||||||
Script: flags.script,
|
Script: flags.script,
|
||||||
ScriptDir: defaultScriptDir(),
|
ScriptDir: defaultScriptDir(),
|
||||||
SendmailPath: "/usr/sbin/sendmail",
|
|
||||||
Email: flags.email,
|
Email: flags.email,
|
||||||
Stdout: flags.stdout,
|
Stdout: flags.stdout,
|
||||||
HealthCheckInterval: flags.healthcheck,
|
HealthCheckInterval: flags.healthcheck,
|
||||||
}
|
}
|
||||||
|
|
||||||
if envVar := os.Getenv("SENDMAIL_PATH"); envVar != "" {
|
|
||||||
config.SendmailPath = envVar
|
|
||||||
}
|
|
||||||
|
|
||||||
emailFileExists := false
|
emailFileExists := false
|
||||||
if emailRecipients, err := readEmailFile(defaultEmailFile()); err == nil {
|
if emailRecipients, err := readEmailFile(defaultEmailFile()); err == nil {
|
||||||
emailFileExists = true
|
emailFileExists = true
|
||||||
|
|
|
@ -20,7 +20,6 @@ type Config struct {
|
||||||
WatchList WatchList
|
WatchList WatchList
|
||||||
Verbose bool
|
Verbose bool
|
||||||
SaveCerts bool
|
SaveCerts bool
|
||||||
SendmailPath string
|
|
||||||
Script string
|
Script string
|
||||||
ScriptDir string
|
ScriptDir string
|
||||||
Email []string
|
Email []string
|
||||||
|
|
|
@ -36,7 +36,7 @@ func notify(ctx context.Context, config *Config, notif notification) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(config.Email) > 0 {
|
if len(config.Email) > 0 {
|
||||||
if err := sendEmail(ctx, config.SendmailPath, config.Email, notif); err != nil {
|
if err := sendEmail(ctx, config.Email, notif); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,10 +62,15 @@ func writeToStdout(notif notification) {
|
||||||
os.Stdout.WriteString(notif.Text() + "\n")
|
os.Stdout.WriteString(notif.Text() + "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendEmail(ctx context.Context, sendmailPath string, to []string, notif notification) error {
|
func sendEmail(ctx context.Context, to []string, notif notification) error {
|
||||||
stdin := new(bytes.Buffer)
|
stdin := new(bytes.Buffer)
|
||||||
stderr := new(bytes.Buffer)
|
stderr := new(bytes.Buffer)
|
||||||
|
|
||||||
|
sendmailPath := "/usr/sbin/sendmail"
|
||||||
|
if envVar := os.Getenv("SENDMAIL_PATH"); envVar != "" {
|
||||||
|
sendmailPath = envVar
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Fprintf(stdin, "To: %s\n", strings.Join(to, ", "))
|
fmt.Fprintf(stdin, "To: %s\n", strings.Join(to, ", "))
|
||||||
fmt.Fprintf(stdin, "Subject: [certspotter] %s\n", notif.Summary())
|
fmt.Fprintf(stdin, "Subject: [certspotter] %s\n", notif.Summary())
|
||||||
fmt.Fprintf(stdin, "Mime-Version: 1.0\n")
|
fmt.Fprintf(stdin, "Mime-Version: 1.0\n")
|
||||||
|
|
Loading…
Reference in New Issue