[v9.3.x] Plugins: Fix bug with copying grafanaData (#64453)
Plugins: Fix bug with copying grafanaData (#64446)
(cherry picked from commit 39a4634ae9)
Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com>
This commit is contained in:
co-authored by
Stephanie Hingtgen
parent
f7892a41d1
commit
ac56c21aad
@@ -417,10 +417,11 @@ func (s *Service) httpClientOptions(ctx context.Context, ds *datasources.DataSou
|
||||
if ds.JsonData != nil {
|
||||
opts.CustomOptions = ds.JsonData.MustMap()
|
||||
// allow the plugin sdk to get the json data in JSONDataFromHTTPClientOptions
|
||||
opts.CustomOptions["grafanaData"] = make(map[string]interface{})
|
||||
deepJsonDataCopy := make(map[string]interface{}, len(opts.CustomOptions))
|
||||
for k, v := range opts.CustomOptions {
|
||||
opts.CustomOptions[k] = v
|
||||
deepJsonDataCopy[k] = v
|
||||
}
|
||||
opts.CustomOptions["grafanaData"] = deepJsonDataCopy
|
||||
}
|
||||
if ds.BasicAuth {
|
||||
password, err := s.DecryptedBasicAuthPassword(ctx, ds)
|
||||
|
||||
@@ -363,6 +363,10 @@ func TestService_GetHttpTransport(t *testing.T) {
|
||||
require.NotNil(t, rt)
|
||||
tr := configuredTransport
|
||||
|
||||
opts, err := dsService.httpClientOptions(context.Background(), &ds)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, ds.JsonData.MustMap()["grafanaData"], opts.CustomOptions["grafanaData"])
|
||||
|
||||
// make sure we can still marshal the JsonData after httpClientOptions (avoid cycles)
|
||||
_, err = ds.JsonData.MarshalJSON()
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user