Skip to content

Commit 76f59fe

Browse files
committed
fix: early fail auth when environment variables are not populated
1 parent 111b928 commit 76f59fe

File tree

1 file changed

+14
-7
lines changed
  • lambdas/functions/control-plane/src/github

1 file changed

+14
-7
lines changed

lambdas/functions/control-plane/src/github/auth.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,25 @@ function signJwt(payload: Record<string, unknown>, privateKey: string): string {
9191
}
9292

9393
async function createAuth(installationId: number | undefined, ghesApiUrl: string): Promise<AuthInterface> {
94+
const appIdParamName = process.env.PARAMETER_GITHUB_APP_ID_NAME;
95+
const appKeyParamName = process.env.PARAMETER_GITHUB_APP_KEY_BASE64_NAME;
96+
if (!appIdParamName) {
97+
throw new Error('Environment variable PARAMETER_GITHUB_APP_ID_NAME is not set');
98+
}
99+
if (!appKeyParamName) {
100+
throw new Error('Environment variable PARAMETER_GITHUB_APP_KEY_BASE64_NAME is not set');
101+
}
102+
94103
// Batch fetch both App ID and Private Key in a single SSM API call
95-
const paramNames = [process.env.PARAMETER_GITHUB_APP_ID_NAME, process.env.PARAMETER_GITHUB_APP_KEY_BASE64_NAME];
104+
const paramNames = [appIdParamName, appKeyParamName];
96105
const params = await getParameters(paramNames);
97-
98-
const appIdValue = params.get(process.env.PARAMETER_GITHUB_APP_ID_NAME);
99-
const privateKeyBase64 = params.get(process.env.PARAMETER_GITHUB_APP_KEY_BASE64_NAME);
100-
106+
const appIdValue = params.get(appIdParamName);
107+
const privateKeyBase64 = params.get(appKeyParamName);
101108
if (!appIdValue) {
102-
throw new Error(`Parameter ${process.env.PARAMETER_GITHUB_APP_ID_NAME} not found`);
109+
throw new Error(`Parameter ${appIdParamName} not found`);
103110
}
104111
if (!privateKeyBase64) {
105-
throw new Error(`Parameter ${process.env.PARAMETER_GITHUB_APP_KEY_BASE64_NAME} not found`);
112+
throw new Error(`Parameter ${appKeyParamName} not found`);
106113
}
107114

108115
const appId = parseInt(appIdValue);

0 commit comments

Comments
 (0)