mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Azure Monitor: Early error if the client secret is not set (#53106)
This commit is contained in:
parent
245af46798
commit
43955bdebd
@ -266,7 +266,10 @@ func checkAzureMonitorResourceGraphHealth(dsInfo types.DatasourceInfo) (*http.Re
|
|||||||
func (s *Service) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
func (s *Service) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
|
||||||
dsInfo, err := s.getDSInfo(req.PluginContext)
|
dsInfo, err := s.getDSInfo(req.PluginContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return &backend.CheckHealthResult{
|
||||||
|
Status: backend.HealthStatusError,
|
||||||
|
Message: err.Error(),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
status := backend.HealthStatusOk
|
status := backend.HealthStatusOk
|
||||||
|
@ -109,6 +109,9 @@ func getAzureCredentials(cfg *setting.Cfg, jsonData *simplejson.Json, secureJson
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if secureJsonData["clientSecret"] == "" {
|
||||||
|
return nil, fmt.Errorf("unable to instantiate credentials, clientSecret must be set")
|
||||||
|
}
|
||||||
credentials := &azcredentials.AzureClientSecretCredentials{
|
credentials := &azcredentials.AzureClientSecretCredentials{
|
||||||
AzureCloud: cloud,
|
AzureCloud: cloud,
|
||||||
TenantId: jsonData.Get("tenantId").MustString(),
|
TenantId: jsonData.Get("tenantId").MustString(),
|
||||||
|
@ -197,5 +197,13 @@ func TestCredentials_getAzureCredentials(t *testing.T) {
|
|||||||
// Azure Monitor datasource doesn't support custom IdP authorities (Authority is always empty)
|
// Azure Monitor datasource doesn't support custom IdP authorities (Authority is always empty)
|
||||||
assert.Equal(t, "", clientSecretCredentials.Authority)
|
assert.Equal(t, "", clientSecretCredentials.Authority)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("should error if no client secret is set", func(t *testing.T) {
|
||||||
|
cfg := &setting.Cfg{}
|
||||||
|
_, err := getAzureCredentials(cfg, jsonData, map[string]string{
|
||||||
|
"clientSecret": "",
|
||||||
|
})
|
||||||
|
require.ErrorContains(t, err, "clientSecret must be set")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package azuremonitor
|
package azuremonitor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana-azure-sdk-go/azcredentials"
|
||||||
"github.com/grafana/grafana-azure-sdk-go/azhttpclient"
|
"github.com/grafana/grafana-azure-sdk-go/azhttpclient"
|
||||||
sdkhttpclient "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
|
sdkhttpclient "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
|
||||||
|
|
||||||
@ -18,6 +20,9 @@ func newHTTPClient(route types.AzRoute, model types.DatasourceInfo, cfg *setting
|
|||||||
|
|
||||||
// Use Azure credentials if the route has OAuth scopes configured
|
// Use Azure credentials if the route has OAuth scopes configured
|
||||||
if len(route.Scopes) > 0 {
|
if len(route.Scopes) > 0 {
|
||||||
|
if cred, ok := model.Credentials.(*azcredentials.AzureClientSecretCredentials); ok && cred.ClientSecret == "" {
|
||||||
|
return nil, fmt.Errorf("unable to initialize HTTP Client: clientSecret not found")
|
||||||
|
}
|
||||||
azhttpclient.AddAzureAuthentication(&opts, cfg.Azure, model.Credentials, route.Scopes)
|
azhttpclient.AddAzureAuthentication(&opts, cfg.Azure, model.Credentials, route.Scopes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,10 +152,7 @@ export function updateCredentials(
|
|||||||
},
|
},
|
||||||
secureJsonData: {
|
secureJsonData: {
|
||||||
...options.secureJsonData,
|
...options.secureJsonData,
|
||||||
clientSecret:
|
clientSecret: typeof credentials.clientSecret === 'string' ? credentials.clientSecret : undefined,
|
||||||
typeof credentials.clientSecret === 'string' && credentials.clientSecret.length > 0
|
|
||||||
? credentials.clientSecret
|
|
||||||
: undefined,
|
|
||||||
},
|
},
|
||||||
secureJsonFields: {
|
secureJsonFields: {
|
||||||
...options.secureJsonFields,
|
...options.secureJsonFields,
|
||||||
|
Loading…
Reference in New Issue
Block a user