mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudMonitoring: Update sdks to latest (#65252)
* Upgrade grafana-google-sdk-go to v0.1.0 * Upgrade @grafana/google-sdk to 0.1.1 * Update doc with provisioning example * Remove unused types * Use config types from the sdk * Add metrics
This commit is contained in:
@@ -131,7 +131,7 @@ type Service struct {
|
||||
resourceHandler backend.CallResourceHandler
|
||||
|
||||
// mocked in tests
|
||||
gceDefaultProjectGetter func(ctx context.Context) (string, error)
|
||||
gceDefaultProjectGetter func(ctx context.Context, scope string) (string, error)
|
||||
}
|
||||
|
||||
type datasourceInfo struct {
|
||||
@@ -143,8 +143,7 @@ type datasourceInfo struct {
|
||||
clientEmail string
|
||||
tokenUri string
|
||||
services map[string]datasourceService
|
||||
|
||||
decryptedSecureJSONData map[string]string
|
||||
privateKey string
|
||||
}
|
||||
|
||||
type datasourceJSONData struct {
|
||||
@@ -172,15 +171,19 @@ func newInstanceSettings(httpClientProvider httpclient.Provider) datasource.Inst
|
||||
}
|
||||
|
||||
dsInfo := &datasourceInfo{
|
||||
id: settings.ID,
|
||||
updated: settings.Updated,
|
||||
url: settings.URL,
|
||||
authenticationType: jsonData.AuthenticationType,
|
||||
defaultProject: jsonData.DefaultProject,
|
||||
clientEmail: jsonData.ClientEmail,
|
||||
tokenUri: jsonData.TokenURI,
|
||||
decryptedSecureJSONData: settings.DecryptedSecureJSONData,
|
||||
services: map[string]datasourceService{},
|
||||
id: settings.ID,
|
||||
updated: settings.Updated,
|
||||
url: settings.URL,
|
||||
authenticationType: jsonData.AuthenticationType,
|
||||
defaultProject: jsonData.DefaultProject,
|
||||
clientEmail: jsonData.ClientEmail,
|
||||
tokenUri: jsonData.TokenURI,
|
||||
services: map[string]datasourceService{},
|
||||
}
|
||||
|
||||
dsInfo.privateKey, err = utils.GetPrivateKey(&settings)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
opts, err := settings.HTTPClientOptions()
|
||||
@@ -571,7 +574,7 @@ func (s *Service) ensureProject(ctx context.Context, dsInfo datasourceInfo, proj
|
||||
|
||||
func (s *Service) getDefaultProject(ctx context.Context, dsInfo datasourceInfo) (string, error) {
|
||||
if dsInfo.authenticationType == gceAuthentication {
|
||||
return s.gceDefaultProjectGetter(ctx)
|
||||
return s.gceDefaultProjectGetter(ctx, cloudMonitorScope)
|
||||
}
|
||||
return dsInfo.defaultProject, nil
|
||||
}
|
||||
|
||||
@@ -1150,7 +1150,7 @@ func TestCheckHealth(t *testing.T) {
|
||||
})
|
||||
service := &Service{
|
||||
im: im,
|
||||
gceDefaultProjectGetter: func(ctx context.Context) (string, error) {
|
||||
gceDefaultProjectGetter: func(ctx context.Context, scope string) (string, error) {
|
||||
return "", fmt.Errorf("not found!")
|
||||
},
|
||||
}
|
||||
|
||||
@@ -9,8 +9,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
cloudMonitor = "cloudmonitoring"
|
||||
resourceManager = "cloudresourcemanager"
|
||||
cloudMonitor = "cloudmonitoring"
|
||||
resourceManager = "cloudresourcemanager"
|
||||
cloudMonitorScope = "https://www.googleapis.com/auth/monitoring.read"
|
||||
resourceManagerScope = "https://www.googleapis.com/auth/cloudplatformprojects.readonly"
|
||||
)
|
||||
|
||||
type routeInfo struct {
|
||||
@@ -23,12 +25,12 @@ var routes = map[string]routeInfo{
|
||||
cloudMonitor: {
|
||||
method: "GET",
|
||||
url: "https://monitoring.googleapis.com",
|
||||
scopes: []string{"https://www.googleapis.com/auth/monitoring.read"},
|
||||
scopes: []string{cloudMonitorScope},
|
||||
},
|
||||
resourceManager: {
|
||||
method: "GET",
|
||||
url: "https://cloudresourcemanager.googleapis.com",
|
||||
scopes: []string{"https://www.googleapis.com/auth/cloudplatformprojects.readonly"},
|
||||
scopes: []string{resourceManagerScope},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -49,7 +51,7 @@ func getMiddleware(model *datasourceInfo, routePath string) (httpclient.Middlewa
|
||||
providerConfig.JwtTokenConfig = &tokenprovider.JwtTokenConfig{
|
||||
Email: model.clientEmail,
|
||||
URI: model.tokenUri,
|
||||
PrivateKey: []byte(model.decryptedSecureJSONData["privateKey"]),
|
||||
PrivateKey: []byte(model.privateKey),
|
||||
}
|
||||
provider = tokenprovider.NewJwtAccessTokenProvider(providerConfig)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func (s *Service) newResourceMux() *http.ServeMux {
|
||||
}
|
||||
|
||||
func (s *Service) getGCEDefaultProject(rw http.ResponseWriter, req *http.Request) {
|
||||
project, err := s.gceDefaultProjectGetter(req.Context())
|
||||
project, err := s.gceDefaultProjectGetter(req.Context(), resourceManagerScope)
|
||||
if err != nil {
|
||||
writeResponse(rw, http.StatusBadRequest, fmt.Sprintf("unexpected error %v", err))
|
||||
return
|
||||
|
||||
@@ -300,7 +300,7 @@ func Test_getGCEDefaultProject(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
gceDefaultProjectGetter: func(ctx context.Context) (string, error) {
|
||||
gceDefaultProjectGetter: func(ctx context.Context, scope string) (string, error) {
|
||||
return project, nil
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user