From e8f1d6db44d44d2bed0358fada5791068073661a Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Thu, 9 Dec 2021 10:44:16 +0000 Subject: [PATCH] Store 'alertmanager_configuration' as JSON string instead of raw bytes (#42443) (#42602) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 5183cc4dc4b4e7d17f6a9e6e359d6f0556b9afd5) Co-authored-by: Joan López de la Franca Beltran <5459617+joanlopez@users.noreply.github.com> --- .../commands/secretsmigrations/reencrypt_secrets.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/grafana-cli/commands/secretsmigrations/reencrypt_secrets.go b/pkg/cmd/grafana-cli/commands/secretsmigrations/reencrypt_secrets.go index 9d07cf97f13..020eccfa864 100644 --- a/pkg/cmd/grafana-cli/commands/secretsmigrations/reencrypt_secrets.go +++ b/pkg/cmd/grafana-cli/commands/secretsmigrations/reencrypt_secrets.go @@ -123,7 +123,7 @@ type alertingSecret struct{} func (s alertingSecret) reencrypt(secretsSrv *manager.SecretsService, sess *xorm.Session) error { var results []struct { Id int - AlertmanagerConfiguration []byte + AlertmanagerConfiguration string } selectSQL := "SELECT id, alertmanager_configuration FROM alert_configuration" @@ -133,7 +133,7 @@ func (s alertingSecret) reencrypt(secretsSrv *manager.SecretsService, sess *xorm for _, result := range results { result := result - postableUserConfig, err := notifier.Load(result.AlertmanagerConfiguration) + postableUserConfig, err := notifier.Load([]byte(result.AlertmanagerConfiguration)) if err != nil { return err } @@ -161,11 +161,12 @@ func (s alertingSecret) reencrypt(secretsSrv *manager.SecretsService, sess *xorm } } - result.AlertmanagerConfiguration, err = json.Marshal(postableUserConfig) + marshalled, err := json.Marshal(postableUserConfig) if err != nil { return err } + result.AlertmanagerConfiguration = string(marshalled) if _, err := sess.Table("alert_configuration").Where("id = ?", result.Id).Update(&result); err != nil { return err }