notifications: add http service
This commit is contained in:
parent
52dbc353e5
commit
b542711078
@ -125,6 +125,10 @@ func (opts *ConfigOpts) ReadConfig() *ConfigOpts {
|
||||
|
||||
log.Info().Str("config file", opts.ConfigFilePath).Send()
|
||||
|
||||
if err := opts.setupVault(); err != nil {
|
||||
log.Err(err).Send()
|
||||
}
|
||||
|
||||
unmarshalConfig(backyKoanf, "commands", &opts.Cmds, opts.Logger)
|
||||
|
||||
getCommandEnvironments(opts)
|
||||
@ -153,10 +157,6 @@ func (opts *ConfigOpts) ReadConfig() *ConfigOpts {
|
||||
|
||||
opts.SetupNotify()
|
||||
|
||||
if err := opts.setupVault(); err != nil {
|
||||
log.Err(err).Send()
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ package backy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
stdHttp "net/http"
|
||||
"strings"
|
||||
|
||||
"git.andrewnw.xyz/CyberShell/backy/pkg/logging"
|
||||
@ -33,7 +32,8 @@ type MailConfig struct {
|
||||
}
|
||||
|
||||
type HttpConfig struct {
|
||||
Url string `yaml:"url"`
|
||||
URL string `yaml:"url"`
|
||||
Method string `yaml:"method"`
|
||||
Headers map[string][]string `yaml:"headers"`
|
||||
}
|
||||
|
||||
@ -66,6 +66,7 @@ func (opts *ConfigOpts) SetupNotify() {
|
||||
continue
|
||||
}
|
||||
conf.Password = getExternalConfigDirectiveValue(conf.Password, opts)
|
||||
opts.Logger.Debug().Str("list", confName).Str("id", confId).Msg("adding mail notification service")
|
||||
mailConf := setupMail(conf)
|
||||
services = append(services, mailConf)
|
||||
case "matrix":
|
||||
@ -75,6 +76,7 @@ func (opts *ConfigOpts) SetupNotify() {
|
||||
continue
|
||||
}
|
||||
conf.AccessToken = getExternalConfigDirectiveValue(conf.AccessToken, opts)
|
||||
opts.Logger.Debug().Str("list", confName).Str("id", confId).Msg("adding matrix notification service")
|
||||
mtrxConf, mtrxErr := setupMatrix(conf)
|
||||
if mtrxErr != nil {
|
||||
opts.Logger.Info().Str("list", confName).Err(fmt.Errorf("error: configuring matrix id %s failed during setup: %w", id, mtrxErr))
|
||||
@ -87,9 +89,9 @@ func (opts *ConfigOpts) SetupNotify() {
|
||||
opts.Logger.Info().Err(fmt.Errorf("error: ID %s not found in http object", confId)).Str("list", confName).Send()
|
||||
continue
|
||||
}
|
||||
opts.Logger.Debug().Str("list", confName).Str("id", confId).Msg("adding http notification service")
|
||||
httpConf := setupHttp(conf)
|
||||
services = append(services, httpConf)
|
||||
|
||||
default:
|
||||
opts.Logger.Info().Err(fmt.Errorf("id %s not found", id)).Str("list", confName).Send()
|
||||
}
|
||||
@ -119,14 +121,13 @@ func setupMail(config MailConfig) *mail.Mail {
|
||||
func setupHttp(httpConf HttpConfig) *http.Service {
|
||||
|
||||
httpService := http.New()
|
||||
// httpService.AddReceiversURLs(httpConf.Url)
|
||||
httpService.AddReceivers(&http.Webhook{
|
||||
URL: httpConf.Url,
|
||||
URL: httpConf.URL,
|
||||
Header: httpConf.Headers,
|
||||
ContentType: "text/plain",
|
||||
Method: stdHttp.MethodPost,
|
||||
Method: httpConf.Method,
|
||||
BuildPayload: func(subject, message string) (payload any) {
|
||||
return "[text/plain]: " + subject + " - " + message
|
||||
return subject + "\n\n" + message
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -393,7 +393,6 @@ func getExternalConfigDirectiveValue(key string, opts *ConfigOpts) string {
|
||||
key = strings.TrimSuffix(key, externDirectiveEnd)
|
||||
key = GetVaultKey(key, opts, opts.Logger)
|
||||
}
|
||||
println(key)
|
||||
|
||||
return key
|
||||
}
|
||||
@ -418,7 +417,6 @@ func getVaultSecret(vaultClient *vault.Client, key *VaultKey) (string, error) {
|
||||
}
|
||||
|
||||
value, ok := secret.Data[key.Key].(string)
|
||||
println(value)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("value type assertion failed for vault key %s: %T %#v", key.Name, secret.Data[key.Name], secret.Data[key.Name])
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user