Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
Fix default project detection for GCE authentication type (GitHub: #326
Browse files Browse the repository at this point in the history
…, #317, #278)
  • Loading branch information
ofir5300 committed May 2, 2021
1 parent 04db2d4 commit f59c6dd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ export class BigQueryDatasource {
let status = 'success';
let message = 'Successfully queried the BigQuery API.';
const defaultErrorMessage = 'Cannot connect to BigQuery API';
if (!this.projectName) {
try {
await this.getDefaultProject();
} catch (error) {
message = error.statusText ? error.statusText : defaultErrorMessage;
}
}
try {
const path = `v2/projects/${this.projectName}/datasets`;
const response = await this.doRequest(`${this.baseUrl}${path}`);
Expand Down Expand Up @@ -391,9 +398,11 @@ export class BigQueryDatasource {
public async getDefaultProject() {
try {
if (this.authenticationType === 'gce' || !this.projectName) {
let data;
data = await this.getProjects();
const data = await this.getProjects();
this.projectName = data[0].value;
if (!this.runInProject) {
this.runInProject = this.projectName;
}
return data[0].value;
} else {
return this.projectName;
Expand Down

0 comments on commit f59c6dd

Please sign in to comment.