From 07460bbea93adfa634803e66ea8ae295016f8ac2 Mon Sep 17 00:00:00 2001 From: andrewHEguardian <114918544+andrewHEguardian@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:48:19 +0100 Subject: [PATCH] remove guard and put whole authString in S3 --- server/routes/newspaperArchive.ts | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/server/routes/newspaperArchive.ts b/server/routes/newspaperArchive.ts index 4f0a5e6ae..98d3ea168 100644 --- a/server/routes/newspaperArchive.ts +++ b/server/routes/newspaperArchive.ts @@ -16,38 +16,30 @@ type NewspapersResponseBody = { }; type NewspaperArchiveConfig = { - authKey: string; + authString: string; }; function base64(input: string) { return Buffer.from(input).toString('base64'); } -export const newspaperArchiveConfigPromise: Promise< +const newspaperArchiveConfigPromise: Promise< NewspaperArchiveConfig | undefined -> = s3ConfigPromise('authKey')('newspaper-archive'); - -let authKey: string; +> = s3ConfigPromise('authString')('newspaper-archive'); const router = Router(); router.use(withIdentity(401)); router.get('/auth', async (_req: Request, res: Response) => { - const subdomain = 'theguardian'; - - if (authKey === undefined) { - const config = await newspaperArchiveConfigPromise; - - if (config?.authKey !== undefined) { - authKey = config?.authKey; - } else { - log.error(`Missing newspaper archive auth key`); - res.status(500).send(); - } + const config = await newspaperArchiveConfigPromise; + const authString = config?.authString; + if (authString === undefined) { + log.error(`Missing newspaper archive auth key`); + res.status(500).send(); } - const authHeader = base64(`${subdomain}:${authKey}`); + const authHeader = base64(`${authString}`); const requestBody: NewspapersRequestBody = {}; const response = await fetch(