From 1cd7ce24c7653fe8ecca5d9a79ab65b4bab381d0 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Wed, 18 Mar 2020 08:11:14 +0100 Subject: [PATCH] Stackdriver: Fix GCE auth bug when creating new data source (#22836) * Fix test datasource for gce auth * Cache gce default project locally * Await gce default project call * Remove reload functionality * Fix build problem --- .../datasource/stackdriver/config_ctrl.ts | 20 +-------------- .../datasource/stackdriver/datasource.ts | 2 ++ .../stackdriver/partials/config.html | 25 +------------------ 3 files changed, 4 insertions(+), 43 deletions(-) diff --git a/public/app/plugins/datasource/stackdriver/config_ctrl.ts b/public/app/plugins/datasource/stackdriver/config_ctrl.ts index 347b2161c48..f7732ad1394 100644 --- a/public/app/plugins/datasource/stackdriver/config_ctrl.ts +++ b/public/app/plugins/datasource/stackdriver/config_ctrl.ts @@ -1,6 +1,4 @@ import DatasourceSrv from 'app/features/plugins/datasource_srv'; -import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; -import StackdriverDatasource from './datasource'; import { AuthType, authTypes } from './types'; export interface JWT { @@ -21,10 +19,9 @@ export class StackdriverConfigCtrl { authenticationTypes: Array<{ key: AuthType; value: string }>; defaultAuthenticationType: string; name: string; - gceError: string; /** @ngInject */ - constructor(datasourceSrv: DatasourceSrv, private $scope: any) { + constructor(datasourceSrv: DatasourceSrv) { this.defaultAuthenticationType = AuthType.JWT; this.datasourceSrv = datasourceSrv; this.name = this.meta.name; @@ -98,19 +95,4 @@ export class StackdriverConfigCtrl { this.current.secureJsonData = {}; this.current.secureJsonFields = {}; } - - async loadGCEDefaultAccount() { - this.gceError = ''; - const ds = (await getDatasourceSrv().loadDatasource(this.name)) as StackdriverDatasource; - try { - const defaultProject = await ds.getGCEDefaultProject(); - this.$scope.$apply(() => { - this.current.jsonData.gceDefaultProject = defaultProject; - }); - } catch (error) { - this.$scope.$apply(() => { - this.gceError = error; - }); - } - } } diff --git a/public/app/plugins/datasource/stackdriver/datasource.ts b/public/app/plugins/datasource/stackdriver/datasource.ts index 670d31bd05c..e8ccd26ff40 100644 --- a/public/app/plugins/datasource/stackdriver/datasource.ts +++ b/public/app/plugins/datasource/stackdriver/datasource.ts @@ -22,6 +22,7 @@ export default class StackdriverDatasource extends DataSourceApi; metricTypesCache: { [key: string]: MetricDescriptor[] }; + gceDefaultProject: string; /** @ngInject */ constructor( @@ -229,6 +230,7 @@ export default class StackdriverDatasource extends DataSourceApi - -
@@ -146,20 +133,10 @@ Do not forget to save your changes after uploading a file.

-

- Before saving, load the Project name that is associated with the default service account -

-
{{ctrl.gceError}}
-

+

Verify GCE default service account by clicking Save & Test