stackdriver: get default project from backend. also ensure default project could be retrieved when authentication type is gce

This commit is contained in:
Erik Sundell
2018-10-10 11:55:45 +02:00
parent 09fb1760a1
commit b9cb4649bb
4 changed files with 79 additions and 21 deletions

View File

@@ -221,8 +221,25 @@ export default class StackdriverDatasource {
async getDefaultProject() {
try {
await this.queryPromise;
return this.projectName;
if (!this.projectName) {
const { data } = await this.backendSrv.datasourceRequest({
url: '/api/tsdb/query',
method: 'POST',
data: {
queries: [
{
refId: 'defaultProject',
type: 'defaultProject',
datasourceId: this.id,
},
],
},
});
this.projectName = data.results.defaultProject.meta.defaultProject;
return this.projectName;
} else {
return this.projectName;
}
} catch (error) {
let message = 'Projects cannot be fetched: ';
message += error.statusText ? error.statusText + ': ' : '';