Provisioning: Support alert notification channel secure settings (#26168)

Closes #25968
pull/26407/head
Marcus Efraimsson 5 years ago committed by GitHub
parent 8746a77407
commit 7969d6645a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      pkg/services/provisioning/notifiers/alert_notifications.go
  2. 2
      pkg/services/provisioning/notifiers/config_reader.go
  3. 3
      pkg/services/provisioning/notifiers/config_reader_test.go
  4. 3
      pkg/services/provisioning/notifiers/testdata/test-configs/correct-properties/correct-properties.yaml
  5. 3
      pkg/services/provisioning/notifiers/types.go

@ -94,6 +94,7 @@ func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*not
Type: notification.Type, Type: notification.Type,
IsDefault: notification.IsDefault, IsDefault: notification.IsDefault,
Settings: notification.SettingsToJSON(), Settings: notification.SettingsToJSON(),
SecureSettings: notification.SecureSettings,
OrgId: notification.OrgID, OrgId: notification.OrgID,
DisableResolveMessage: notification.DisableResolveMessage, DisableResolveMessage: notification.DisableResolveMessage,
Frequency: notification.Frequency, Frequency: notification.Frequency,
@ -111,6 +112,7 @@ func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*not
Type: notification.Type, Type: notification.Type,
IsDefault: notification.IsDefault, IsDefault: notification.IsDefault,
Settings: notification.SettingsToJSON(), Settings: notification.SettingsToJSON(),
SecureSettings: notification.SecureSettings,
OrgId: notification.OrgID, OrgId: notification.OrgID,
DisableResolveMessage: notification.DisableResolveMessage, DisableResolveMessage: notification.DisableResolveMessage,
Frequency: notification.Frequency, Frequency: notification.Frequency,

@ -7,6 +7,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/grafana/grafana/pkg/components/securejsondata"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/alerting"
@ -149,6 +150,7 @@ func validateNotifications(notifications []*notificationsAsConfig) error {
_, err := alerting.InitNotifier(&models.AlertNotification{ _, err := alerting.InitNotifier(&models.AlertNotification{
Name: notification.Name, Name: notification.Name,
Settings: notification.SettingsToJSON(), Settings: notification.SettingsToJSON(),
SecureSettings: securejsondata.GetEncryptedJsonData(notification.SecureSettings),
Type: notification.Type, Type: notification.Type,
}) })

@ -66,6 +66,9 @@ func TestNotificationAsConfig(t *testing.T) {
So(nt.Settings, ShouldResemble, map[string]interface{}{ So(nt.Settings, ShouldResemble, map[string]interface{}{
"recipient": "XXX", "token": "xoxb", "uploadImage": true, "url": "https://slack.com", "recipient": "XXX", "token": "xoxb", "uploadImage": true, "url": "https://slack.com",
}) })
So(nt.SecureSettings, ShouldResemble, map[string]string{
"token": "xoxbsecure", "url": "https://slack.com/secure",
})
So(nt.SendReminder, ShouldBeTrue) So(nt.SendReminder, ShouldBeTrue)
So(nt.Frequency, ShouldEqual, "1h") So(nt.Frequency, ShouldEqual, "1h")

@ -11,6 +11,9 @@ notifiers:
token: "xoxb" token: "xoxb"
uploadImage: true uploadImage: true
url: https://slack.com url: https://slack.com
secure_settings:
url: https://slack.com/secure
token: "xoxbsecure"
- name: another-not-default-notification - name: another-not-default-notification
type: email type: email
settings: settings:

@ -30,6 +30,7 @@ type notificationFromConfig struct {
Frequency string Frequency string
IsDefault bool IsDefault bool
Settings map[string]interface{} Settings map[string]interface{}
SecureSettings map[string]string
} }
// notificationsAsConfigV0 is mapping for zero version configs. This is mapped to its normalised version. // notificationsAsConfigV0 is mapping for zero version configs. This is mapped to its normalised version.
@ -56,6 +57,7 @@ type notificationFromConfigV0 struct {
Frequency values.StringValue `json:"frequency" yaml:"frequency"` Frequency values.StringValue `json:"frequency" yaml:"frequency"`
IsDefault values.BoolValue `json:"is_default" yaml:"is_default"` IsDefault values.BoolValue `json:"is_default" yaml:"is_default"`
Settings values.JSONValue `json:"settings" yaml:"settings"` Settings values.JSONValue `json:"settings" yaml:"settings"`
SecureSettings values.StringMapValue `json:"secure_settings" yaml:"secure_settings"`
} }
func (notification notificationFromConfig) SettingsToJSON() *simplejson.Json { func (notification notificationFromConfig) SettingsToJSON() *simplejson.Json {
@ -88,6 +90,7 @@ func (cfg *notificationsAsConfigV0) mapToNotificationFromConfig() *notifications
DisableResolveMessage: notification.DisableResolveMessage.Value(), DisableResolveMessage: notification.DisableResolveMessage.Value(),
Frequency: notification.Frequency.Value(), Frequency: notification.Frequency.Value(),
SendReminder: notification.SendReminder.Value(), SendReminder: notification.SendReminder.Value(),
SecureSettings: notification.SecureSettings.Value(),
}) })
} }

Loading…
Cancel
Save