Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions lambda/github/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,38 @@ import {
DeleteCommand,
} from '@aws-sdk/lib-dynamodb';
import { SecretsManagerClient, GetSecretValueCommand } from '@aws-sdk/client-secrets-manager';
import { SSMClient, PutParameterCommand, DeleteParameterCommand } from '@aws-sdk/client-ssm';
import {
SSMClient,
PutParameterCommand,
DeleteParameterCommand,
GetParameterCommand,
} from '@aws-sdk/client-ssm';
import crypto from 'crypto';
import { buildResponse } from '../shared/response.js';
import { resolveGitToken } from '../shared/git-token.js';

const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({}));
const secrets = new SecretsManagerClient({});
const ssm = new SSMClient({});

const GIT_TOKEN_PARAM_PATTERN = /^\/[\w-]+\/[\w-]+\/[\w-]+\/[\w-]+$/;

// Inlined from shared/git-token.js — esbuild cannot bundle the CJS module
// because it does `require('@aws-sdk/client-ssm')` which becomes a dynamic
// require not supported in the ESM runtime. Mirrors the pattern adopted by
// lambda/github-issues (see PR #180).
const resolveGitToken = async (ssmClient, item) => {
if (item?.parameterName) {
if (!GIT_TOKEN_PARAM_PATTERN.test(item.parameterName)) {
throw new Error('Invalid SSM parameter name format');
}
const param = await ssmClient.send(
new GetParameterCommand({ Name: item.parameterName, WithDecryption: true }),
);
return JSON.parse(param.Parameter.Value).accessToken;
}
throw new Error('No SSM parameter name set');
};

class OAuthNotConfiguredError extends Error {
constructor() {
super(
Expand Down
13 changes: 6 additions & 7 deletions terraform/modules/api/lambda/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -668,17 +668,16 @@ module "github_lambda" {

function_name = "${var.project_name}-github-${var.environment}"
handler = "index.handler"
runtime = "nodejs18.x"
runtime = "nodejs24.x"
timeout = 30

source_path = [
{
path = "${path.module}/../../../../lambda/github"
npm_requirements = true
},
{
path = "${path.module}/../../../../lambda/shared"
prefix_in_zip = "shared"
path = "${path.module}/../../../../lambda/github"
commands = [
"cd ../.. && npm run build -w github-lambda",
":zip lambda/github/.build",
]
}
]

Expand Down
Loading