2019-03-13 10:12:01 +00:00
|
|
|
// Copyright 2019 Prometheus Team
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2019-06-18 13:34:46 +00:00
|
|
|
package email
|
2019-03-13 10:12:01 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"crypto/tls"
|
2023-11-24 21:17:35 +00:00
|
|
|
"errors"
|
2019-03-13 10:12:01 +00:00
|
|
|
"fmt"
|
2024-11-06 09:09:57 +00:00
|
|
|
"log/slog"
|
2019-10-23 13:49:30 +00:00
|
|
|
"math/rand"
|
2019-03-13 10:12:01 +00:00
|
|
|
"mime"
|
|
|
|
"mime/multipart"
|
|
|
|
"mime/quotedprintable"
|
|
|
|
"net"
|
|
|
|
"net/mail"
|
|
|
|
"net/smtp"
|
|
|
|
"net/textproto"
|
2019-10-23 13:49:30 +00:00
|
|
|
"os"
|
2019-03-13 10:12:01 +00:00
|
|
|
"strings"
|
2024-08-30 14:17:15 +00:00
|
|
|
"sync"
|
2019-03-13 10:12:01 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
commoncfg "github.com/prometheus/common/config"
|
|
|
|
|
|
|
|
"github.com/prometheus/alertmanager/config"
|
2019-06-18 13:34:46 +00:00
|
|
|
"github.com/prometheus/alertmanager/notify"
|
2019-03-13 10:12:01 +00:00
|
|
|
"github.com/prometheus/alertmanager/template"
|
|
|
|
"github.com/prometheus/alertmanager/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Email implements a Notifier for email notifications.
|
|
|
|
type Email struct {
|
2019-10-23 13:49:30 +00:00
|
|
|
conf *config.EmailConfig
|
|
|
|
tmpl *template.Template
|
2024-11-06 09:09:57 +00:00
|
|
|
logger *slog.Logger
|
2019-10-23 13:49:30 +00:00
|
|
|
hostname string
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 13:34:46 +00:00
|
|
|
// New returns a new Email notifier.
|
2024-11-06 09:09:57 +00:00
|
|
|
func New(c *config.EmailConfig, t *template.Template, l *slog.Logger) *Email {
|
2019-03-13 10:12:01 +00:00
|
|
|
if _, ok := c.Headers["Subject"]; !ok {
|
|
|
|
c.Headers["Subject"] = config.DefaultEmailSubject
|
|
|
|
}
|
|
|
|
if _, ok := c.Headers["To"]; !ok {
|
|
|
|
c.Headers["To"] = c.To
|
|
|
|
}
|
|
|
|
if _, ok := c.Headers["From"]; !ok {
|
|
|
|
c.Headers["From"] = c.From
|
|
|
|
}
|
2019-10-23 13:49:30 +00:00
|
|
|
|
|
|
|
h, err := os.Hostname()
|
|
|
|
// If we can't get the hostname, we'll use localhost
|
|
|
|
if err != nil {
|
|
|
|
h = "localhost.localdomain"
|
|
|
|
}
|
|
|
|
return &Email{conf: c, tmpl: t, logger: l, hostname: h}
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// auth resolves a string of authentication mechanisms.
|
|
|
|
func (n *Email) auth(mechs string) (smtp.Auth, error) {
|
|
|
|
username := n.conf.AuthUsername
|
|
|
|
|
|
|
|
// If no username is set, keep going without authentication.
|
|
|
|
if n.conf.AuthUsername == "" {
|
2024-11-06 09:09:57 +00:00
|
|
|
n.logger.Debug("smtp_auth_username is not configured. Attempting to send email without authenticating")
|
2019-03-13 10:12:01 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
err := &types.MultiError{}
|
|
|
|
for _, mech := range strings.Split(mechs, " ") {
|
|
|
|
switch mech {
|
|
|
|
case "CRAM-MD5":
|
|
|
|
secret := string(n.conf.AuthSecret)
|
|
|
|
if secret == "" {
|
|
|
|
err.Add(errors.New("missing secret for CRAM-MD5 auth mechanism"))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return smtp.CRAMMD5Auth(username, secret), nil
|
|
|
|
|
|
|
|
case "PLAIN":
|
2022-09-16 12:36:57 +00:00
|
|
|
password, passwordErr := n.getPassword()
|
|
|
|
if passwordErr != nil {
|
|
|
|
err.Add(passwordErr)
|
|
|
|
continue
|
|
|
|
}
|
2019-03-13 10:12:01 +00:00
|
|
|
if password == "" {
|
|
|
|
err.Add(errors.New("missing password for PLAIN auth mechanism"))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
identity := n.conf.AuthIdentity
|
|
|
|
|
2019-08-28 13:04:40 +00:00
|
|
|
return smtp.PlainAuth(identity, username, password, n.conf.Smarthost.Host), nil
|
2019-03-13 10:12:01 +00:00
|
|
|
case "LOGIN":
|
2022-09-16 12:36:57 +00:00
|
|
|
password, passwordErr := n.getPassword()
|
|
|
|
if passwordErr != nil {
|
|
|
|
err.Add(passwordErr)
|
|
|
|
continue
|
|
|
|
}
|
2019-03-13 10:12:01 +00:00
|
|
|
if password == "" {
|
|
|
|
err.Add(errors.New("missing password for LOGIN auth mechanism"))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return LoginAuth(username, password), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err.Len() == 0 {
|
|
|
|
err.Add(errors.New("unknown auth mechanism: " + mechs))
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notify implements the Notifier interface.
|
|
|
|
func (n *Email) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
|
2019-07-10 09:24:51 +00:00
|
|
|
var (
|
|
|
|
c *smtp.Client
|
|
|
|
conn net.Conn
|
2019-08-28 13:04:40 +00:00
|
|
|
err error
|
2019-07-10 09:24:51 +00:00
|
|
|
success = false
|
|
|
|
)
|
2019-08-28 13:04:40 +00:00
|
|
|
if n.conf.Smarthost.Port == "465" {
|
2024-02-22 14:29:05 +00:00
|
|
|
tlsConfig, err := commoncfg.NewTLSConfig(n.conf.TLSConfig)
|
2019-03-13 10:12:01 +00:00
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return false, fmt.Errorf("parse TLS configuration: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
if tlsConfig.ServerName == "" {
|
2019-08-28 13:04:40 +00:00
|
|
|
tlsConfig.ServerName = n.conf.Smarthost.Host
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 13:04:40 +00:00
|
|
|
conn, err = tls.Dial("tcp", n.conf.Smarthost.String(), tlsConfig)
|
2019-03-13 10:12:01 +00:00
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return true, fmt.Errorf("establish TLS connection to server: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-07-10 09:24:51 +00:00
|
|
|
var (
|
|
|
|
d = net.Dialer{}
|
|
|
|
err error
|
|
|
|
)
|
2019-08-28 13:04:40 +00:00
|
|
|
conn, err = d.DialContext(ctx, "tcp", n.conf.Smarthost.String())
|
2019-03-13 10:12:01 +00:00
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return true, fmt.Errorf("establish connection to server: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-28 13:04:40 +00:00
|
|
|
c, err = smtp.NewClient(conn, n.conf.Smarthost.Host)
|
2019-07-10 09:24:51 +00:00
|
|
|
if err != nil {
|
|
|
|
conn.Close()
|
2023-11-24 21:17:35 +00:00
|
|
|
return true, fmt.Errorf("create SMTP client: %w", err)
|
2019-07-10 09:24:51 +00:00
|
|
|
}
|
2019-03-13 10:12:01 +00:00
|
|
|
defer func() {
|
2019-07-10 09:24:51 +00:00
|
|
|
// Try to clean up after ourselves but don't log anything if something has failed.
|
|
|
|
if err := c.Quit(); success && err != nil {
|
2024-11-06 09:09:57 +00:00
|
|
|
n.logger.Warn("failed to close SMTP connection", "err", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if n.conf.Hello != "" {
|
2019-07-10 09:24:51 +00:00
|
|
|
err = c.Hello(n.conf.Hello)
|
2019-03-13 10:12:01 +00:00
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return true, fmt.Errorf("send EHLO command: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Global Config guarantees RequireTLS is not nil.
|
|
|
|
if *n.conf.RequireTLS {
|
|
|
|
if ok, _ := c.Extension("STARTTLS"); !ok {
|
2023-11-24 21:17:35 +00:00
|
|
|
return true, fmt.Errorf("'require_tls' is true (default) but %q does not advertise the STARTTLS extension", n.conf.Smarthost)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
|
2024-02-22 14:29:05 +00:00
|
|
|
tlsConf, err := commoncfg.NewTLSConfig(n.conf.TLSConfig)
|
2019-03-13 10:12:01 +00:00
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return false, fmt.Errorf("parse TLS configuration: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
if tlsConf.ServerName == "" {
|
2019-08-28 13:04:40 +00:00
|
|
|
tlsConf.ServerName = n.conf.Smarthost.Host
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := c.StartTLS(tlsConf); err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return true, fmt.Errorf("send STARTTLS command: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ok, mech := c.Extension("AUTH"); ok {
|
|
|
|
auth, err := n.auth(mech)
|
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return true, fmt.Errorf("find auth mechanism: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
if auth != nil {
|
|
|
|
if err := c.Auth(auth); err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return true, fmt.Errorf("%T auth: %w", auth, err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
tmplErr error
|
2019-06-18 13:34:46 +00:00
|
|
|
data = notify.GetTemplateData(ctx, n.tmpl, as, n.logger)
|
|
|
|
tmpl = notify.TmplText(n.tmpl, data, &tmplErr)
|
2019-03-13 10:12:01 +00:00
|
|
|
)
|
2019-07-10 09:24:51 +00:00
|
|
|
from := tmpl(n.conf.From)
|
|
|
|
if tmplErr != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return false, fmt.Errorf("execute 'from' template: %w", tmplErr)
|
2019-07-10 09:24:51 +00:00
|
|
|
}
|
|
|
|
to := tmpl(n.conf.To)
|
2019-03-13 10:12:01 +00:00
|
|
|
if tmplErr != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return false, fmt.Errorf("execute 'to' template: %w", tmplErr)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addrs, err := mail.ParseAddressList(from)
|
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return false, fmt.Errorf("parse 'from' addresses: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
if len(addrs) != 1 {
|
2023-11-24 21:17:35 +00:00
|
|
|
return false, fmt.Errorf("must be exactly one 'from' address (got: %d)", len(addrs))
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
2019-07-10 09:24:51 +00:00
|
|
|
if err = c.Mail(addrs[0].Address); err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return true, fmt.Errorf("send MAIL command: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
addrs, err = mail.ParseAddressList(to)
|
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return false, fmt.Errorf("parse 'to' addresses: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
for _, addr := range addrs {
|
2019-07-10 09:24:51 +00:00
|
|
|
if err = c.Rcpt(addr.Address); err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return true, fmt.Errorf("send RCPT command: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-10 09:24:51 +00:00
|
|
|
// Send the email headers and body.
|
|
|
|
message, err := c.Data()
|
2019-03-13 10:12:01 +00:00
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return true, fmt.Errorf("send DATA command: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
2024-08-30 14:17:15 +00:00
|
|
|
closeOnce := sync.OnceValue(func() error {
|
|
|
|
return message.Close()
|
|
|
|
})
|
|
|
|
// Close the message when this method exits in order to not leak resources. Even though we're calling this explicitly
|
|
|
|
// further down, the method may exit before then.
|
|
|
|
defer func() {
|
|
|
|
// If we try close an already-closed writer, it'll send a subsequent request to the server which is invalid.
|
|
|
|
_ = closeOnce()
|
|
|
|
}()
|
2019-03-13 10:12:01 +00:00
|
|
|
|
|
|
|
buffer := &bytes.Buffer{}
|
|
|
|
for header, t := range n.conf.Headers {
|
|
|
|
value, err := n.tmpl.ExecuteTextString(t, data)
|
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return false, fmt.Errorf("execute %q header template: %w", header, err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
fmt.Fprintf(buffer, "%s: %s\r\n", header, mime.QEncoding.Encode("utf-8", value))
|
|
|
|
}
|
|
|
|
|
2019-10-23 13:49:30 +00:00
|
|
|
if _, ok := n.conf.Headers["Message-Id"]; !ok {
|
|
|
|
fmt.Fprintf(buffer, "Message-Id: %s\r\n", fmt.Sprintf("<%d.%d@%s>", time.Now().UnixNano(), rand.Uint64(), n.hostname))
|
|
|
|
}
|
|
|
|
|
2019-03-13 10:12:01 +00:00
|
|
|
multipartBuffer := &bytes.Buffer{}
|
|
|
|
multipartWriter := multipart.NewWriter(multipartBuffer)
|
|
|
|
|
|
|
|
fmt.Fprintf(buffer, "Date: %s\r\n", time.Now().Format(time.RFC1123Z))
|
|
|
|
fmt.Fprintf(buffer, "Content-Type: multipart/alternative; boundary=%s\r\n", multipartWriter.Boundary())
|
|
|
|
fmt.Fprintf(buffer, "MIME-Version: 1.0\r\n\r\n")
|
|
|
|
|
|
|
|
// TODO: Add some useful headers here, such as URL of the alertmanager
|
|
|
|
// and active/resolved.
|
2019-07-10 09:24:51 +00:00
|
|
|
_, err = message.Write(buffer.Bytes())
|
2019-03-13 10:12:01 +00:00
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return false, fmt.Errorf("write headers: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(n.conf.Text) > 0 {
|
|
|
|
// Text template
|
|
|
|
w, err := multipartWriter.CreatePart(textproto.MIMEHeader{
|
|
|
|
"Content-Transfer-Encoding": {"quoted-printable"},
|
|
|
|
"Content-Type": {"text/plain; charset=UTF-8"},
|
|
|
|
})
|
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return false, fmt.Errorf("create part for text template: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
body, err := n.tmpl.ExecuteTextString(n.conf.Text, data)
|
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return false, fmt.Errorf("execute text template: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
qw := quotedprintable.NewWriter(w)
|
|
|
|
_, err = qw.Write([]byte(body))
|
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return true, fmt.Errorf("write text part: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
err = qw.Close()
|
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return true, fmt.Errorf("close text part: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(n.conf.HTML) > 0 {
|
|
|
|
// Html template
|
|
|
|
// Preferred alternative placed last per section 5.1.4 of RFC 2046
|
|
|
|
// https://www.ietf.org/rfc/rfc2046.txt
|
|
|
|
w, err := multipartWriter.CreatePart(textproto.MIMEHeader{
|
|
|
|
"Content-Transfer-Encoding": {"quoted-printable"},
|
|
|
|
"Content-Type": {"text/html; charset=UTF-8"},
|
|
|
|
})
|
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return false, fmt.Errorf("create part for html template: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
body, err := n.tmpl.ExecuteHTMLString(n.conf.HTML, data)
|
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return false, fmt.Errorf("execute html template: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
qw := quotedprintable.NewWriter(w)
|
|
|
|
_, err = qw.Write([]byte(body))
|
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return true, fmt.Errorf("write HTML part: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
err = qw.Close()
|
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return true, fmt.Errorf("close HTML part: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = multipartWriter.Close()
|
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return false, fmt.Errorf("close multipartWriter: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
|
2019-07-10 09:24:51 +00:00
|
|
|
_, err = message.Write(multipartBuffer.Bytes())
|
2019-03-13 10:12:01 +00:00
|
|
|
if err != nil {
|
2023-11-24 21:17:35 +00:00
|
|
|
return false, fmt.Errorf("write body buffer: %w", err)
|
2019-03-13 10:12:01 +00:00
|
|
|
}
|
|
|
|
|
2024-08-30 14:17:15 +00:00
|
|
|
// Complete the message and await response.
|
|
|
|
if err = closeOnce(); err != nil {
|
|
|
|
return true, fmt.Errorf("delivery failure: %w", err)
|
|
|
|
}
|
|
|
|
|
2019-07-10 09:24:51 +00:00
|
|
|
success = true
|
2019-03-13 10:12:01 +00:00
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type loginAuth struct {
|
|
|
|
username, password string
|
|
|
|
}
|
|
|
|
|
|
|
|
func LoginAuth(username, password string) smtp.Auth {
|
|
|
|
return &loginAuth{username, password}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {
|
|
|
|
return "LOGIN", []byte{}, nil
|
|
|
|
}
|
|
|
|
|
2024-03-21 11:26:46 +00:00
|
|
|
// Used for AUTH LOGIN. (Maybe password should be encrypted).
|
2019-03-13 10:12:01 +00:00
|
|
|
func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
|
|
|
|
if more {
|
|
|
|
switch strings.ToLower(string(fromServer)) {
|
|
|
|
case "username:":
|
|
|
|
return []byte(a.username), nil
|
|
|
|
case "password:":
|
|
|
|
return []byte(a.password), nil
|
|
|
|
default:
|
|
|
|
return nil, errors.New("unexpected server challenge")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
2022-09-16 12:36:57 +00:00
|
|
|
|
|
|
|
func (n *Email) getPassword() (string, error) {
|
|
|
|
if len(n.conf.AuthPasswordFile) > 0 {
|
|
|
|
content, err := os.ReadFile(n.conf.AuthPasswordFile)
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("could not read %s: %w", n.conf.AuthPasswordFile, err)
|
|
|
|
}
|
2024-01-22 20:26:18 +00:00
|
|
|
return strings.TrimSpace(string(content)), nil
|
2022-09-16 12:36:57 +00:00
|
|
|
}
|
|
|
|
return string(n.conf.AuthPassword), nil
|
|
|
|
}
|