Skip to content

Commit

Permalink
channel/email: Make fields required instead of setting default values
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 authored and julianbrost committed Jan 11, 2024
1 parent 63ae2d2 commit 4e5716e
Showing 1 changed file with 11 additions and 32 deletions.
43 changes: 11 additions & 32 deletions cmd/channel/email/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"github.com/jhillyerd/enmime"
"net"
"net/mail"
"os"
"os/user"
)

const (
Expand Down Expand Up @@ -103,30 +101,8 @@ func (ch *Email) SetConfig(jsonStr json.RawMessage) error {
return fmt.Errorf("failed to load config: %s %w", jsonStr, err)
}

if ch.Host == "" {
ch.Host = "localhost"
}

if ch.Port == "" {
ch.Port = "25"
}

if ch.SenderMail == "" {
hostname, err := os.Hostname()
if err != nil {
return fmt.Errorf("failed to get the OS hostname: %w", err)
}

usr, err := user.Current()
if err != nil {
return fmt.Errorf("failed to get the OS current user: %w", err)
}

ch.SenderMail = usr.Username + "@" + hostname
}

if ch.User == "" {
ch.User = ch.SenderMail
if (ch.User == "") != (ch.Password == "") {
return fmt.Errorf("user and password fields must both be set or empty")
}

return nil
Expand All @@ -143,25 +119,28 @@ func (ch *Email) GetInfo() *plugin.Info {
},
},
{
Name: "sender_mail",
Type: "string",
Name: "sender_mail",
Type: "string",
Required: true,
Label: map[string]string{
"en_US": "Sender Address",
"de_DE": "Absenderadresse",
},
Default: "icinga@example.com",
},
{
Name: "host",
Type: "string",
Name: "host",
Type: "string",
Required: true,
Label: map[string]string{
"en_US": "SMTP Host",
"de_DE": "SMTP Host",
},
},
{
Name: "port",
Type: "number",
Name: "port",
Type: "number",
Required: true,
Label: map[string]string{
"en_US": "SMTP Port",
"de_DE": "SMTP Port",
Expand Down

0 comments on commit 4e5716e

Please sign in to comment.