From 15ee35d99631a290fb17811ee182784cb71b503e Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Sun, 16 Jul 2023 14:26:09 -0600 Subject: [PATCH] feat: added more config checks --- backend/UserConfig.ts | 27 +++++++++++++++++++++++++++ common/types.d.ts | 17 +++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/backend/UserConfig.ts b/backend/UserConfig.ts index 7b819c2..619cece 100644 --- a/backend/UserConfig.ts +++ b/backend/UserConfig.ts @@ -40,6 +40,25 @@ const Checkers: UserConfigTypeChecker = { idSize: numChecker, gfySize: numChecker, maximumFileSize: numChecker, + + s3: { + endpoint: basicStringChecker, + bucket: basicStringChecker, + region: (val) => val == null || basicStringChecker(val), + credentials: { + accessKey: basicStringChecker, + secretKey: basicStringChecker + } + }, + + sql: { + mySql: { + host: basicStringChecker, + user: basicStringChecker, + password: basicStringChecker, + database: basicStringChecker + } + } } export class UserConfig { @@ -69,6 +88,14 @@ export class UserConfig { if (!Checkers.gfySize(config.gfySize)) throw new Error('Invalid Gfy size'); if (!Checkers.maximumFileSize(config.maximumFileSize)) throw new Error('Invalid maximum file size'); + if (config.s3 != null) { + if (!Checkers.s3.endpoint(config.s3.endpoint)) throw new Error('Invalid S3 Endpoint'); + if (!Checkers.s3.bucket(config.s3.bucket)) throw new Error('Invalid S3 Bucket'); + if (!Checkers.s3.region(config.s3.region)) throw new Error('Invalid S3 Region'); + if (!Checkers.s3.credentials.accessKey(config.s3.credentials.accessKey)) throw new Error('Invalid S3 Access key'); + if (!Checkers.s3.credentials.secretKey(config.s3.credentials.secretKey)) throw new Error('Invalid S3 Secret key'); + } + // All is fine, carry on! return config; } diff --git a/common/types.d.ts b/common/types.d.ts index 88b939e..229d6f4 100644 --- a/common/types.d.ts +++ b/common/types.d.ts @@ -61,6 +61,23 @@ declare module 'ass' { idSize: (val: any) => boolean; gfySize: (val: any) => boolean; maximumFileSize: (val: any) => boolean; + s3: { + endpoint: (val: any) => boolean; + bucket: (val: any) => boolean; + region: (val: any) => boolean; + credentials: { + accessKey: (val: any) => boolean; + secretKey: (val: any) => boolean; + } + } + sql: { + mySql: { + host: (val: any) => boolean; + user: (val: any) => boolean; + password: (val: any) => boolean; + database: (val: any) => boolean; + } + } } interface BusBoyFile {