From 5183cc4dc4b4e7d17f6a9e6e359d6f0556b9afd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= <5459617+joanlopez@users.noreply.github.com> Date: Wed, 1 Dec 2021 17:49:57 +0100 Subject: [PATCH] Store 'alertmanager_configuration' as JSON string instead of raw bytes (#42443) --- .../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 }