mirror of
https://github.com/zitadel/zitadel.git
synced 2025-05-19 00:58:17 +00:00

* feat: add login check lifetimes to login policy * feat: org features test * feat: debug notificatiaon events * feat: debug notification file/log commands * feat: add requests to proto * feat: add api for debug notification providers file/log * feat: add projection for debug notifiication providers * feat: requests * feat: merge v2 * feat: add settings proto to generate * feat: notifiaction providers * fix: remove unused code * Update iam_converter.go Co-authored-by: Livio Amstutz <livio.a@gmail.com>
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package fs
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"sort"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/caos/logging"
|
|
|
|
caos_errors "github.com/caos/zitadel/internal/errors"
|
|
|
|
"github.com/k3a/html2text"
|
|
|
|
"github.com/caos/zitadel/internal/notification/channels"
|
|
"github.com/caos/zitadel/internal/notification/messages"
|
|
)
|
|
|
|
func InitFSChannel(path string, config FSConfig) (channels.NotificationChannel, error) {
|
|
if path == "" {
|
|
return nil, nil
|
|
}
|
|
if err := os.MkdirAll(path, os.ModePerm); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
logging.Log("NOTIF-kSvPp").Debug("successfully initialized filesystem email and sms channel")
|
|
|
|
return channels.HandleMessageFunc(func(message channels.Message) error {
|
|
|
|
fileName := fmt.Sprintf("%d_", time.Now().Unix())
|
|
content := message.GetContent()
|
|
switch msg := message.(type) {
|
|
case *messages.Email:
|
|
recipients := make([]string, len(msg.Recipients))
|
|
copy(recipients, msg.Recipients)
|
|
sort.Strings(recipients)
|
|
fileName = fileName + "mail_to_" + strings.Join(recipients, "_") + ".html"
|
|
if config.Compact {
|
|
content = html2text.HTML2Text(content)
|
|
}
|
|
case *messages.SMS:
|
|
fileName = fileName + "sms_to_" + msg.RecipientPhoneNumber + ".txt"
|
|
default:
|
|
return caos_errors.ThrowUnimplementedf(nil, "NOTIF-6f9a1", "filesystem provider doesn't support message type %T", message)
|
|
}
|
|
|
|
return ioutil.WriteFile(filepath.Join(path, fileName), []byte(content), 0666)
|
|
}), nil
|
|
}
|