Skip to content

Commit 3b38c33

Browse files
committed
Adding checks for service account key
1 parent a43eb46 commit 3b38c33

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

components/gmail/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/gmail",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "Pipedream Gmail Components",
55
"main": "gmail.app.mjs",
66
"keywords": [

components/gmail/sources/new-email-received/new-email-received.mjs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default {
1515
name: "New Email Received",
1616
description: "Emit new event when a new email is received.",
1717
type: "source",
18-
version: "0.1.10",
18+
version: "0.1.11",
1919
dedupe: "unique",
2020
props: {
2121
gmail,
@@ -166,7 +166,7 @@ export default {
166166
// create topic prop
167167
let topicName = this.topic;
168168
if (this.topicType === "new") {
169-
const authKeyJSON = JSON.parse(this.serviceAccountKeyJson);
169+
const authKeyJSON = this.getServiceAccountKeyJson();
170170
const { project_id: projectId } = authKeyJSON;
171171
topicName = `projects/${projectId}/topics/${this.convertNameToValidPubSubTopicName(
172172
uuidv4(),
@@ -317,8 +317,18 @@ export default {
317317
_setLastReceivedTime(lastReceivedTime) {
318318
this.db.set("lastReceivedTime", lastReceivedTime);
319319
},
320+
getServiceAccountKeyJson() {
321+
try {
322+
return JSON.parse(this.serviceAccountKeyJson);
323+
} catch (err) {
324+
throw new ConfigurationError(`Error parsing \`Service Account Key JSON\`. Ensure its contents are valid JSON. \`${err}\``);
325+
}
326+
},
320327
sdkParams() {
321-
const authKeyJSON = JSON.parse(this.serviceAccountKeyJson);
328+
if (!this.serviceAccountKeyJson) {
329+
throw new ConfigurationError("Not able to create a webhook or subscribe to topics without configuring a service account. Please reconfigure the trigger type and try again.");
330+
}
331+
const authKeyJSON = this.getServiceAccountKeyJson();
322332
const {
323333
project_id: projectId, client_email, private_key,
324334
} = authKeyJSON;
@@ -332,6 +342,7 @@ export default {
332342
return sdkParams;
333343
},
334344
async getTopics() {
345+
335346
const sdkParams = this.sdkParams();
336347
const pubSubClient = new PubSub(sdkParams);
337348
const topics = (await pubSubClient.getTopics())[0];

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)