From 224aa4dde883b0127ee6a91ba794f8bc9bbd9105 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Tue, 5 May 2020 11:54:50 +0200 Subject: [PATCH] Backend plugins: Fix incorrect JSON Unmarshal (#24243) --- pkg/api/plugins.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/api/plugins.go b/pkg/api/plugins.go index 3262dd16335..00c23585f14 100644 --- a/pkg/api/plugins.go +++ b/pkg/api/plugins.go @@ -29,21 +29,22 @@ func (hs *HTTPServer) getPluginContext(pluginID string, user *models.SignedInUse return pc, ErrPluginNotFound } - var jsonData json.RawMessage - var decryptedSecureJSONData map[string]string + jsonData := json.RawMessage{} + decryptedSecureJSONData := map[string]string{} var updated time.Time ps, err := hs.getCachedPluginSettings(pluginID, user) if err != nil { + // models.ErrPluginSettingNotFound is expected if there's no row found for plugin setting in database (if non-app plugin). + // If it's not this expected error something is wrong with cache or database and we return the error to the client. if err != models.ErrPluginSettingNotFound { return pc, errutil.Wrap("Failed to get plugin settings", err) } + } else { jsonData, err = json.Marshal(ps.JsonData) if err != nil { return pc, errutil.Wrap("Failed to unmarshal plugin json data", err) } - decryptedSecureJSONData = make(map[string]string) - } else { decryptedSecureJSONData = ps.DecryptedValues() updated = ps.Updated }