From 3d0d30a24f0f4b825b8efad585bee47e3de1eb9b Mon Sep 17 00:00:00 2001 From: Artem-Darius Atlas Date: Thu, 29 Jun 2023 16:10:02 +0300 Subject: [PATCH] feat: added configs for the auth service --- apps/auth/src/config/keys.config.ts | 10 ++++++++++ apps/auth/src/config/port.config.ts | 5 +++++ apps/auth/src/const/regex.ts | 2 ++ 3 files changed, 17 insertions(+) create mode 100644 apps/auth/src/config/keys.config.ts create mode 100644 apps/auth/src/config/port.config.ts create mode 100644 apps/auth/src/const/regex.ts diff --git a/apps/auth/src/config/keys.config.ts b/apps/auth/src/config/keys.config.ts new file mode 100644 index 0000000..9ee659f --- /dev/null +++ b/apps/auth/src/config/keys.config.ts @@ -0,0 +1,10 @@ +import { readFileSync } from "fs"; +import { join } from "path"; + +export default () => { + if (process.env.PRIVATE_KEY_PATH === undefined) throw new Error("Incorrect PRIVATE_KEY_PATH format in configurations"); + if (process.env.PUBLIC_KEY_PATH === undefined) throw new Error("Incorrect PUBLIC_KEY_PATH format in configurations"); + const private_key = readFileSync(join("./", process.env.PRIVATE_KEY_PATH), "utf8"); + const public_key = readFileSync(join("./", process.env.PUBLIC_KEY_PATH), "utf8"); + return { private_key, public_key }; +}; \ No newline at end of file diff --git a/apps/auth/src/config/port.config.ts b/apps/auth/src/config/port.config.ts new file mode 100644 index 0000000..6471b02 --- /dev/null +++ b/apps/auth/src/config/port.config.ts @@ -0,0 +1,5 @@ +export default () => { + const port = process.env.PORT !== undefined ? parseInt(process.env.PORT, 10) : 80; + if (isNaN(port) || port < 0) throw new Error("Incorrect port format in configurations"); + return { port }; +}; \ No newline at end of file diff --git a/apps/auth/src/const/regex.ts b/apps/auth/src/const/regex.ts new file mode 100644 index 0000000..c059203 --- /dev/null +++ b/apps/auth/src/const/regex.ts @@ -0,0 +1,2 @@ +export const UUIDv4 = /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i; +export const SHA256 = /^[a-f0-9]{64}$/i; \ No newline at end of file