feat: add stdout and filesystem notification channels (#2925)

* feat: add filesystem and stdout notification channels

* configure through env vars

* compile

* feat: add compact option for debug notification channels

* fix channel mock generation

* avoid sensitive information in error message

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* add review improvements

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
Elio Bischof
2022-01-06 09:00:24 +01:00
committed by GitHub
parent 2bbbc3551a
commit aa2a1848da
37 changed files with 426 additions and 247 deletions

View File

@@ -0,0 +1,51 @@
package messages
import (
"fmt"
"regexp"
"strings"
"github.com/caos/zitadel/internal/notification/channels"
)
var (
isHTMLRgx = regexp.MustCompile(`.*<html.*>.*`)
lineBreak = "\r\n"
)
var _ channels.Message = (*Email)(nil)
type Email struct {
Recipients []string
BCC []string
CC []string
SenderEmail string
Subject string
Content string
}
func (msg *Email) GetContent() string {
headers := make(map[string]string)
headers["From"] = msg.SenderEmail
headers["To"] = strings.Join(msg.Recipients, ", ")
headers["Cc"] = strings.Join(msg.CC, ", ")
message := ""
for k, v := range headers {
message += fmt.Sprintf("%s: %s"+lineBreak, k, v)
}
//default mime-type is html
mime := "MIME-version: 1.0;" + lineBreak + "Content-Type: text/html; charset=\"UTF-8\";" + lineBreak + lineBreak
if !isHTML(msg.Content) {
mime = "MIME-version: 1.0;" + lineBreak + "Content-Type: text/plain; charset=\"UTF-8\";" + lineBreak + lineBreak
}
subject := "Subject: " + msg.Subject + lineBreak
message += subject + mime + lineBreak + msg.Content
return message
}
func isHTML(input string) bool {
return isHTMLRgx.MatchString(input)
}

View File

@@ -0,0 +1,15 @@
package messages
import "github.com/caos/zitadel/internal/notification/channels"
var _ channels.Message = (*SMS)(nil)
type SMS struct {
SenderPhoneNumber string
RecipientPhoneNumber string
Content string
}
func (msg *SMS) GetContent() string {
return msg.Content
}