mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Adds skeleton for loading projects from google resource manager
This commit is contained in:
parent
6840968780
commit
aff1de9892
@ -5,12 +5,16 @@ export class StackdriverConfigCtrl {
|
|||||||
jsonText: string;
|
jsonText: string;
|
||||||
validationErrors: string[] = [];
|
validationErrors: string[] = [];
|
||||||
inputDataValid: boolean;
|
inputDataValid: boolean;
|
||||||
|
defaultProject: string;
|
||||||
|
projects: string[];
|
||||||
|
loadingProjects: boolean;
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor($scope, datasourceSrv) {
|
constructor($scope, datasourceSrv) {
|
||||||
this.datasourceSrv = datasourceSrv;
|
this.datasourceSrv = datasourceSrv;
|
||||||
this.current.jsonData = this.current.jsonData || {};
|
this.current.jsonData = this.current.jsonData || {};
|
||||||
this.current.secureJsonData = this.current.secureJsonData || {};
|
this.current.secureJsonData = this.current.secureJsonData || {};
|
||||||
|
this.projects = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
save(jwt) {
|
save(jwt) {
|
||||||
@ -45,6 +49,7 @@ export class StackdriverConfigCtrl {
|
|||||||
this.jsonText = '';
|
this.jsonText = '';
|
||||||
if (this.validateJwt(json)) {
|
if (this.validateJwt(json)) {
|
||||||
this.save(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);
|
const json = JSON.parse(e.originalEvent.clipboardData.getData('text/plain') || this.jsonText);
|
||||||
if (this.validateJwt(json)) {
|
if (this.validateJwt(json)) {
|
||||||
this.save(json);
|
this.save(json);
|
||||||
|
this.displayProjects();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.resetValidationMessages();
|
this.resetValidationMessages();
|
||||||
@ -65,4 +71,16 @@ export class StackdriverConfigCtrl {
|
|||||||
this.inputDataValid = false;
|
this.inputDataValid = false;
|
||||||
this.jsonText = '';
|
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) {
|
constructor(instanceSettings, private backendSrv) {
|
||||||
this.baseUrl = `/stackdriver/`;
|
this.baseUrl = `/stackdriver/`;
|
||||||
this.url = instanceSettings.url;
|
this.url = instanceSettings.url;
|
||||||
|
this.doRequest = this.doRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
testDatasource() {
|
testDatasource() {
|
||||||
@ -15,7 +16,7 @@ export default class StackdriverDatasource {
|
|||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
return {
|
return {
|
||||||
status: 'success',
|
status: 'success',
|
||||||
message: 'Successfully queried the Azure Monitor service.',
|
message: 'Successfully queried the Stackdriver API.',
|
||||||
title: 'Success',
|
title: 'Success',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,16 @@
|
|||||||
<div class="gf-form" ng-if="!ctrl.inputDataValid">
|
<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>
|
<textarea rows="10" data-share-panel-url="" class="gf-form-input" ng-model="ctrl.jsonText" ng-paste="ctrl.onPasteJwt($event)"></textarea>
|
||||||
</div>
|
</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…</em>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div ng-repeat="valError in ctrl.validationErrors" class="text-error p-l-1">
|
<div ng-repeat="valError in ctrl.validationErrors" class="text-error p-l-1">
|
||||||
<i class="fa fa-warning"></i>
|
<i class="fa fa-warning"></i>
|
||||||
{{valError}}
|
{{valError}}
|
||||||
|
@ -25,6 +25,18 @@
|
|||||||
"private_key": "{{.SecureJsonData.privateKey}}"
|
"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}}"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user