From 78bdc425341410165283cc866a56351f1eba3f5f Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Mon, 10 Jun 2024 19:25:41 +0100 Subject: [PATCH] refactor: Update SelfSignedSSL class to use async/await for generating SSL certificates --- .../Utils/CodeRepository/CodeRepository.ts | 5 ++ CommonServer/Utils/Exec.ts | 18 ++++++ Nginx/Utils/SelfSignedSSL.ts | 20 ++---- Nginx/package-lock.json | 61 +++++++++---------- 4 files changed, 57 insertions(+), 47 deletions(-) create mode 100644 CommonServer/Utils/CodeRepository/CodeRepository.ts create mode 100644 CommonServer/Utils/Exec.ts diff --git a/CommonServer/Utils/CodeRepository/CodeRepository.ts b/CommonServer/Utils/CodeRepository/CodeRepository.ts new file mode 100644 index 0000000000..345fb6f6c3 --- /dev/null +++ b/CommonServer/Utils/CodeRepository/CodeRepository.ts @@ -0,0 +1,5 @@ +export default class CodeRepositoryUtil { + public static getGitCommitHashForFile(filePath: string): string { + // this is git repository. + } +} diff --git a/CommonServer/Utils/Exec.ts b/CommonServer/Utils/Exec.ts new file mode 100644 index 0000000000..c044aef893 --- /dev/null +++ b/CommonServer/Utils/Exec.ts @@ -0,0 +1,18 @@ +import { PromiseRejectErrorFunction } from 'Common/Types/FunctionTypes'; +import { ExecException, exec } from 'node:child_process'; + +export default class Exec { + public static exec(command: string): Promise { + return new Promise( + (resolve: VoidFunction, reject: PromiseRejectErrorFunction) => { + exec(`${command}`, (err: ExecException | null) => { + if (err) { + return reject(err); + } + + return resolve(); + }); + } + ); + } +} diff --git a/Nginx/Utils/SelfSignedSSL.ts b/Nginx/Utils/SelfSignedSSL.ts index 759ce5a914..003758c224 100644 --- a/Nginx/Utils/SelfSignedSSL.ts +++ b/Nginx/Utils/SelfSignedSSL.ts @@ -1,21 +1,9 @@ -import { PromiseRejectErrorFunction } from 'Common/Types/FunctionTypes'; -import { ExecException, exec } from 'node:child_process'; +import Exec from 'CommonServer/Utils/Exec'; export default class SelfSignedSSL { - public static generate(path: string, host: string): Promise { - return new Promise( - (resolve: VoidFunction, reject: PromiseRejectErrorFunction) => { - exec( - `mkdir -p ${path} && openssl req -new -x509 -nodes -subj "/C=US/ST=NY/L=NYC/O=Global Security/OU=IT Department/CN=example.com" -out ${path}/${host}.crt -keyout ${path}/${host}.key -days 99999 && chmod -R 777 ${path}`, - (err: ExecException | null) => { - if (err) { - return reject(err); - } - - return resolve(); - } - ); - } + public static async generate(path: string, host: string): Promise { + return await Exec.exec( + `mkdir -p ${path} && openssl req -new -x509 -nodes -subj "/C=US/ST=NY/L=NYC/O=Global Security/OU=IT Department/CN=example.com" -out ${path}/${host}.crt -keyout ${path}/${host}.key -days 99999 && chmod -R 777 ${path}` ); } } diff --git a/Nginx/package-lock.json b/Nginx/package-lock.json index 2768542d91..a413ea12dc 100644 --- a/Nginx/package-lock.json +++ b/Nginx/package-lock.json @@ -1,13 +1,13 @@ { - "name": "nginx", + "name": "@oneuptime/nginx", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "nginx", + "name": "@oneuptime/nginx", "version": "1.0.0", - "license": "ISC", + "license": "Apache-2.0", "dependencies": { "Common": "file:../Common", "CommonServer": "file:../CommonServer", @@ -19,19 +19,19 @@ } }, "../Common": { - "name": "common", + "name": "@oneuptime/common", "version": "1.0.0", - "license": "MIT", + "license": "Apache-2.0", "dependencies": { "@types/crypto-js": "^4.2.2", "@types/uuid": "^8.3.4", - "axios": "^1.6.7", + "axios": "^1.6.8", "crypto-js": "^4.1.1", "json5": "^2.2.3", "moment": "^2.30.1", "moment-timezone": "^0.5.45", - "posthog-js": "^1.105.7", - "reflect-metadata": "^0.2.1", + "posthog-js": "^1.131.4", + "reflect-metadata": "^0.2.2", "slugify": "^1.6.5", "typeorm": "^0.3.20", "uuid": "^8.3.2" @@ -45,49 +45,49 @@ } }, "../CommonServer": { - "name": "common-server", + "name": "@oneuptime/common-server", "version": "1.0.0", - "license": "MIT", + "license": "Apache-2.0", "dependencies": { - "@clickhouse/client": "^0.2.9", - "@elastic/elasticsearch": "^8.11.0", + "@clickhouse/client": "^0.2.10", + "@elastic/elasticsearch": "^8.12.1", "@opentelemetry/api": "^1.7.0", - "@opentelemetry/api-logs": "^0.48.0", - "@opentelemetry/exporter-logs-otlp-http": "^0.48.0", - "@opentelemetry/exporter-metrics-otlp-proto": "^0.48.0", - "@opentelemetry/exporter-trace-otlp-proto": "^0.48.0", + "@opentelemetry/api-logs": "^0.49.1", + "@opentelemetry/auto-instrumentations-node": "^0.43.0", + "@opentelemetry/exporter-logs-otlp-http": "^0.49.1", + "@opentelemetry/exporter-metrics-otlp-proto": "^0.49.1", + "@opentelemetry/exporter-trace-otlp-proto": "^0.49.1", "@opentelemetry/id-generator-aws-xray": "^1.2.1", - "@opentelemetry/instrumentation-express": "^0.35.0", - "@opentelemetry/instrumentation-http": "^0.48.0", - "@opentelemetry/sdk-logs": "^0.48.0", + "@opentelemetry/sdk-logs": "^0.49.1", "@opentelemetry/sdk-metrics": "^1.21.0", "@opentelemetry/sdk-node": "^0.48.0", "@opentelemetry/sdk-trace-node": "^1.21.0", - "@socket.io/redis-adapter": "^8.2.1", + "@types/crypto-js": "^4.2.2", + "acme-client": "^5.3.0", "airtable": "^0.12.2", - "axios": "^1.6.7", "bullmq": "^5.3.3", "Common": "file:../Common", "cookie-parser": "^1.4.6", "cors": "^2.8.5", "cron-parser": "^4.8.1", - "dotenv": "^16.4.1", - "ejs": "^3.1.8", - "express": "^4.17.3", + "crypto-js": "^4.2.0", + "dotenv": "^16.4.4", + "ejs": "^3.1.10", + "express": "^4.19.2", "ioredis": "^5.3.2", "json2csv": "^5.0.7", "jsonwebtoken": "^9.0.0", - "markdown-it": "^13.0.1", + "marked": "^12.0.2", "Model": "file:../Model", "node-cron": "^3.0.3", - "nodemailer": "^6.9.9", + "nodemailer": "^6.9.10", "pg": "^8.7.3", + "redis-semaphore": "^5.5.1", "socket.io": "^4.7.4", "stripe": "^10.17.0", "twilio": "^4.22.0", "typeorm": "^0.3.20", - "typeorm-extension": "^2.2.13", - "vm2": "^3.9.14" + "typeorm-extension": "^2.2.13" }, "devDependencies": { "@faker-js/faker": "^6.3.1", @@ -98,7 +98,6 @@ "@types/jest": "^27.4.1", "@types/json2csv": "^5.0.3", "@types/jsonwebtoken": "^8.5.9", - "@types/markdown-it": "^12.2.3", "@types/node": "^17.0.22", "@types/node-cron": "^3.0.7", "@types/nodemailer": "^6.4.7", @@ -108,9 +107,9 @@ } }, "../Model": { - "name": "model", + "name": "@oneuptime/model", "version": "1.0.0", - "license": "ISC", + "license": "Apache-2.0", "dependencies": { "Common": "file:../Common", "typeorm": "^0.3.20"