mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Remove dependency on secrets in definitions package (#65391)
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
|||||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||||
"github.com/grafana/grafana/pkg/services/ngalert/notifier"
|
"github.com/grafana/grafana/pkg/services/ngalert/notifier"
|
||||||
"github.com/grafana/grafana/pkg/services/ngalert/store"
|
"github.com/grafana/grafana/pkg/services/ngalert/store"
|
||||||
|
"github.com/grafana/grafana/pkg/services/secrets"
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -267,7 +268,9 @@ func (srv AlertmanagerSrv) RoutePostTestReceivers(c *contextmodel.ReqContext, bo
|
|||||||
return ErrResp(http.StatusInternalServerError, err, "")
|
return ErrResp(http.StatusInternalServerError, err, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := body.ProcessConfig(srv.crypto.Encrypt); err != nil {
|
if err := body.ProcessConfig(func(ctx context.Context, payload []byte) ([]byte, error) {
|
||||||
|
return srv.crypto.Encrypt(ctx, payload, secrets.WithoutScope())
|
||||||
|
}); err != nil {
|
||||||
return ErrResp(http.StatusInternalServerError, err, "failed to post process Alertmanager configuration")
|
return ErrResp(http.StatusInternalServerError, err, "failed to post process Alertmanager configuration")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import (
|
|||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/secrets"
|
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1177,7 +1176,7 @@ type PostableGrafanaReceivers struct {
|
|||||||
GrafanaManagedReceivers []*PostableGrafanaReceiver `yaml:"grafana_managed_receiver_configs,omitempty" json:"grafana_managed_receiver_configs,omitempty"`
|
GrafanaManagedReceivers []*PostableGrafanaReceiver `yaml:"grafana_managed_receiver_configs,omitempty" json:"grafana_managed_receiver_configs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type EncryptFn func(ctx context.Context, payload []byte, scope secrets.EncryptionOptions) ([]byte, error)
|
type EncryptFn func(ctx context.Context, payload []byte) ([]byte, error)
|
||||||
|
|
||||||
func processReceiverConfigs(c []*PostableApiReceiver, encrypt EncryptFn) error {
|
func processReceiverConfigs(c []*PostableApiReceiver, encrypt EncryptFn) error {
|
||||||
seenUIDs := make(map[string]struct{})
|
seenUIDs := make(map[string]struct{})
|
||||||
@@ -1187,7 +1186,7 @@ func processReceiverConfigs(c []*PostableApiReceiver, encrypt EncryptFn) error {
|
|||||||
case GrafanaReceiverType:
|
case GrafanaReceiverType:
|
||||||
for _, gr := range r.PostableGrafanaReceivers.GrafanaManagedReceivers {
|
for _, gr := range r.PostableGrafanaReceivers.GrafanaManagedReceivers {
|
||||||
for k, v := range gr.SecureSettings {
|
for k, v := range gr.SecureSettings {
|
||||||
encryptedData, err := encrypt(context.Background(), []byte(v), secrets.WithoutScope())
|
encryptedData, err := encrypt(context.Background(), []byte(v))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to encrypt secure settings: %w", err)
|
return fmt.Errorf("failed to encrypt secure settings: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||||
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||||
"github.com/grafana/grafana/pkg/services/ngalert/store"
|
"github.com/grafana/grafana/pkg/services/ngalert/store"
|
||||||
|
"github.com/grafana/grafana/pkg/services/secrets"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UnknownReceiverError struct {
|
type UnknownReceiverError struct {
|
||||||
@@ -103,7 +104,9 @@ func (moa *MultiOrgAlertmanager) ApplyAlertmanagerConfiguration(ctx context.Cont
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := config.ProcessConfig(moa.Crypto.Encrypt); err != nil {
|
if err := config.ProcessConfig(func(ctx context.Context, payload []byte) ([]byte, error) {
|
||||||
|
return moa.Crypto.Encrypt(ctx, payload, secrets.WithoutScope())
|
||||||
|
}); err != nil {
|
||||||
return fmt.Errorf("failed to post process Alertmanager configuration: %w", err)
|
return fmt.Errorf("failed to post process Alertmanager configuration: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user