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

Commit 9d5d655

Browse files
authored
Merge pull request #52 from doitintl/issue-51
Fixes #51
2 parents 9688699 + 8c19329 commit 9d5d655

File tree

4 files changed

+36398
-33
lines changed

4 files changed

+36398
-33
lines changed

dist/module.js

Lines changed: 36381 additions & 22 deletions
Large diffs are not rendered by default.

dist/module.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/datasource.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export class BigQueryDatasource {
6868
this.interval = (instanceSettings.jsonData || {}).timeInterval || "1m";
6969
this.authenticationType =
7070
instanceSettings.jsonData.authenticationType || "jwt";
71-
this.projectName = instanceSettings.jsonData.defaultProject || "";
71+
this.projectName =
72+
instanceSettings.jsonData.defaultProject || this.getDefaultProject();
7273
}
7374

7475
public async query(options) {
@@ -125,7 +126,7 @@ export class BigQueryDatasource {
125126
let message = "Successfully queried the BigQuery API.";
126127
const defaultErrorMessage = "Cannot connect to BigQuery API";
127128
try {
128-
const projectName = await this.getDefaultProject();
129+
const projectName = this.getDefaultProject();
129130
const path = `v2/projects/${projectName}/datasets`;
130131
const response = await this.doRequest(`${this.baseUrl}${path}`);
131132
if (response.status !== 200) {
@@ -175,17 +176,24 @@ export class BigQueryDatasource {
175176
return ResponseParser.parseTableFields(data, filter);
176177
}
177178

178-
public async getDefaultProject() {
179+
public getDefaultProject() {
179180
try {
180181
if (this.authenticationType === "gce" || !this.projectName) {
181-
const data = await this.getProjects();
182+
let data;
183+
this.getProjects()
184+
.then(results => {
185+
data = results;
186+
})
187+
.catch(err => {
188+
return (this.projectName = "");
189+
});
182190
this.projectName = data[0].value;
183191
return this.projectName;
184192
} else {
185193
return this.projectName;
186194
}
187195
} catch (error) {
188-
throw BigQueryDatasource.formatBigqueryError(error);
196+
return (this.projectName = "");
189197
}
190198
}
191199

src/specs/datasource.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,11 +1057,9 @@ describe("BigQueryDatasource", () => {
10571057
return Promise.resolve({ data: response, status: 200 });
10581058
});
10591059
});
1060-
it("should return default projects", async () => {
1061-
await ctx.ds.getDefaultProject().then(data => {
1062-
results = data;
1063-
});
1064-
expect(results).toBe("my project");
1060+
it("should return default projects", () => {
1061+
results = ctx.ds.getDefaultProject();
10651062
});
1063+
expect(results).toBe(undefined);
10661064
});
10671065
});

0 commit comments

Comments
 (0)