Alerting: Check for nil model.Settings and models.SecureSettings (#37738)
This commit is contained in:
@@ -22,7 +22,9 @@ func NewAlertmanagerNotifier(model *NotificationChannelConfig, _ *template.Templ
|
|||||||
if model.Settings == nil {
|
if model.Settings == nil {
|
||||||
return nil, receiverInitError{Reason: "no settings supplied"}
|
return nil, receiverInitError{Reason: "no settings supplied"}
|
||||||
}
|
}
|
||||||
|
if model.SecureSettings == nil {
|
||||||
|
return nil, receiverInitError{Cfg: *model, Reason: "no secure settings supplied"}
|
||||||
|
}
|
||||||
urlStr := model.Settings.Get("url").MustString()
|
urlStr := model.Settings.Get("url").MustString()
|
||||||
if urlStr == "" {
|
if urlStr == "" {
|
||||||
return nil, receiverInitError{Reason: "could not find url property in settings", Cfg: *model}
|
return nil, receiverInitError{Reason: "could not find url property in settings", Cfg: *model}
|
||||||
|
|||||||
@@ -49,11 +49,13 @@ func TestNewAlertmanagerNotifier(t *testing.T) {
|
|||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
secureSettings := make(map[string][]byte)
|
||||||
|
|
||||||
m := &NotificationChannelConfig{
|
m := &NotificationChannelConfig{
|
||||||
Name: c.receiverName,
|
Name: c.receiverName,
|
||||||
Type: "alertmanager",
|
Type: "alertmanager",
|
||||||
Settings: settingsJSON,
|
Settings: settingsJSON,
|
||||||
|
SecureSettings: secureSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
||||||
@@ -130,11 +132,13 @@ func TestAlertmanagerNotifier_Notify(t *testing.T) {
|
|||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
secureSettings := make(map[string][]byte)
|
||||||
|
|
||||||
m := &NotificationChannelConfig{
|
m := &NotificationChannelConfig{
|
||||||
Name: c.receiverName,
|
Name: c.receiverName,
|
||||||
Type: "alertmanager",
|
Type: "alertmanager",
|
||||||
Settings: settingsJSON,
|
Settings: settingsJSON,
|
||||||
|
SecureSettings: secureSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const defaultDingdingMsgType = "link"
|
|||||||
// NewDingDingNotifier is the constructor for the Dingding notifier
|
// NewDingDingNotifier is the constructor for the Dingding notifier
|
||||||
func NewDingDingNotifier(model *NotificationChannelConfig, t *template.Template) (*DingDingNotifier, error) {
|
func NewDingDingNotifier(model *NotificationChannelConfig, t *template.Template) (*DingDingNotifier, error) {
|
||||||
if model.Settings == nil {
|
if model.Settings == nil {
|
||||||
return nil, receiverInitError{Reason: "no settings supplied", Cfg: *model}
|
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
||||||
}
|
}
|
||||||
|
|
||||||
url := model.Settings.Get("url").MustString()
|
url := model.Settings.Get("url").MustString()
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ type DiscordNotifier struct {
|
|||||||
|
|
||||||
func NewDiscordNotifier(model *NotificationChannelConfig, t *template.Template) (*DiscordNotifier, error) {
|
func NewDiscordNotifier(model *NotificationChannelConfig, t *template.Template) (*DiscordNotifier, error) {
|
||||||
if model.Settings == nil {
|
if model.Settings == nil {
|
||||||
return nil, receiverInitError{Reason: "no settings supplied", Cfg: *model}
|
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
||||||
}
|
}
|
||||||
|
|
||||||
avatarURL := model.Settings.Get("avatar_url").MustString()
|
avatarURL := model.Settings.Get("avatar_url").MustString()
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ type EmailNotifier struct {
|
|||||||
// for the EmailNotifier.
|
// for the EmailNotifier.
|
||||||
func NewEmailNotifier(model *NotificationChannelConfig, t *template.Template) (*EmailNotifier, error) {
|
func NewEmailNotifier(model *NotificationChannelConfig, t *template.Template) (*EmailNotifier, error) {
|
||||||
if model.Settings == nil {
|
if model.Settings == nil {
|
||||||
return nil, receiverInitError{Reason: "no settings supplied", Cfg: *model}
|
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
||||||
}
|
}
|
||||||
|
|
||||||
addressesString := model.Settings.Get("addresses").MustString()
|
addressesString := model.Settings.Get("addresses").MustString()
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ type GoogleChatNotifier struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewGoogleChatNotifier(model *NotificationChannelConfig, t *template.Template) (*GoogleChatNotifier, error) {
|
func NewGoogleChatNotifier(model *NotificationChannelConfig, t *template.Template) (*GoogleChatNotifier, error) {
|
||||||
|
if model.Settings == nil {
|
||||||
|
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
||||||
|
}
|
||||||
|
|
||||||
url := model.Settings.Get("url").MustString()
|
url := model.Settings.Get("url").MustString()
|
||||||
if url == "" {
|
if url == "" {
|
||||||
return nil, receiverInitError{Cfg: *model, Reason: "could not find url property in settings"}
|
return nil, receiverInitError{Cfg: *model, Reason: "could not find url property in settings"}
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ type KafkaNotifier struct {
|
|||||||
|
|
||||||
// NewKafkaNotifier is the constructor function for the Kafka notifier.
|
// NewKafkaNotifier is the constructor function for the Kafka notifier.
|
||||||
func NewKafkaNotifier(model *NotificationChannelConfig, t *template.Template) (*KafkaNotifier, error) {
|
func NewKafkaNotifier(model *NotificationChannelConfig, t *template.Template) (*KafkaNotifier, error) {
|
||||||
|
if model.Settings == nil {
|
||||||
|
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
||||||
|
}
|
||||||
|
|
||||||
endpoint := model.Settings.Get("kafkaRestProxy").MustString()
|
endpoint := model.Settings.Get("kafkaRestProxy").MustString()
|
||||||
if endpoint == "" {
|
if endpoint == "" {
|
||||||
return nil, receiverInitError{Cfg: *model, Reason: "could not find kafka rest proxy endpoint property in settings"}
|
return nil, receiverInitError{Cfg: *model, Reason: "could not find kafka rest proxy endpoint property in settings"}
|
||||||
|
|||||||
@@ -19,6 +19,13 @@ var (
|
|||||||
|
|
||||||
// NewLineNotifier is the constructor for the LINE notifier
|
// NewLineNotifier is the constructor for the LINE notifier
|
||||||
func NewLineNotifier(model *NotificationChannelConfig, t *template.Template, fn GetDecryptedValueFn) (*LineNotifier, error) {
|
func NewLineNotifier(model *NotificationChannelConfig, t *template.Template, fn GetDecryptedValueFn) (*LineNotifier, error) {
|
||||||
|
if model.Settings == nil {
|
||||||
|
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
||||||
|
}
|
||||||
|
if model.SecureSettings == nil {
|
||||||
|
return nil, receiverInitError{Cfg: *model, Reason: "no secure settings supplied"}
|
||||||
|
}
|
||||||
|
|
||||||
token := fn(context.Background(), model.SecureSettings, "token", model.Settings.Get("token").MustString())
|
token := fn(context.Background(), model.SecureSettings, "token", model.Settings.Get("token").MustString())
|
||||||
if token == "" {
|
if token == "" {
|
||||||
return nil, receiverInitError{Cfg: *model, Reason: "could not find token in settings"}
|
return nil, receiverInitError{Cfg: *model, Reason: "could not find token in settings"}
|
||||||
|
|||||||
@@ -83,11 +83,13 @@ func TestLineNotifier(t *testing.T) {
|
|||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
secureSettings := make(map[string][]byte)
|
||||||
|
|
||||||
m := &NotificationChannelConfig{
|
m := &NotificationChannelConfig{
|
||||||
Name: "line_testing",
|
Name: "line_testing",
|
||||||
Type: "line",
|
Type: "line",
|
||||||
Settings: settingsJSON,
|
Settings: settingsJSON,
|
||||||
|
SecureSettings: secureSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
||||||
|
|||||||
@@ -42,6 +42,12 @@ type OpsgenieNotifier struct {
|
|||||||
|
|
||||||
// NewOpsgenieNotifier is the constructor for the Opsgenie notifier
|
// NewOpsgenieNotifier is the constructor for the Opsgenie notifier
|
||||||
func NewOpsgenieNotifier(model *NotificationChannelConfig, t *template.Template, fn GetDecryptedValueFn) (*OpsgenieNotifier, error) {
|
func NewOpsgenieNotifier(model *NotificationChannelConfig, t *template.Template, fn GetDecryptedValueFn) (*OpsgenieNotifier, error) {
|
||||||
|
if model.Settings == nil {
|
||||||
|
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
||||||
|
}
|
||||||
|
if model.SecureSettings == nil {
|
||||||
|
return nil, receiverInitError{Cfg: *model, Reason: "no secure settings supplied"}
|
||||||
|
}
|
||||||
autoClose := model.Settings.Get("autoClose").MustBool(true)
|
autoClose := model.Settings.Get("autoClose").MustBool(true)
|
||||||
overridePriority := model.Settings.Get("overridePriority").MustBool(true)
|
overridePriority := model.Settings.Get("overridePriority").MustBool(true)
|
||||||
apiKey := fn(context.Background(), model.SecureSettings, "apiKey", model.Settings.Get("apiKey").MustString())
|
apiKey := fn(context.Background(), model.SecureSettings, "apiKey", model.Settings.Get("apiKey").MustString())
|
||||||
|
|||||||
@@ -163,11 +163,13 @@ func TestOpsgenieNotifier(t *testing.T) {
|
|||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
secureSettings := make(map[string][]byte)
|
||||||
|
|
||||||
m := &NotificationChannelConfig{
|
m := &NotificationChannelConfig{
|
||||||
Name: "opsgenie_testing",
|
Name: "opsgenie_testing",
|
||||||
Type: "opsgenie",
|
Type: "opsgenie",
|
||||||
Settings: settingsJSON,
|
Settings: settingsJSON,
|
||||||
|
SecureSettings: secureSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ func NewPagerdutyNotifier(model *NotificationChannelConfig, t *template.Template
|
|||||||
if model.Settings == nil {
|
if model.Settings == nil {
|
||||||
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
||||||
}
|
}
|
||||||
|
if model.SecureSettings == nil {
|
||||||
|
return nil, receiverInitError{Cfg: *model, Reason: "no secure settings supplied"}
|
||||||
|
}
|
||||||
|
|
||||||
key := fn(context.Background(), model.SecureSettings, "integrationKey", model.Settings.Get("integrationKey").MustString())
|
key := fn(context.Background(), model.SecureSettings, "integrationKey", model.Settings.Get("integrationKey").MustString())
|
||||||
if key == "" {
|
if key == "" {
|
||||||
|
|||||||
@@ -129,11 +129,13 @@ func TestPagerdutyNotifier(t *testing.T) {
|
|||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
secureSettings := make(map[string][]byte)
|
||||||
|
|
||||||
m := &NotificationChannelConfig{
|
m := &NotificationChannelConfig{
|
||||||
Name: "pageduty_testing",
|
Name: "pageduty_testing",
|
||||||
Type: "pagerduty",
|
Type: "pagerduty",
|
||||||
Settings: settingsJSON,
|
Settings: settingsJSON,
|
||||||
|
SecureSettings: secureSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ func NewPushoverNotifier(model *NotificationChannelConfig, t *template.Template,
|
|||||||
if model.Settings == nil {
|
if model.Settings == nil {
|
||||||
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
||||||
}
|
}
|
||||||
|
if model.SecureSettings == nil {
|
||||||
|
return nil, receiverInitError{Cfg: *model, Reason: "no secure settings supplied"}
|
||||||
|
}
|
||||||
|
|
||||||
userKey := fn(context.Background(), model.SecureSettings, "userKey", model.Settings.Get("userKey").MustString())
|
userKey := fn(context.Background(), model.SecureSettings, "userKey", model.Settings.Get("userKey").MustString())
|
||||||
APIToken := fn(context.Background(), model.SecureSettings, "apiToken", model.Settings.Get("apiToken").MustString())
|
APIToken := fn(context.Background(), model.SecureSettings, "apiToken", model.Settings.Get("apiToken").MustString())
|
||||||
|
|||||||
@@ -137,11 +137,13 @@ func TestPushoverNotifier(t *testing.T) {
|
|||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
secureSettings := make(map[string][]byte)
|
||||||
|
|
||||||
m := &NotificationChannelConfig{
|
m := &NotificationChannelConfig{
|
||||||
Name: "pushover_testing",
|
Name: "pushover_testing",
|
||||||
Type: "pushover",
|
Type: "pushover",
|
||||||
Settings: settingsJSON,
|
Settings: settingsJSON,
|
||||||
|
SecureSettings: secureSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ func NewSensuGoNotifier(model *NotificationChannelConfig, t *template.Template,
|
|||||||
if model.Settings == nil {
|
if model.Settings == nil {
|
||||||
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
||||||
}
|
}
|
||||||
|
if model.SecureSettings == nil {
|
||||||
|
return nil, receiverInitError{Cfg: *model, Reason: "no secure settings supplied"}
|
||||||
|
}
|
||||||
url := model.Settings.Get("url").MustString()
|
url := model.Settings.Get("url").MustString()
|
||||||
if url == "" {
|
if url == "" {
|
||||||
return nil, receiverInitError{Cfg: *model, Reason: "could not find URL property in settings"}
|
return nil, receiverInitError{Cfg: *model, Reason: "could not find URL property in settings"}
|
||||||
|
|||||||
@@ -134,11 +134,13 @@ func TestSensuGoNotifier(t *testing.T) {
|
|||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
secureSettings := make(map[string][]byte)
|
||||||
|
|
||||||
m := &NotificationChannelConfig{
|
m := &NotificationChannelConfig{
|
||||||
Name: "Sensu Go",
|
Name: "Sensu Go",
|
||||||
Type: "sensugo",
|
Type: "sensugo",
|
||||||
Settings: settingsJSON,
|
Settings: settingsJSON,
|
||||||
|
SecureSettings: secureSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ func NewSlackNotifier(model *NotificationChannelConfig, t *template.Template, fn
|
|||||||
if model.Settings == nil {
|
if model.Settings == nil {
|
||||||
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
||||||
}
|
}
|
||||||
|
if model.SecureSettings == nil {
|
||||||
|
return nil, receiverInitError{Cfg: *model, Reason: "no secure settings supplied"}
|
||||||
|
}
|
||||||
|
|
||||||
slackURL := fn(context.Background(), model.SecureSettings, "url", model.Settings.Get("url").MustString())
|
slackURL := fn(context.Background(), model.SecureSettings, "url", model.Settings.Get("url").MustString())
|
||||||
if slackURL == "" {
|
if slackURL == "" {
|
||||||
|
|||||||
@@ -165,11 +165,13 @@ func TestSlackNotifier(t *testing.T) {
|
|||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
secureSettings := make(map[string][]byte)
|
||||||
|
|
||||||
m := &NotificationChannelConfig{
|
m := &NotificationChannelConfig{
|
||||||
Name: "slack_testing",
|
Name: "slack_testing",
|
||||||
Type: "slack",
|
Type: "slack",
|
||||||
Settings: settingsJSON,
|
Settings: settingsJSON,
|
||||||
|
SecureSettings: secureSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ func NewTelegramNotifier(model *NotificationChannelConfig, t *template.Template,
|
|||||||
if model.Settings == nil {
|
if model.Settings == nil {
|
||||||
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
||||||
}
|
}
|
||||||
|
if model.SecureSettings == nil {
|
||||||
|
return nil, receiverInitError{Cfg: *model, Reason: "no secure settings supplied"}
|
||||||
|
}
|
||||||
|
|
||||||
botToken := fn(context.Background(), model.SecureSettings, "bottoken", model.Settings.Get("bottoken").MustString())
|
botToken := fn(context.Background(), model.SecureSettings, "bottoken", model.Settings.Get("bottoken").MustString())
|
||||||
chatID := model.Settings.Get("chatid").MustString()
|
chatID := model.Settings.Get("chatid").MustString()
|
||||||
|
|||||||
@@ -89,11 +89,13 @@ func TestTelegramNotifier(t *testing.T) {
|
|||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
secureSettings := make(map[string][]byte)
|
||||||
|
|
||||||
m := &NotificationChannelConfig{
|
m := &NotificationChannelConfig{
|
||||||
Name: "telegram_testing",
|
Name: "telegram_testing",
|
||||||
Type: "telegram",
|
Type: "telegram",
|
||||||
Settings: settingsJSON,
|
Settings: settingsJSON,
|
||||||
|
SecureSettings: secureSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ func NewThreemaNotifier(model *NotificationChannelConfig, t *template.Template,
|
|||||||
if model.Settings == nil {
|
if model.Settings == nil {
|
||||||
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
||||||
}
|
}
|
||||||
|
if model.SecureSettings == nil {
|
||||||
|
return nil, receiverInitError{Cfg: *model, Reason: "no secure settings supplied"}
|
||||||
|
}
|
||||||
gatewayID := model.Settings.Get("gateway_id").MustString()
|
gatewayID := model.Settings.Get("gateway_id").MustString()
|
||||||
recipientID := model.Settings.Get("recipient_id").MustString()
|
recipientID := model.Settings.Get("recipient_id").MustString()
|
||||||
apiSecret := fn(context.Background(), model.SecureSettings, "api_secret", model.Settings.Get("api_secret").MustString())
|
apiSecret := fn(context.Background(), model.SecureSettings, "api_secret", model.Settings.Get("api_secret").MustString())
|
||||||
|
|||||||
@@ -101,11 +101,13 @@ func TestThreemaNotifier(t *testing.T) {
|
|||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
secureSettings := make(map[string][]byte)
|
||||||
|
|
||||||
m := &NotificationChannelConfig{
|
m := &NotificationChannelConfig{
|
||||||
Name: "threema_testing",
|
Name: "threema_testing",
|
||||||
Type: "threema",
|
Type: "threema",
|
||||||
Settings: settingsJSON,
|
Settings: settingsJSON,
|
||||||
|
SecureSettings: secureSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ const (
|
|||||||
// NewVictoropsNotifier creates an instance of VictoropsNotifier that
|
// NewVictoropsNotifier creates an instance of VictoropsNotifier that
|
||||||
// handles posting notifications to Victorops REST API
|
// handles posting notifications to Victorops REST API
|
||||||
func NewVictoropsNotifier(model *NotificationChannelConfig, t *template.Template) (*VictoropsNotifier, error) {
|
func NewVictoropsNotifier(model *NotificationChannelConfig, t *template.Template) (*VictoropsNotifier, error) {
|
||||||
|
if model.Settings == nil {
|
||||||
|
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
||||||
|
}
|
||||||
|
|
||||||
url := model.Settings.Get("url").MustString()
|
url := model.Settings.Get("url").MustString()
|
||||||
if url == "" {
|
if url == "" {
|
||||||
return nil, receiverInitError{Cfg: *model, Reason: "could not find victorops url property in settings"}
|
return nil, receiverInitError{Cfg: *model, Reason: "could not find victorops url property in settings"}
|
||||||
|
|||||||
@@ -31,7 +31,10 @@ type WebhookNotifier struct {
|
|||||||
// the WebHook notifier.
|
// the WebHook notifier.
|
||||||
func NewWebHookNotifier(model *NotificationChannelConfig, t *template.Template, fn GetDecryptedValueFn) (*WebhookNotifier, error) {
|
func NewWebHookNotifier(model *NotificationChannelConfig, t *template.Template, fn GetDecryptedValueFn) (*WebhookNotifier, error) {
|
||||||
if model.Settings == nil {
|
if model.Settings == nil {
|
||||||
return nil, receiverInitError{Cfg: *model, Reason: "could not find settings property"}
|
return nil, receiverInitError{Cfg: *model, Reason: "no settings supplied"}
|
||||||
|
}
|
||||||
|
if model.SecureSettings == nil {
|
||||||
|
return nil, receiverInitError{Cfg: *model, Reason: "no secure settings supplied"}
|
||||||
}
|
}
|
||||||
url := model.Settings.Get("url").MustString()
|
url := model.Settings.Get("url").MustString()
|
||||||
if url == "" {
|
if url == "" {
|
||||||
|
|||||||
@@ -182,12 +182,14 @@ func TestWebhookNotifier(t *testing.T) {
|
|||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
settingsJSON, err := simplejson.NewJson([]byte(c.settings))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
secureSettings := make(map[string][]byte)
|
||||||
|
|
||||||
m := &NotificationChannelConfig{
|
m := &NotificationChannelConfig{
|
||||||
Name: "webhook_testing",
|
OrgID: orgID,
|
||||||
Type: "webhook",
|
Name: "webhook_testing",
|
||||||
Settings: settingsJSON,
|
Type: "webhook",
|
||||||
OrgID: orgID,
|
Settings: settingsJSON,
|
||||||
|
SecureSettings: secureSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
secretsService := secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore())
|
||||||
|
|||||||
Reference in New Issue
Block a user