diff --git a/go.mod b/go.mod index 62353693670..28901d39b98 100644 --- a/go.mod +++ b/go.mod @@ -65,7 +65,7 @@ require ( github.com/google/go-github/v57 v57.0.0 github.com/google/uuid v1.6.0 github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc - github.com/grafana/alerting v0.0.0-20240926144415-27f4e81b4b6b + github.com/grafana/alerting v0.0.0-20241010165806-807ddf183724 github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc github.com/hashicorp/golang-lru/v2 v2.0.7 github.com/hashicorp/vault/api v1.15.0 diff --git a/go.sum b/go.sum index 44661f9a030..0454f093f4e 100644 --- a/go.sum +++ b/go.sum @@ -1254,8 +1254,8 @@ github.com/gosimple/slug v1.1.1 h1:fRu/digW+NMwBIP+RmviTK97Ho/bEj/C9swrCspN3D4= github.com/gosimple/slug v1.1.1/go.mod h1:ER78kgg1Mv0NQGlXiDe57DpCyfbNywXXZ9mIorhxAf0= github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc h1:PXZQA2WCxe85Tnn+WEvr8fDpfwibmEPgfgFEaC87G24= github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc/go.mod h1:AHHlOEv1+GGQ3ktHMlhuTUwo3zljV3QJbC0+8o2kn+4= -github.com/grafana/alerting v0.0.0-20240926144415-27f4e81b4b6b h1:UO4mv94pG1kzKCgBKh20TXdACBCAK2vYjV3Q2MlcpEQ= -github.com/grafana/alerting v0.0.0-20240926144415-27f4e81b4b6b/go.mod h1:GMLi6d09Xqo96fCVUjNk//rcjP5NKEdjOzfWIffD5r4= +github.com/grafana/alerting v0.0.0-20241010165806-807ddf183724 h1:u+ZM5TLkdeEoSWXgYWxc4XRfPHhXpR63MyHXJxbBLrc= +github.com/grafana/alerting v0.0.0-20241010165806-807ddf183724/go.mod h1:QsnoKX/iYZxA4Cv+H+wC7uxutBD8qi8ZW5UJvD2TYmU= github.com/grafana/dskit v0.0.0-20241013223235-619c42124e93 h1:MgJ51Z/pgKDx9t0UaenBXp4u2Q80yH/yLNvQ5Oe9OQQ= github.com/grafana/dskit v0.0.0-20241013223235-619c42124e93/go.mod h1:SPLNCARd4xdjCkue0O6hvuoveuS1dGJjDnfxYe405YQ= github.com/grafana/e2e v0.1.2-0.20240118170847-db90b84177fc h1:BW+LjKJDz0So5LI8UZfW5neWeKpSkWqhmGjQFzcFfLM= diff --git a/vendor/github.com/grafana/alerting/definition/alertmanager.go b/vendor/github.com/grafana/alerting/definition/alertmanager.go index 7a1efa3d0dd..8631711fe76 100644 --- a/vendor/github.com/grafana/alerting/definition/alertmanager.go +++ b/vendor/github.com/grafana/alerting/definition/alertmanager.go @@ -1,6 +1,7 @@ package definition import ( + "encoding/base64" "encoding/json" "fmt" "reflect" @@ -606,3 +607,22 @@ func (r *PostableApiReceiver) GetName() string { type PostableGrafanaReceivers struct { GrafanaManagedReceivers []*PostableGrafanaReceiver `yaml:"grafana_managed_receiver_configs,omitempty" json:"grafana_managed_receiver_configs,omitempty"` } + +// DecryptSecureSettings returns a map containing the decoded and decrypted secure settings. +func (pgr *PostableGrafanaReceiver) DecryptSecureSettings(decryptFn func(payload []byte) ([]byte, error)) (map[string]string, error) { + decrypted := make(map[string]string, len(pgr.SecureSettings)) + for k, v := range pgr.SecureSettings { + decoded, err := base64.StdEncoding.DecodeString(v) + if err != nil { + return nil, fmt.Errorf("failed to decode value for key '%s': %w", k, err) + } + + b, err := decryptFn(decoded) + if err != nil { + return nil, fmt.Errorf("failed to decrypt value for key '%s': %w", k, err) + } + + decrypted[k] = string(b) + } + return decrypted, nil +} diff --git a/vendor/github.com/grafana/alerting/notify/grafana_alertmanager_metrics.go b/vendor/github.com/grafana/alerting/notify/grafana_alertmanager_metrics.go index 8c1bf6acc6f..73b970d8e82 100644 --- a/vendor/github.com/grafana/alerting/notify/grafana_alertmanager_metrics.go +++ b/vendor/github.com/grafana/alerting/notify/grafana_alertmanager_metrics.go @@ -1,6 +1,7 @@ package notify import ( + "github.com/go-kit/log" "github.com/prometheus/alertmanager/api/metrics" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" @@ -20,10 +21,10 @@ type GrafanaAlertmanagerMetrics struct { } // NewGrafanaAlertmanagerMetrics creates a set of metrics for the Alertmanager. -func NewGrafanaAlertmanagerMetrics(r prometheus.Registerer) *GrafanaAlertmanagerMetrics { +func NewGrafanaAlertmanagerMetrics(r prometheus.Registerer, l log.Logger) *GrafanaAlertmanagerMetrics { return &GrafanaAlertmanagerMetrics{ Registerer: r, - Alerts: metrics.NewAlerts(r), + Alerts: metrics.NewAlerts(r, l), configuredReceivers: promauto.With(r).NewGaugeVec(prometheus.GaugeOpts{ Namespace: namespace, Subsystem: subsystem, diff --git a/vendor/github.com/grafana/alerting/notify/receivers.go b/vendor/github.com/grafana/alerting/notify/receivers.go index 9fdf162c699..09ac3715298 100644 --- a/vendor/github.com/grafana/alerting/notify/receivers.go +++ b/vendor/github.com/grafana/alerting/notify/receivers.go @@ -283,7 +283,7 @@ func parseNotifier(ctx context.Context, result *GrafanaReceiverConfig, receiver } result.EmailConfigs = append(result.EmailConfigs, newNotifierConfig(receiver, cfg)) case "googlechat": - cfg, err := googlechat.NewConfig(receiver.Settings) + cfg, err := googlechat.NewConfig(receiver.Settings, decryptFn) if err != nil { return err } diff --git a/vendor/github.com/grafana/alerting/notify/testing.go b/vendor/github.com/grafana/alerting/notify/testing.go index a200afb7045..d4ccdf7f86c 100644 --- a/vendor/github.com/grafana/alerting/notify/testing.go +++ b/vendor/github.com/grafana/alerting/notify/testing.go @@ -136,7 +136,8 @@ var AllKnownConfigsForTesting = map[string]NotifierConfigTest{ Config: email.FullValidConfigForTesting, }, "googlechat": {NotifierType: "googlechat", - Config: googlechat.FullValidConfigForTesting, + Config: googlechat.FullValidConfigForTesting, + Secrets: googlechat.FullValidSecretsForTesting, }, "kafka": {NotifierType: "kafka", Config: kafka.FullValidConfigForTesting, diff --git a/vendor/github.com/grafana/alerting/receivers/email_sender.go b/vendor/github.com/grafana/alerting/receivers/email_sender.go index a8ecdce28ed..f029e17c0ba 100644 --- a/vendor/github.com/grafana/alerting/receivers/email_sender.go +++ b/vendor/github.com/grafana/alerting/receivers/email_sender.go @@ -43,7 +43,7 @@ type defaultEmailSender struct { // NewEmailSenderFactory takes a configuration and returns a new EmailSender factory function. func NewEmailSenderFactory(cfg EmailSenderConfig) func(Metadata) (EmailSender, error) { - return func(n Metadata) (EmailSender, error) { + return func(_ Metadata) (EmailSender, error) { tmpl, err := template.New("templates"). Funcs(template.FuncMap{ "Subject": subjectTemplateFunc, diff --git a/vendor/github.com/grafana/alerting/receivers/googlechat/config.go b/vendor/github.com/grafana/alerting/receivers/googlechat/config.go index 993a577e7c0..a23ca8d537e 100644 --- a/vendor/github.com/grafana/alerting/receivers/googlechat/config.go +++ b/vendor/github.com/grafana/alerting/receivers/googlechat/config.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" + "github.com/grafana/alerting/receivers" "github.com/grafana/alerting/templates" ) @@ -14,13 +15,14 @@ type Config struct { Message string `json:"message,omitempty" yaml:"message,omitempty"` } -func NewConfig(jsonData json.RawMessage) (Config, error) { +func NewConfig(jsonData json.RawMessage, decryptFn receivers.DecryptFunc) (Config, error) { var settings Config err := json.Unmarshal(jsonData, &settings) if err != nil { return Config{}, fmt.Errorf("failed to unmarshal settings: %w", err) } + settings.URL = decryptFn("url", settings.URL) if settings.URL == "" { return Config{}, errors.New("could not find url property in settings") } diff --git a/vendor/github.com/grafana/alerting/receivers/googlechat/testing.go b/vendor/github.com/grafana/alerting/receivers/googlechat/testing.go index b82663f3d2c..2a078b95caa 100644 --- a/vendor/github.com/grafana/alerting/receivers/googlechat/testing.go +++ b/vendor/github.com/grafana/alerting/receivers/googlechat/testing.go @@ -8,3 +8,8 @@ const FullValidConfigForTesting = `{ "avatar_url" : "http://avatar", "use_discord_username": true }` + +// FullValidSecretsForTesting is a string representation of JSON object that contains all fields that can be overridden from secrets. +const FullValidSecretsForTesting = `{ + "url": "http://localhost/url-secret" +}` diff --git a/vendor/github.com/grafana/alerting/receivers/pushover/pushover.go b/vendor/github.com/grafana/alerting/receivers/pushover/pushover.go index 140963c82ec..6876676fef9 100644 --- a/vendor/github.com/grafana/alerting/receivers/pushover/pushover.go +++ b/vendor/github.com/grafana/alerting/receivers/pushover/pushover.go @@ -215,7 +215,7 @@ func (pn *Notifier) genPushoverBody(ctx context.Context, as ...*types.Alert) (ma func (pn *Notifier) writeImageParts(ctx context.Context, w *multipart.Writer, as ...*types.Alert) { // Pushover supports at most one image attachment with a maximum size of pushoverMaxFileSize. // If the image is larger than pushoverMaxFileSize then return an error. - err := images.WithStoredImages(ctx, pn.log, pn.images, func(index int, image images.Image) error { + err := images.WithStoredImages(ctx, pn.log, pn.images, func(_ int, image images.Image) error { f, err := os.Open(image.Path) if err != nil { return fmt.Errorf("failed to open the image: %w", err) diff --git a/vendor/github.com/grafana/alerting/receivers/slack/slack.go b/vendor/github.com/grafana/alerting/receivers/slack/slack.go index b89e4cd88e6..a90278e31d9 100644 --- a/vendor/github.com/grafana/alerting/receivers/slack/slack.go +++ b/vendor/github.com/grafana/alerting/receivers/slack/slack.go @@ -176,7 +176,7 @@ func (sn *Notifier) Notify(ctx context.Context, alerts ...*types.Alert) (bool, e // sendSlackRequest sends a request to the Slack API. // Stubbable by tests. -var sendSlackRequest = func(ctx context.Context, req *http.Request, logger logging.Logger) (string, error) { +var sendSlackRequest = func(_ context.Context, req *http.Request, logger logging.Logger) (string, error) { resp, err := slackClient.Do(req) if err != nil { return "", fmt.Errorf("failed to send request: %w", err) @@ -344,7 +344,7 @@ func (sn *Notifier) createSlackMessage(ctx context.Context, alerts []*types.Aler if isIncomingWebhook(sn.settings) { // Incoming webhooks cannot upload files, instead share images via their URL - _ = images.WithStoredImages(ctx, sn.log, sn.images, func(index int, image images.Image) error { + _ = images.WithStoredImages(ctx, sn.log, sn.images, func(_ int, image images.Image) error { if image.URL != "" { req.Attachments[0].ImageURL = image.URL return images.ErrImagesDone diff --git a/vendor/github.com/grafana/alerting/receivers/victorops/victorops.go b/vendor/github.com/grafana/alerting/receivers/victorops/victorops.go index 5455118e474..206ee6af762 100644 --- a/vendor/github.com/grafana/alerting/receivers/victorops/victorops.go +++ b/vendor/github.com/grafana/alerting/receivers/victorops/victorops.go @@ -87,7 +87,7 @@ func (vn *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error } _ = images.WithStoredImages(ctx, vn.log, vn.images, - func(index int, image images.Image) error { + func(_ int, image images.Image) error { if image.URL != "" { bodyJSON["image_url"] = image.URL return images.ErrImagesDone diff --git a/vendor/modules.txt b/vendor/modules.txt index 1bce74be227..09e8b2663dd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -577,8 +577,8 @@ github.com/gosimple/slug # github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc ## explicit; go 1.13 github.com/grafana-tools/sdk -# github.com/grafana/alerting v0.0.0-20240926144415-27f4e81b4b6b -## explicit; go 1.21 +# github.com/grafana/alerting v0.0.0-20241010165806-807ddf183724 +## explicit; go 1.22 github.com/grafana/alerting/cluster github.com/grafana/alerting/definition github.com/grafana/alerting/images