Compare commits

...

2 Commits

Author SHA1 Message Date
cd5f7611a9 notifications: add http service
All checks were successful
ci/woodpecker/push/go-lint Pipeline was successful
2025-03-13 23:35:00 -05:00
b542711078 notifications: add http service 2025-03-13 23:34:37 -05:00
5 changed files with 18 additions and 13 deletions

View File

@ -0,0 +1,3 @@
kind: Added
body: 'Notifications: http service added'
time: 2025-03-13T23:23:20.130625927-05:00

View File

@ -0,0 +1,3 @@
kind: Changed
body: 'vault: initialize vault before validating config'
time: 2025-03-13T22:48:40.584581357-05:00

View File

@ -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
}

View File

@ -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
},
})

View File

@ -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])
}