Commit db8d7ffb by Carl Bergquist Committed by GitHub

Linting fixes for the provisioning package (#25690)

parent 891ae24f
...@@ -835,6 +835,8 @@ jobs: ...@@ -835,6 +835,8 @@ jobs:
./pkg/services/alerting/... \ ./pkg/services/alerting/... \
./pkg/services/provisioning/datasources/... \ ./pkg/services/provisioning/datasources/... \
./pkg/services/provisioning/dashboards/... \ ./pkg/services/provisioning/dashboards/... \
./pkg/services/provisioning/notifiers/... \
./pkg/services/provisioning/values/... \
./pkg/plugins/backendplugin/... ./pkg/plugins/backendplugin/...
test-frontend: test-frontend:
......
...@@ -90,6 +90,8 @@ revive-strict: scripts/go/bin/revive ...@@ -90,6 +90,8 @@ revive-strict: scripts/go/bin/revive
./pkg/services/alerting/... \ ./pkg/services/alerting/... \
./pkg/services/provisioning/datasources/... \ ./pkg/services/provisioning/datasources/... \
./pkg/services/provisioning/dashboards/... \ ./pkg/services/provisioning/dashboards/... \
./pkg/services/provisioning/notifiers/... \
./pkg/services/provisioning/values/... \
./pkg/plugins/backendplugin/... ./pkg/plugins/backendplugin/...
scripts/go/bin/golangci-lint: scripts/go/go.mod scripts/go/bin/golangci-lint: scripts/go/go.mod
......
package notifiers package notifiers
import ( import (
"errors"
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"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"
) )
var ( // Provision alert notifiers
ErrInvalidConfigTooManyDefault = errors.New("Alert notification provisioning config is invalid. Only one alert notification can be marked as default")
)
func Provision(configDirectory string) error { func Provision(configDirectory string) error {
dc := newNotificationProvisioner(log.New("provisioning.notifiers")) dc := newNotificationProvisioner(log.New("provisioning.notifiers"))
return dc.applyChanges(configDirectory) return dc.applyChanges(configDirectory)
} }
// NotificationProvisioner is responsible for provsioning alert notifiers
type NotificationProvisioner struct { type NotificationProvisioner struct {
log log.Logger log log.Logger
cfgProvider *configReader cfgProvider *configReader
...@@ -43,19 +39,19 @@ func (dc *NotificationProvisioner) apply(cfg *notificationsAsConfig) error { ...@@ -43,19 +39,19 @@ func (dc *NotificationProvisioner) apply(cfg *notificationsAsConfig) error {
func (dc *NotificationProvisioner) deleteNotifications(notificationToDelete []*deleteNotificationConfig) error { func (dc *NotificationProvisioner) deleteNotifications(notificationToDelete []*deleteNotificationConfig) error {
for _, notification := range notificationToDelete { for _, notification := range notificationToDelete {
dc.log.Info("Deleting alert notification", "name", notification.Name, "uid", notification.Uid) dc.log.Info("Deleting alert notification", "name", notification.Name, "uid", notification.UID)
if notification.OrgId == 0 && notification.OrgName != "" { if notification.OrgID == 0 && notification.OrgName != "" {
getOrg := &models.GetOrgByNameQuery{Name: notification.OrgName} getOrg := &models.GetOrgByNameQuery{Name: notification.OrgName}
if err := bus.Dispatch(getOrg); err != nil { if err := bus.Dispatch(getOrg); err != nil {
return err return err
} }
notification.OrgId = getOrg.Result.Id notification.OrgID = getOrg.Result.Id
} else if notification.OrgId < 0 { } else if notification.OrgID < 0 {
notification.OrgId = 1 notification.OrgID = 1
} }
getNotification := &models.GetAlertNotificationsWithUidQuery{Uid: notification.Uid, OrgId: notification.OrgId} getNotification := &models.GetAlertNotificationsWithUidQuery{Uid: notification.UID, OrgId: notification.OrgID}
if err := bus.Dispatch(getNotification); err != nil { if err := bus.Dispatch(getNotification); err != nil {
return err return err
...@@ -75,31 +71,31 @@ func (dc *NotificationProvisioner) deleteNotifications(notificationToDelete []*d ...@@ -75,31 +71,31 @@ func (dc *NotificationProvisioner) deleteNotifications(notificationToDelete []*d
func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*notificationFromConfig) error { func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*notificationFromConfig) error {
for _, notification := range notificationToMerge { for _, notification := range notificationToMerge {
if notification.OrgId == 0 && notification.OrgName != "" { if notification.OrgID == 0 && notification.OrgName != "" {
getOrg := &models.GetOrgByNameQuery{Name: notification.OrgName} getOrg := &models.GetOrgByNameQuery{Name: notification.OrgName}
if err := bus.Dispatch(getOrg); err != nil { if err := bus.Dispatch(getOrg); err != nil {
return err return err
} }
notification.OrgId = getOrg.Result.Id notification.OrgID = getOrg.Result.Id
} else if notification.OrgId < 0 { } else if notification.OrgID < 0 {
notification.OrgId = 1 notification.OrgID = 1
} }
cmd := &models.GetAlertNotificationsWithUidQuery{OrgId: notification.OrgId, Uid: notification.Uid} cmd := &models.GetAlertNotificationsWithUidQuery{OrgId: notification.OrgID, Uid: notification.UID}
err := bus.Dispatch(cmd) err := bus.Dispatch(cmd)
if err != nil { if err != nil {
return err return err
} }
if cmd.Result == nil { if cmd.Result == nil {
dc.log.Debug("inserting alert notification from configuration", "name", notification.Name, "uid", notification.Uid) dc.log.Debug("inserting alert notification from configuration", "name", notification.Name, "uid", notification.UID)
insertCmd := &models.CreateAlertNotificationCommand{ insertCmd := &models.CreateAlertNotificationCommand{
Uid: notification.Uid, Uid: notification.UID,
Name: notification.Name, Name: notification.Name,
Type: notification.Type, Type: notification.Type,
IsDefault: notification.IsDefault, IsDefault: notification.IsDefault,
Settings: notification.SettingsToJson(), Settings: notification.SettingsToJSON(),
OrgId: notification.OrgId, OrgId: notification.OrgID,
DisableResolveMessage: notification.DisableResolveMessage, DisableResolveMessage: notification.DisableResolveMessage,
Frequency: notification.Frequency, Frequency: notification.Frequency,
SendReminder: notification.SendReminder, SendReminder: notification.SendReminder,
...@@ -111,12 +107,12 @@ func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*not ...@@ -111,12 +107,12 @@ func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*not
} else { } else {
dc.log.Debug("updating alert notification from configuration", "name", notification.Name) dc.log.Debug("updating alert notification from configuration", "name", notification.Name)
updateCmd := &models.UpdateAlertNotificationWithUidCommand{ updateCmd := &models.UpdateAlertNotificationWithUidCommand{
Uid: notification.Uid, Uid: notification.UID,
Name: notification.Name, Name: notification.Name,
Type: notification.Type, Type: notification.Type,
IsDefault: notification.IsDefault, IsDefault: notification.IsDefault,
Settings: notification.SettingsToJson(), Settings: notification.SettingsToJSON(),
OrgId: notification.OrgId, OrgId: notification.OrgID,
DisableResolveMessage: notification.DisableResolveMessage, DisableResolveMessage: notification.DisableResolveMessage,
Frequency: notification.Frequency, Frequency: notification.Frequency,
SendReminder: notification.SendReminder, SendReminder: notification.SendReminder,
......
...@@ -46,7 +46,7 @@ func (cr *configReader) readConfig(path string) ([]*notificationsAsConfig, error ...@@ -46,7 +46,7 @@ func (cr *configReader) readConfig(path string) ([]*notificationsAsConfig, error
return nil, err return nil, err
} }
checkOrgIdAndOrgName(notifications) checkOrgIDAndOrgName(notifications)
err = validateNotifications(notifications) err = validateNotifications(notifications)
if err != nil { if err != nil {
...@@ -72,24 +72,24 @@ func (cr *configReader) parseNotificationConfig(path string, file os.FileInfo) ( ...@@ -72,24 +72,24 @@ func (cr *configReader) parseNotificationConfig(path string, file os.FileInfo) (
return cfg.mapToNotificationFromConfig(), nil return cfg.mapToNotificationFromConfig(), nil
} }
func checkOrgIdAndOrgName(notifications []*notificationsAsConfig) { func checkOrgIDAndOrgName(notifications []*notificationsAsConfig) {
for i := range notifications { for i := range notifications {
for _, notification := range notifications[i].Notifications { for _, notification := range notifications[i].Notifications {
if notification.OrgId < 1 { if notification.OrgID < 1 {
if notification.OrgName == "" { if notification.OrgName == "" {
notification.OrgId = 1 notification.OrgID = 1
} else { } else {
notification.OrgId = 0 notification.OrgID = 0
} }
} }
} }
for _, notification := range notifications[i].DeleteNotifications { for _, notification := range notifications[i].DeleteNotifications {
if notification.OrgId < 1 { if notification.OrgID < 1 {
if notification.OrgName == "" { if notification.OrgName == "" {
notification.OrgId = 1 notification.OrgID = 1
} else { } else {
notification.OrgId = 0 notification.OrgID = 0
} }
} }
} }
...@@ -107,7 +107,7 @@ func validateRequiredField(notifications []*notificationsAsConfig) error { ...@@ -107,7 +107,7 @@ func validateRequiredField(notifications []*notificationsAsConfig) error {
) )
} }
if notification.Uid == "" { if notification.UID == "" {
errStrings = append( errStrings = append(
errStrings, errStrings,
fmt.Sprintf("Added alert notification item %d in configuration doesn't contain required field uid", index+1), fmt.Sprintf("Added alert notification item %d in configuration doesn't contain required field uid", index+1),
...@@ -123,7 +123,7 @@ func validateRequiredField(notifications []*notificationsAsConfig) error { ...@@ -123,7 +123,7 @@ func validateRequiredField(notifications []*notificationsAsConfig) error {
) )
} }
if notification.Uid == "" { if notification.UID == "" {
errStrings = append( errStrings = append(
errStrings, errStrings,
fmt.Sprintf("Deleted alert notification item %d in configuration doesn't contain required field uid", index+1), fmt.Sprintf("Deleted alert notification item %d in configuration doesn't contain required field uid", index+1),
...@@ -149,7 +149,7 @@ func validateNotifications(notifications []*notificationsAsConfig) error { ...@@ -149,7 +149,7 @@ func validateNotifications(notifications []*notificationsAsConfig) error {
for _, notification := range notifications[i].Notifications { for _, notification := range notifications[i].Notifications {
_, err := alerting.InitNotifier(&models.AlertNotification{ _, err := alerting.InitNotifier(&models.AlertNotification{
Name: notification.Name, Name: notification.Name,
Settings: notification.SettingsToJson(), Settings: notification.SettingsToJSON(),
Type: notification.Type, Type: notification.Type,
}) })
......
...@@ -13,16 +13,16 @@ import ( ...@@ -13,16 +13,16 @@ import (
) )
var ( var (
correct_properties = "./testdata/test-configs/correct-properties" correctProperties = "./testdata/test-configs/correct-properties"
incorrect_settings = "./testdata/test-configs/incorrect-settings" incorrectSettings = "./testdata/test-configs/incorrect-settings"
no_required_fields = "./testdata/test-configs/no-required-fields" noRequiredFields = "./testdata/test-configs/no-required-fields"
correct_properties_with_orgName = "./testdata/test-configs/correct-properties-with-orgName" correctPropertiesWithOrgName = "./testdata/test-configs/correct-properties-with-orgName"
brokenYaml = "./testdata/test-configs/broken-yaml" brokenYaml = "./testdata/test-configs/broken-yaml"
doubleNotificationsConfig = "./testdata/test-configs/double-default" doubleNotificationsConfig = "./testdata/test-configs/double-default"
emptyFolder = "./testdata/test-configs/empty_folder" emptyFolder = "./testdata/test-configs/empty_folder"
emptyFile = "./testdata/test-configs/empty" emptyFile = "./testdata/test-configs/empty"
twoNotificationsConfig = "./testdata/test-configs/two-notifications" twoNotificationsConfig = "./testdata/test-configs/two-notifications"
unknownNotifier = "./testdata/test-configs/unknown-notifier" unknownNotifier = "./testdata/test-configs/unknown-notifier"
) )
func TestNotificationAsConfig(t *testing.T) { func TestNotificationAsConfig(t *testing.T) {
...@@ -46,7 +46,7 @@ func TestNotificationAsConfig(t *testing.T) { ...@@ -46,7 +46,7 @@ func TestNotificationAsConfig(t *testing.T) {
Convey("Can read correct properties", func() { Convey("Can read correct properties", func() {
_ = os.Setenv("TEST_VAR", "default") _ = os.Setenv("TEST_VAR", "default")
cfgProvider := &configReader{log: log.New("test logger")} cfgProvider := &configReader{log: log.New("test logger")}
cfg, err := cfgProvider.readConfig(correct_properties) cfg, err := cfgProvider.readConfig(correctProperties)
_ = os.Unsetenv("TEST_VAR") _ = os.Unsetenv("TEST_VAR")
if err != nil { if err != nil {
t.Fatalf("readConfig return an error %v", err) t.Fatalf("readConfig return an error %v", err)
...@@ -60,8 +60,8 @@ func TestNotificationAsConfig(t *testing.T) { ...@@ -60,8 +60,8 @@ func TestNotificationAsConfig(t *testing.T) {
nt := nts[0] nt := nts[0]
So(nt.Name, ShouldEqual, "default-slack-notification") So(nt.Name, ShouldEqual, "default-slack-notification")
So(nt.Type, ShouldEqual, "slack") So(nt.Type, ShouldEqual, "slack")
So(nt.OrgId, ShouldEqual, 2) So(nt.OrgID, ShouldEqual, 2)
So(nt.Uid, ShouldEqual, "notifier1") So(nt.UID, ShouldEqual, "notifier1")
So(nt.IsDefault, ShouldBeTrue) So(nt.IsDefault, ShouldBeTrue)
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",
...@@ -72,45 +72,45 @@ func TestNotificationAsConfig(t *testing.T) { ...@@ -72,45 +72,45 @@ func TestNotificationAsConfig(t *testing.T) {
nt = nts[1] nt = nts[1]
So(nt.Name, ShouldEqual, "another-not-default-notification") So(nt.Name, ShouldEqual, "another-not-default-notification")
So(nt.Type, ShouldEqual, "email") So(nt.Type, ShouldEqual, "email")
So(nt.OrgId, ShouldEqual, 3) So(nt.OrgID, ShouldEqual, 3)
So(nt.Uid, ShouldEqual, "notifier2") So(nt.UID, ShouldEqual, "notifier2")
So(nt.IsDefault, ShouldBeFalse) So(nt.IsDefault, ShouldBeFalse)
nt = nts[2] nt = nts[2]
So(nt.Name, ShouldEqual, "check-unset-is_default-is-false") So(nt.Name, ShouldEqual, "check-unset-is_default-is-false")
So(nt.Type, ShouldEqual, "slack") So(nt.Type, ShouldEqual, "slack")
So(nt.OrgId, ShouldEqual, 3) So(nt.OrgID, ShouldEqual, 3)
So(nt.Uid, ShouldEqual, "notifier3") So(nt.UID, ShouldEqual, "notifier3")
So(nt.IsDefault, ShouldBeFalse) So(nt.IsDefault, ShouldBeFalse)
nt = nts[3] nt = nts[3]
So(nt.Name, ShouldEqual, "Added notification with whitespaces in name") So(nt.Name, ShouldEqual, "Added notification with whitespaces in name")
So(nt.Type, ShouldEqual, "email") So(nt.Type, ShouldEqual, "email")
So(nt.Uid, ShouldEqual, "notifier4") So(nt.UID, ShouldEqual, "notifier4")
So(nt.OrgId, ShouldEqual, 3) So(nt.OrgID, ShouldEqual, 3)
deleteNts := ntCfg.DeleteNotifications deleteNts := ntCfg.DeleteNotifications
So(len(deleteNts), ShouldEqual, 4) So(len(deleteNts), ShouldEqual, 4)
deleteNt := deleteNts[0] deleteNt := deleteNts[0]
So(deleteNt.Name, ShouldEqual, "default-slack-notification") So(deleteNt.Name, ShouldEqual, "default-slack-notification")
So(deleteNt.Uid, ShouldEqual, "notifier1") So(deleteNt.UID, ShouldEqual, "notifier1")
So(deleteNt.OrgId, ShouldEqual, 2) So(deleteNt.OrgID, ShouldEqual, 2)
deleteNt = deleteNts[1] deleteNt = deleteNts[1]
So(deleteNt.Name, ShouldEqual, "deleted-notification-without-orgId") So(deleteNt.Name, ShouldEqual, "deleted-notification-without-orgId")
So(deleteNt.OrgId, ShouldEqual, 1) So(deleteNt.OrgID, ShouldEqual, 1)
So(deleteNt.Uid, ShouldEqual, "notifier2") So(deleteNt.UID, ShouldEqual, "notifier2")
deleteNt = deleteNts[2] deleteNt = deleteNts[2]
So(deleteNt.Name, ShouldEqual, "deleted-notification-with-0-orgId") So(deleteNt.Name, ShouldEqual, "deleted-notification-with-0-orgId")
So(deleteNt.OrgId, ShouldEqual, 1) So(deleteNt.OrgID, ShouldEqual, 1)
So(deleteNt.Uid, ShouldEqual, "notifier3") So(deleteNt.UID, ShouldEqual, "notifier3")
deleteNt = deleteNts[3] deleteNt = deleteNts[3]
So(deleteNt.Name, ShouldEqual, "Deleted notification with whitespaces in name") So(deleteNt.Name, ShouldEqual, "Deleted notification with whitespaces in name")
So(deleteNt.OrgId, ShouldEqual, 1) So(deleteNt.OrgID, ShouldEqual, 1)
So(deleteNt.Uid, ShouldEqual, "notifier4") So(deleteNt.UID, ShouldEqual, "notifier4")
}) })
Convey("One configured notification", func() { Convey("One configured notification", func() {
...@@ -243,7 +243,7 @@ func TestNotificationAsConfig(t *testing.T) { ...@@ -243,7 +243,7 @@ func TestNotificationAsConfig(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
dc := newNotificationProvisioner(logger) dc := newNotificationProvisioner(logger)
err = dc.applyChanges(correct_properties_with_orgName) err = dc.applyChanges(correctPropertiesWithOrgName)
if err != nil { if err != nil {
t.Fatalf("applyChanges return an error %v", err) t.Fatalf("applyChanges return an error %v", err)
} }
...@@ -262,7 +262,7 @@ func TestNotificationAsConfig(t *testing.T) { ...@@ -262,7 +262,7 @@ func TestNotificationAsConfig(t *testing.T) {
Convey("Config doesn't contain required field", func() { Convey("Config doesn't contain required field", func() {
dc := newNotificationProvisioner(logger) dc := newNotificationProvisioner(logger)
err := dc.applyChanges(no_required_fields) err := dc.applyChanges(noRequiredFields)
So(err, ShouldNotBeNil) So(err, ShouldNotBeNil)
errString := err.Error() errString := err.Error()
...@@ -310,7 +310,7 @@ func TestNotificationAsConfig(t *testing.T) { ...@@ -310,7 +310,7 @@ func TestNotificationAsConfig(t *testing.T) {
Convey("Read incorrect properties", func() { Convey("Read incorrect properties", func() {
cfgProvider := &configReader{log: log.New("test logger")} cfgProvider := &configReader{log: log.New("test logger")}
_, err := cfgProvider.readConfig(incorrect_settings) _, err := cfgProvider.readConfig(incorrectSettings)
So(err, ShouldNotBeNil) So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "Alert validation error: Could not find url property in settings") So(err.Error(), ShouldEqual, "Alert validation error: Could not find url property in settings")
}) })
......
...@@ -13,15 +13,15 @@ type notificationsAsConfig struct { ...@@ -13,15 +13,15 @@ type notificationsAsConfig struct {
} }
type deleteNotificationConfig struct { type deleteNotificationConfig struct {
Uid string UID string
Name string Name string
OrgId int64 OrgID int64
OrgName string OrgName string
} }
type notificationFromConfig struct { type notificationFromConfig struct {
Uid string UID string
OrgId int64 OrgID int64
OrgName string OrgName string
Name string Name string
Type string Type string
...@@ -39,15 +39,15 @@ type notificationsAsConfigV0 struct { ...@@ -39,15 +39,15 @@ type notificationsAsConfigV0 struct {
} }
type deleteNotificationConfigV0 struct { type deleteNotificationConfigV0 struct {
Uid values.StringValue `json:"uid" yaml:"uid"` UID values.StringValue `json:"uid" yaml:"uid"`
Name values.StringValue `json:"name" yaml:"name"` Name values.StringValue `json:"name" yaml:"name"`
OrgId values.Int64Value `json:"org_id" yaml:"org_id"` OrgID values.Int64Value `json:"org_id" yaml:"org_id"`
OrgName values.StringValue `json:"org_name" yaml:"org_name"` OrgName values.StringValue `json:"org_name" yaml:"org_name"`
} }
type notificationFromConfigV0 struct { type notificationFromConfigV0 struct {
Uid values.StringValue `json:"uid" yaml:"uid"` UID values.StringValue `json:"uid" yaml:"uid"`
OrgId values.Int64Value `json:"org_id" yaml:"org_id"` OrgID values.Int64Value `json:"org_id" yaml:"org_id"`
OrgName values.StringValue `json:"org_name" yaml:"org_name"` OrgName values.StringValue `json:"org_name" yaml:"org_name"`
Name values.StringValue `json:"name" yaml:"name"` Name values.StringValue `json:"name" yaml:"name"`
Type values.StringValue `json:"type" yaml:"type"` Type values.StringValue `json:"type" yaml:"type"`
...@@ -58,7 +58,7 @@ type notificationFromConfigV0 struct { ...@@ -58,7 +58,7 @@ type notificationFromConfigV0 struct {
Settings values.JSONValue `json:"settings" yaml:"settings"` Settings values.JSONValue `json:"settings" yaml:"settings"`
} }
func (notification notificationFromConfig) SettingsToJson() *simplejson.Json { func (notification notificationFromConfig) SettingsToJSON() *simplejson.Json {
settings := simplejson.New() settings := simplejson.New()
if len(notification.Settings) > 0 { if len(notification.Settings) > 0 {
for k, v := range notification.Settings { for k, v := range notification.Settings {
...@@ -78,8 +78,8 @@ func (cfg *notificationsAsConfigV0) mapToNotificationFromConfig() *notifications ...@@ -78,8 +78,8 @@ func (cfg *notificationsAsConfigV0) mapToNotificationFromConfig() *notifications
for _, notification := range cfg.Notifications { for _, notification := range cfg.Notifications {
r.Notifications = append(r.Notifications, &notificationFromConfig{ r.Notifications = append(r.Notifications, &notificationFromConfig{
Uid: notification.Uid.Value(), UID: notification.UID.Value(),
OrgId: notification.OrgId.Value(), OrgID: notification.OrgID.Value(),
OrgName: notification.OrgName.Value(), OrgName: notification.OrgName.Value(),
Name: notification.Name.Value(), Name: notification.Name.Value(),
Type: notification.Type.Value(), Type: notification.Type.Value(),
...@@ -93,8 +93,8 @@ func (cfg *notificationsAsConfigV0) mapToNotificationFromConfig() *notifications ...@@ -93,8 +93,8 @@ func (cfg *notificationsAsConfigV0) mapToNotificationFromConfig() *notifications
for _, notification := range cfg.DeleteNotifications { for _, notification := range cfg.DeleteNotifications {
r.DeleteNotifications = append(r.DeleteNotifications, &deleteNotificationConfig{ r.DeleteNotifications = append(r.DeleteNotifications, &deleteNotificationConfig{
Uid: notification.Uid.Value(), UID: notification.UID.Value(),
OrgId: notification.OrgId.Value(), OrgID: notification.OrgID.Value(),
OrgName: notification.OrgName.Value(), OrgName: notification.OrgName.Value(),
Name: notification.Name.Value(), Name: notification.Name.Value(),
}) })
......
...@@ -22,11 +22,14 @@ import ( ...@@ -22,11 +22,14 @@ import (
"github.com/grafana/grafana/pkg/util/errutil" "github.com/grafana/grafana/pkg/util/errutil"
) )
// IntValue represents a string value in a YAML
// config that can be overridden by environment variables
type IntValue struct { type IntValue struct {
value int value int
Raw string Raw string
} }
// UnmarshalYAML converts YAML into an *IntValue
func (val *IntValue) UnmarshalYAML(unmarshal func(interface{}) error) error { func (val *IntValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
interpolated, err := getInterpolated(unmarshal) interpolated, err := getInterpolated(unmarshal)
if err != nil { if err != nil {
...@@ -41,15 +44,19 @@ func (val *IntValue) UnmarshalYAML(unmarshal func(interface{}) error) error { ...@@ -41,15 +44,19 @@ func (val *IntValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
return errutil.Wrap("cannot convert value int", err) return errutil.Wrap("cannot convert value int", err)
} }
// Value returns the wrapped int value
func (val *IntValue) Value() int { func (val *IntValue) Value() int {
return val.value return val.value
} }
// Int64Value represents a string value in a YAML
// config that can be overridden by environment variables
type Int64Value struct { type Int64Value struct {
value int64 value int64
Raw string Raw string
} }
// UnmarshalYAML converts YAML into an *Int64Value
func (val *Int64Value) UnmarshalYAML(unmarshal func(interface{}) error) error { func (val *Int64Value) UnmarshalYAML(unmarshal func(interface{}) error) error {
interpolated, err := getInterpolated(unmarshal) interpolated, err := getInterpolated(unmarshal)
if err != nil { if err != nil {
...@@ -64,15 +71,19 @@ func (val *Int64Value) UnmarshalYAML(unmarshal func(interface{}) error) error { ...@@ -64,15 +71,19 @@ func (val *Int64Value) UnmarshalYAML(unmarshal func(interface{}) error) error {
return err return err
} }
// Value returns the wrapped int64 value
func (val *Int64Value) Value() int64 { func (val *Int64Value) Value() int64 {
return val.value return val.value
} }
// StringValue represents a string value in a YAML
// config that can be overridden by environment variables
type StringValue struct { type StringValue struct {
value string value string
Raw string Raw string
} }
// UnmarshalYAML converts YAML into an *StringValue
func (val *StringValue) UnmarshalYAML(unmarshal func(interface{}) error) error { func (val *StringValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
interpolated, err := getInterpolated(unmarshal) interpolated, err := getInterpolated(unmarshal)
if err != nil { if err != nil {
...@@ -83,15 +94,19 @@ func (val *StringValue) UnmarshalYAML(unmarshal func(interface{}) error) error { ...@@ -83,15 +94,19 @@ func (val *StringValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
return err return err
} }
// Value returns the wrapped string value
func (val *StringValue) Value() string { func (val *StringValue) Value() string {
return val.value return val.value
} }
// BoolValue represents a string value in a YAML
// config that can be overridden by environment variables
type BoolValue struct { type BoolValue struct {
value bool value bool
Raw string Raw string
} }
// UnmarshalYAML converts YAML into an *BoolValue
func (val *BoolValue) UnmarshalYAML(unmarshal func(interface{}) error) error { func (val *BoolValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
interpolated, err := getInterpolated(unmarshal) interpolated, err := getInterpolated(unmarshal)
if err != nil { if err != nil {
...@@ -102,15 +117,19 @@ func (val *BoolValue) UnmarshalYAML(unmarshal func(interface{}) error) error { ...@@ -102,15 +117,19 @@ func (val *BoolValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
return err return err
} }
// Value returns the wrapped bool value
func (val *BoolValue) Value() bool { func (val *BoolValue) Value() bool {
return val.value return val.value
} }
// JSONValue represents a string value in a YAML
// config that can be overridden by environment variables
type JSONValue struct { type JSONValue struct {
value map[string]interface{} value map[string]interface{}
Raw map[string]interface{} Raw map[string]interface{}
} }
// UnmarshalYAML converts YAML into an *JSONValue
func (val *JSONValue) UnmarshalYAML(unmarshal func(interface{}) error) error { func (val *JSONValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
unmarshaled := make(map[string]interface{}) unmarshaled := make(map[string]interface{})
err := unmarshal(unmarshaled) err := unmarshal(unmarshaled)
...@@ -131,15 +150,19 @@ func (val *JSONValue) UnmarshalYAML(unmarshal func(interface{}) error) error { ...@@ -131,15 +150,19 @@ func (val *JSONValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
return err return err
} }
// Value returns the wrapped JSON value as map[string]interface{}
func (val *JSONValue) Value() map[string]interface{} { func (val *JSONValue) Value() map[string]interface{} {
return val.value return val.value
} }
// StringMapValue represents a string value in a YAML
// config that can be overridden by environment variables
type StringMapValue struct { type StringMapValue struct {
value map[string]string value map[string]string
Raw map[string]string Raw map[string]string
} }
// UnmarshalYAML converts YAML into an *StringMapValue
func (val *StringMapValue) UnmarshalYAML(unmarshal func(interface{}) error) error { func (val *StringMapValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
unmarshaled := make(map[string]string) unmarshaled := make(map[string]string)
err := unmarshal(unmarshaled) err := unmarshal(unmarshaled)
...@@ -159,6 +182,7 @@ func (val *StringMapValue) UnmarshalYAML(unmarshal func(interface{}) error) erro ...@@ -159,6 +182,7 @@ func (val *StringMapValue) UnmarshalYAML(unmarshal func(interface{}) error) erro
return err return err
} }
// Value returns the wrapped map[string]string value
func (val *StringMapValue) Value() map[string]string { func (val *StringMapValue) Value() map[string]string {
return val.value return val.value
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment