feat: add the ability to set a MAILFROM value for local cron emails

Closes #7419
This commit is contained in:
Jose Diaz-Gonzalez
2024-12-17 00:27:08 -05:00
parent 819f9a84c9
commit b93a47c35b
7 changed files with 50 additions and 5 deletions

View File

@@ -12,12 +12,14 @@ import (
var (
// DefaultProperties is a map of all valid cron properties with corresponding default property values
DefaultProperties = map[string]string{
"mailto": "",
"mailfrom": "",
"mailto": "",
}
// GlobalProperties is a map of all valid global cron properties
GlobalProperties = map[string]bool{
"mailto": true,
"mailfrom": true,
"mailto": true,
}
)

View File

@@ -13,6 +13,7 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
}
flags := map[string]common.ReportFunc{
"--cron-mailfrom": reportMailfrom,
"--cron-mailto": reportMailto,
"--cron-task-count": reportTasks,
}
@@ -28,6 +29,10 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
return common.ReportSingleApp("cron", appName, infoFlag, infoFlags, flagKeys, format, trimPrefix, uppercaseFirstCharacter)
}
func reportMailfrom(_ string) string {
return common.PropertyGet("cron", "--global", "mailfrom")
}
func reportMailto(_ string) string {
return common.PropertyGet("cron", "--global", "mailto")
}

View File

@@ -3,6 +3,10 @@ package cron
import "errors"
func validateSetValue(appName string, key string, value string) error {
if key == "mailfrom" && appName != "--global" {
return errors.New("Property cannot be specified on a per-app basis")
}
if key == "mailto" && appName != "--global" {
return errors.New("Property cannot be specified on a per-app basis")
}

View File

@@ -1,3 +1,6 @@
{{ if .Mailfrom -}}
MAILFROM={{ .Mailfrom }}
{{ end -}}
{{ if .Mailto -}}
MAILTO={{ .Mailto }}
{{ end -}}

View File

@@ -9,7 +9,11 @@ import (
// TriggerCronGetProperty writes the cron key to stdout for a given app container
func TriggerCronGetProperty(appName string, key string) error {
if key != "mailto" {
validProperties := map[string]bool{
"mailfrom": true,
"mailto": true,
}
if !validProperties[key] {
return errors.New("Invalid cron property specified")
}

View File

@@ -124,14 +124,21 @@ func writeCronEntries() error {
return deleteCrontab()
}
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
resultfromResults, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "cron-get-property",
Args: []string{"--global", "mailfrom"},
})
mailfrom := resultfromResults.StdoutContents()
mailtoResults, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "cron-get-property",
Args: []string{"--global", "mailto"},
})
mailto := results.StdoutContents()
mailto := mailtoResults.StdoutContents()
data := map[string]interface{}{
"Commands": commands,
"Mailfrom": mailfrom,
"Mailto": mailto,
}