Commit aff1de98 by Erik Sundell Committed by Daniel Lee

Adds skeleton for loading projects from google resource manager

parent 68409687
......@@ -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);
}
}
}
}
......@@ -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',
};
}
......
......@@ -11,6 +11,16 @@
<div class="gf-form" ng-if="!ctrl.inputDataValid">
<textarea rows="10" data-share-panel-url="" class="gf-form-input" ng-model="ctrl.jsonText" ng-paste="ctrl.onPasteJwt($event)"></textarea>
</div>
<div class="gf-form" ng-if="ctrl.inputDataValid">
<span class="gf-form-label width-7">Default Projects</span>
<div class="gf-form-select-wrapper max-width-23">
<select class="gf-form-input" ng-model="ctrl.defaultProject" ng-options="p.id as p.name for p in ctrl.projects" ng-change="ctrl.userChangedDefaultProject()"></select>
</div>
<div ng-if="ctrl.loadingProjects">
<i class="fa fa-spinner fa-spin"></i>
<em>Fetching history list&hellip;</em>
</div>
</div>
<div ng-repeat="valError in ctrl.validationErrors" class="text-error p-l-1">
<i class="fa fa-warning"></i>
{{valError}}
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment