From 3d0f505961469a42738c31b904fa1143b0dff85a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20H=C3=BCttemann?= Date: Thu, 25 May 2023 17:35:21 +0200 Subject: [PATCH] Add dotenv and config instructions --- .env.example | 1 + README.md | 4 ++++ package-lock.json | 14 ++++++++++++++ package.json | 1 + src/app.ts | 8 +++++--- src/users.ts | 8 ++++++-- 6 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..a1dbd28 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +REGISTRATION_SHARED_SECRET='look in your synapses homeserver.yaml' diff --git a/README.md b/README.md index 6bd7b03..8a943ed 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,10 @@ curl --request POST \ > src/config/synapse_access_token.json ``` +## Configuration + +Copy over `.env.example` to `.env` and insert your values. + ## Design Decisions - Getting data from Rocket.Chat via (currently) manual mongodb export diff --git a/package-lock.json b/package-lock.json index 22ac7bb..bc004f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "AGPL-3.0-or-later", "dependencies": { "axios": "^1.4.0", + "dotenv": "^16.0.3", "winston": "^3.8.2" }, "devDependencies": { @@ -921,6 +922,14 @@ "node": ">=6.0.0" } }, + "node_modules/dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", + "engines": { + "node": ">=12" + } + }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -4513,6 +4522,11 @@ "esutils": "^2.0.2" } }, + "dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==" + }, "eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", diff --git a/package.json b/package.json index 1105132..4d94d94 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ }, "dependencies": { "axios": "^1.4.0", + "dotenv": "^16.0.3", "winston": "^3.8.2" } } diff --git a/src/app.ts b/src/app.ts index 4e15ac7..2a22567 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,9 +1,11 @@ +import dotenv from 'dotenv' +dotenv.config() import fs from 'node:fs' -import readline from 'node:readline' import log from './logger' -import { whoami } from './synapse' -import { storage } from './storage' +import readline from 'node:readline' import { RcUser, createUser } from './users' +import { storage } from './storage' +import { whoami } from './synapse' log.info('rocketchat2matrix starts.') diff --git a/src/users.ts b/src/users.ts index aac8145..025ad9e 100644 --- a/src/users.ts +++ b/src/users.ts @@ -30,8 +30,12 @@ export function mapUser(rcUser: RcUser): MatrixUser { } } -const registration_shared_secret = - 'vkq7zfBDt4A1NmMN6jJ*g+,G~.R:QuC_xI:~7~jQ_6kJ6O~JrG' +const registration_shared_secret = process.env.REGISTRATION_SHARED_SECRET || '' +if (!registration_shared_secret) { + const message = 'No REGISTRATION_SHARED_SECRET found in .env.' + log.error(message) + throw new Error(message) +} function generateHmac(user: MatrixUser): string { const hmac = createHmac('sha1', registration_shared_secret)