From aff1de9892d253c6612610d65e55498249e1b23d Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Wed, 5 Sep 2018 18:04:51 +0200 Subject: [PATCH] Adds skeleton for loading projects from google resource manager --- .../datasource/stackdriver/config_ctrl.ts | 18 ++++++++++++++++++ .../datasource/stackdriver/datasource.ts | 3 ++- .../stackdriver/partials/config.html | 10 ++++++++++ .../plugins/datasource/stackdriver/plugin.json | 12 ++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/stackdriver/config_ctrl.ts b/public/app/plugins/datasource/stackdriver/config_ctrl.ts index 95f10ec1986..a919a0fba77 100644 --- a/public/app/plugins/datasource/stackdriver/config_ctrl.ts +++ b/public/app/plugins/datasource/stackdriver/config_ctrl.ts @@ -5,12 +5,16 @@ export class StackdriverConfigCtrl { jsonText: string; validationErrors: string[] = []; inputDataValid: boolean; + defaultProject: string; + projects: string[]; + loadingProjects: boolean; /** @ngInject */ constructor($scope, datasourceSrv) { this.datasourceSrv = datasourceSrv; this.current.jsonData = this.current.jsonData || {}; this.current.secureJsonData = this.current.secureJsonData || {}; + this.projects = []; } save(jwt) { @@ -45,6 +49,7 @@ export class StackdriverConfigCtrl { this.jsonText = ''; if (this.validateJwt(json)) { this.save(json); + this.displayProjects(); } } @@ -53,6 +58,7 @@ export class StackdriverConfigCtrl { const json = JSON.parse(e.originalEvent.clipboardData.getData('text/plain') || this.jsonText); if (this.validateJwt(json)) { this.save(json); + this.displayProjects(); } } catch (error) { this.resetValidationMessages(); @@ -65,4 +71,16 @@ export class StackdriverConfigCtrl { this.inputDataValid = false; this.jsonText = ''; } + + async displayProjects() { + if (this.projects.length === 0) { + this.loadingProjects = true; + const ds = await this.datasourceSrv.loadDatasource(this.current.name); + try { + this.projects = await ds.doRequest(`/cloudresourcemanager/v1/projects`); + } catch (error) { + console.log(error); + } + } + } } diff --git a/public/app/plugins/datasource/stackdriver/datasource.ts b/public/app/plugins/datasource/stackdriver/datasource.ts index 016b9c2e9d3..5b5838990cc 100644 --- a/public/app/plugins/datasource/stackdriver/datasource.ts +++ b/public/app/plugins/datasource/stackdriver/datasource.ts @@ -6,6 +6,7 @@ export default class StackdriverDatasource { constructor(instanceSettings, private backendSrv) { this.baseUrl = `/stackdriver/`; this.url = instanceSettings.url; + this.doRequest = this.doRequest; } testDatasource() { @@ -15,7 +16,7 @@ export default class StackdriverDatasource { if (response.status === 200) { return { status: 'success', - message: 'Successfully queried the Azure Monitor service.', + message: 'Successfully queried the Stackdriver API.', title: 'Success', }; } diff --git a/public/app/plugins/datasource/stackdriver/partials/config.html b/public/app/plugins/datasource/stackdriver/partials/config.html index c7933a4e3e1..46bd7a3d6af 100644 --- a/public/app/plugins/datasource/stackdriver/partials/config.html +++ b/public/app/plugins/datasource/stackdriver/partials/config.html @@ -11,6 +11,16 @@
+
+ Default Projects +
+ +
+
+ + Fetching history list… +
+
{{valError}} diff --git a/public/app/plugins/datasource/stackdriver/plugin.json b/public/app/plugins/datasource/stackdriver/plugin.json index d2a482bae5b..e2cdfb63814 100644 --- a/public/app/plugins/datasource/stackdriver/plugin.json +++ b/public/app/plugins/datasource/stackdriver/plugin.json @@ -25,6 +25,18 @@ "private_key": "{{.SecureJsonData.privateKey}}" } } + }, + { + "path": "cloudresourcemanager", + "method": "GET", + "url": "https://cloudresourcemanager.googleapis.com", + "jwtTokenAuth": { + "params": { + "token_uri": "{{.JsonData.tokenUri}}", + "client_email": "{{.JsonData.clientEmail}}", + "private_key": "{{.SecureJsonData.privateKey}}" + } + } } ] } \ No newline at end of file