Skip to content

Commit

Permalink
[Gdrive] Adding tracability to webhooks (#2476)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasryaric authored Nov 10, 2023
1 parent ad07397 commit 66a57e2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion connectors/src/api_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function startServer(port: number) {

app.post("/webhooks/:webhook_secret/slack", webhookSlackAPIHandler);
app.post(
"/webhooks/:webhook_secret/google_drive",
"/webhooks/:webhook_secret/google_drive/:connector_id?",
webhookGoogleDriveAPIHandler
);
app.post(
Expand Down
2 changes: 1 addition & 1 deletion connectors/src/connectors/google_drive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export async function createGoogleDriveConnector(
{ transaction: t }
);

const webhookInfo = await registerWebhook(connector.connectionId);
const webhookInfo = await registerWebhook(connector);
if (webhookInfo.isErr()) {
throw webhookInfo.error;
} else {
Expand Down
8 changes: 4 additions & 4 deletions connectors/src/connectors/google_drive/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import memoize from "lodash.memoize";
import { v4 as uuidv4 } from "uuid";

import { HTTPError } from "@connectors/lib/error";
import { GoogleDriveFiles, ModelId } from "@connectors/lib/models";
import { Connector, GoogleDriveFiles, ModelId } from "@connectors/lib/models";
import { Err, Ok, type Result } from "@connectors/lib/result.js";

import { getAuthObject } from "./temporal/activities";
const { CONNECTORS_PUBLIC_URL, DUST_CONNECTORS_WEBHOOKS_SECRET } = process.env;

export async function registerWebhook(
nangoConnectionId: string
connector: Connector
): Promise<
Result<{ id: string; expirationTsMs: number; url: string }, HTTPError | Error>
> {
Expand All @@ -19,11 +19,11 @@ export async function registerWebhook(
if (!CONNECTORS_PUBLIC_URL) {
return new Err(new Error("CONNECTORS_PUBLIC_URL is not defined"));
}
const auth = await getAuthObject(nangoConnectionId);
const auth = await getAuthObject(connector.connectionId);

const uuid = uuidv4().toString();
const accessToken = (await auth.getAccessToken()).token;
const webhookURL = `${CONNECTORS_PUBLIC_URL}/webhooks/${DUST_CONNECTORS_WEBHOOKS_SECRET}/google_drive`;
const webhookURL = `${CONNECTORS_PUBLIC_URL}/webhooks/${DUST_CONNECTORS_WEBHOOKS_SECRET}/google_drive/${connector.id}`;
const res = await fetch(
"https://www.googleapis.com/drive/v3/changes/watch?pageToken=&includeItemsFromAllDrives=true",
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ export async function renewOneWebhook(webhookId: ModelId) {

if (connector) {
try {
const webhookInfo = await registerWebhook(connector.connectionId);
const webhookInfo = await registerWebhook(connector);
if (webhookInfo.isErr()) {
throw webhookInfo.error;
} else {
Expand Down

0 comments on commit 66a57e2

Please sign in to comment.