[v10.4.x] Chore: Update grafana-plugin-sdk (#85087)

* Chore: Update grafana-plugin-sdk (#84289)

(cherry picked from commit 265200799d)

* Re-generate openapi

---------

Co-authored-by: Andres Martinez Gotor <andres.martinez@grafana.com>
Co-authored-by: Giuseppe Guerra <giuseppe@guerra.in>
This commit is contained in:
Will Browne
2024-03-25 21:27:55 +02:00
committed by GitHub
co-authored by Andres Martinez Gotor Giuseppe Guerra
parent 6a8944a76e
commit e1fc1e9a13
14 changed files with 139 additions and 107 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ type DataSourceService interface {
// CustomHeaders returns a map of custom headers the user might have
// configured for this Datasource. Not every datasource can has the option
// to configure those.
CustomHeaders(ctx context.Context, ds *DataSource) (map[string]string, error)
CustomHeaders(ctx context.Context, ds *DataSource) (http.Header, error)
}
// CacheService interface for retrieving a cached datasource.
@@ -134,6 +134,6 @@ func (s *FakeDataSourceService) DecryptedPassword(ctx context.Context, ds *datas
return "", nil
}
func (s *FakeDataSourceService) CustomHeaders(ctx context.Context, ds *datasources.DataSource) (map[string]string, error) {
func (s *FakeDataSourceService) CustomHeaders(ctx context.Context, ds *datasources.DataSource) (http.Header, error) {
return nil, nil
}
@@ -484,7 +484,7 @@ func (s *Service) httpClientOptions(ctx context.Context, ds *datasources.DataSou
opts := &sdkhttpclient.Options{
Timeouts: timeouts,
Headers: s.getCustomHeaders(ds.JsonData, decryptedValues),
Header: s.getCustomHeaders(ds.JsonData, decryptedValues),
Labels: map[string]string{
"datasource_type": ds.Type,
"datasource_name": ds.Name,
@@ -654,8 +654,8 @@ func (s *Service) getTimeout(ds *datasources.DataSource) time.Duration {
// getCustomHeaders returns a map with all the to be set headers
// The map key represents the HeaderName and the value represents this header's value
func (s *Service) getCustomHeaders(jsonData *simplejson.Json, decryptedValues map[string]string) map[string]string {
headers := make(map[string]string)
func (s *Service) getCustomHeaders(jsonData *simplejson.Json, decryptedValues map[string]string) http.Header {
headers := make(http.Header)
if jsonData == nil {
return headers
}
@@ -680,7 +680,7 @@ func (s *Service) getCustomHeaders(jsonData *simplejson.Json, decryptedValues ma
}
if val, ok := decryptedValues[headerValueSuffix]; ok {
headers[key] = val
headers.Add(key, val)
}
}
@@ -769,7 +769,7 @@ func readQuotaConfig(cfg *setting.Cfg) (*quota.Map, error) {
}
// CustomerHeaders returns the custom headers specified in the datasource. The context is used for the decryption operation that might use the store, so consider setting an acceptable timeout for your use case.
func (s *Service) CustomHeaders(ctx context.Context, ds *datasources.DataSource) (map[string]string, error) {
func (s *Service) CustomHeaders(ctx context.Context, ds *datasources.DataSource) (http.Header, error) {
values, err := s.SecretsService.DecryptJsonData(ctx, ds.SecureJsonData)
if err != nil {
return nil, fmt.Errorf("failed to get custom headers: %w", err)
@@ -833,7 +833,7 @@ func TestService_GetHttpTransport(t *testing.T) {
require.NoError(t, err)
headers := dsService.getCustomHeaders(sjson, map[string]string{"httpHeaderValue1": "Bearer xf5yhfkpsnmgo"})
require.Equal(t, "Bearer xf5yhfkpsnmgo", headers["Authorization"])
require.Equal(t, "Bearer xf5yhfkpsnmgo", headers.Get("Authorization"))
// 1. Start HTTP test server which checks the request headers
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -902,7 +902,7 @@ func TestService_GetHttpTransport(t *testing.T) {
require.NoError(t, err)
headers := dsService.getCustomHeaders(sjson, map[string]string{"httpHeaderValue1": "example.com"})
require.Equal(t, "example.com", headers["Host"])
require.Equal(t, "example.com", headers.Get("Host"))
// 1. Start HTTP test server which checks the request headers
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -1192,7 +1192,7 @@ func TestDataSource_CustomHeaders(t *testing.T) {
name string
jsonData *simplejson.Json
secureJsonData map[string][]byte
expectedHeaders map[string]string
expectedHeaders http.Header
expectedErrorMsg string
}{
{
@@ -1203,8 +1203,8 @@ func TestDataSource_CustomHeaders(t *testing.T) {
secureJsonData: map[string][]byte{
"httpHeaderValue1": encryptedValue,
},
expectedHeaders: map[string]string{
"X-Test-Header1": testValue,
expectedHeaders: http.Header{
"X-Test-Header1": []string{testValue},
},
},
{
@@ -1213,7 +1213,7 @@ func TestDataSource_CustomHeaders(t *testing.T) {
"httpHeaderName1": "X-Test-Header1",
}),
secureJsonData: map[string][]byte{},
expectedHeaders: map[string]string{},
expectedHeaders: http.Header{},
},
{
name: "non customer header value",
@@ -1221,7 +1221,21 @@ func TestDataSource_CustomHeaders(t *testing.T) {
"someotherheader": "X-Test-Header1",
}),
secureJsonData: map[string][]byte{},
expectedHeaders: map[string]string{},
expectedHeaders: http.Header{},
},
{
name: "add multiple header value",
jsonData: simplejson.NewFromAny(map[string]any{
"httpHeaderName1": "X-Test-Header1",
"httpHeaderName2": "X-Test-Header1",
}),
secureJsonData: map[string][]byte{
"httpHeaderValue1": encryptedValue,
"httpHeaderValue2": encryptedValue,
},
expectedHeaders: http.Header{
"X-Test-Header1": []string{testValue, testValue},
},
},
}