Skip to content

Commit

Permalink
[DOP-4171]: Add error state if webhook is hit with invalid branch or org
Browse files Browse the repository at this point in the history
  • Loading branch information
branberry committed Jan 26, 2024
1 parent f06af32 commit a3c52be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion api/controllers/v2/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,18 @@ export async function rebuildCacheGithubWebhookHandler(event: APIGatewayEvent) {
};
}

const cacheUpdateBody = JSON.stringify([{ repoOwner: body.repository.owner.login, repoName: body.repository.name }]);
const repoOwner = body.repository.owner.login;
const repoName = body.repository.name;

const ref = body.ref;
if ((ref !== 'refs/head/master' && ref !== 'refs/head/main') || (repoOwner !== '10gen' && repoOwner !== 'mongodb')) {
return {
statusCode: 403,
body: 'Cache job not processed because the request is not for the primary branch and/or the repository does not belong to the 10gen or mongodb organizations',
};
}

const cacheUpdateBody = JSON.stringify([{ repoOwner, repoName }]);
const { GITHUB_SECRET } = process.env;

if (!GITHUB_SECRET) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class CacheUpdaterApiConstruct extends Construct {
});

taskDefinition.grantRun(cacheWebhookLambda);
taskDefinition.grantRun(cacheGithubWebhookLambda);

// generic handler for the root endpoint
const rootEndpointLambda = new Function(this, 'RootEndpointLambda', {
Expand Down

0 comments on commit a3c52be

Please sign in to comment.