From eb31c88f8361bdd3c21ec01976522306a8ad9d6d Mon Sep 17 00:00:00 2001 From: William Oldham Date: Wed, 16 Oct 2024 13:34:42 +0100 Subject: [PATCH 1/3] Add S3 config option for region and path-style --- src/config-manager.ts | 9 ++++++++- src/types/common/config.ts | 2 ++ src/util.ts | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/config-manager.ts b/src/config-manager.ts index fb9d1c7..7d98100 100644 --- a/src/config-manager.ts +++ b/src/config-manager.ts @@ -56,7 +56,9 @@ export const config: Config = { s3: { endpoint: process.env.PN_ACT_CONFIG_S3_ENDPOINT || '', key: process.env.PN_ACT_CONFIG_S3_ACCESS_KEY || '', - secret: process.env.PN_ACT_CONFIG_S3_ACCESS_SECRET || '' + secret: process.env.PN_ACT_CONFIG_S3_ACCESS_SECRET || '', + region: process.env.PN_ACT_CONFIG_S3_REGION || '', + forcePathStyle: process.env.PN_ACT_CONFIG_S3_FORCE_PATH_STYLE === 'true' }, hcaptcha: { secret: process.env.PN_ACT_CONFIG_HCAPTCHA_SECRET || '' @@ -195,6 +197,11 @@ if (!config.s3.secret) { disabledFeatures.s3 = true; } +if (!config.s3.region) { + LOG_WARN('Failed to find S3 region config. Disabling feature. To enable feature set the PN_ACT_CONFIG_S3_REGION environment variable'); + disabledFeatures.s3 = true; +} + if (!config.server_environment) { LOG_WARN('Failed to find server environment. To change the environment, set the PN_ACT_CONFIG_SERVER_ENVIRONMENT environment variable. Defaulting to prod'); config.server_environment = 'prod'; diff --git a/src/types/common/config.ts b/src/types/common/config.ts index 5585280..3554c56 100644 --- a/src/types/common/config.ts +++ b/src/types/common/config.ts @@ -30,6 +30,8 @@ export interface Config { endpoint: string; key: string; secret: string; + region: string; + forcePathStyle: boolean; }; hcaptcha: { secret: string; diff --git a/src/util.ts b/src/util.ts index 8df0490..753bfb3 100644 --- a/src/util.ts +++ b/src/util.ts @@ -20,6 +20,8 @@ let s3: S3; if (!disabledFeatures.s3) { s3 = new S3({ endpoint: config.s3.endpoint, + forcePathStyle: config.s3.forcePathStyle, + region: config.s3.region, credentials: { accessKeyId: config.s3.key, From 83dab9bb5da9da307f0fd33fe71ed0e4127a1552 Mon Sep 17 00:00:00 2001 From: William Oldham Date: Wed, 16 Oct 2024 14:09:23 +0100 Subject: [PATCH 2/3] Use appropriate error message and status code for register route --- src/services/api/routes/v1/register.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/services/api/routes/v1/register.ts b/src/services/api/routes/v1/register.ts index 2b1928b..728b8f8 100644 --- a/src/services/api/routes/v1/register.ts +++ b/src/services/api/routes/v1/register.ts @@ -345,15 +345,16 @@ router.post('/', async (request: express.Request, response: express.Response): P await pnid.save({ session }); await session.commitTransaction(); - } catch (error) { + } catch (error: any) { LOG_ERROR('[POST] /v1/register: ' + error); + if (error.stack) console.error(error.stack) await session.abortTransaction(); - response.status(400).json({ + response.status(500).json({ app: 'api', - status: 400, - error: 'Password must have combination of letters, numbers, and/or punctuation characters' + status: 500, + error: 'Internal server error' }); return; From 54dfed93467c1f4fbb6ffb774ed61cd60f6e3fed Mon Sep 17 00:00:00 2001 From: William Oldham Date: Wed, 16 Oct 2024 14:40:26 +0100 Subject: [PATCH 3/3] Fix missing semicolon --- src/services/api/routes/v1/register.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/api/routes/v1/register.ts b/src/services/api/routes/v1/register.ts index 728b8f8..3bf0cad 100644 --- a/src/services/api/routes/v1/register.ts +++ b/src/services/api/routes/v1/register.ts @@ -347,7 +347,7 @@ router.post('/', async (request: express.Request, response: express.Response): P await session.commitTransaction(); } catch (error: any) { LOG_ERROR('[POST] /v1/register: ' + error); - if (error.stack) console.error(error.stack) + if (error.stack) console.error(error.stack); await session.abortTransaction();