From 7be3458e8df5255899aaad1b44b63399cc92c767 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Tue, 4 Jan 2022 17:59:08 +0000 Subject: [PATCH] Add config validator (#125) * Add config validator * Add docs --- changelog.d/125.feature | 1 + docs/setup.md | 2 ++ package.json | 3 ++- src/Config/Config.ts | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 changelog.d/125.feature diff --git a/changelog.d/125.feature b/changelog.d/125.feature new file mode 100644 index 00000000..31e29147 --- /dev/null +++ b/changelog.d/125.feature @@ -0,0 +1 @@ +Add new script `validate-config` which check your config file for simple errors. \ No newline at end of file diff --git a/docs/setup.md b/docs/setup.md index 9dd155cf..f6326ec0 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -52,6 +52,8 @@ Copy the `config.sample.yml` to a new file `config.yml`. The sample config is al You should read and fill this in as the bridge will not start without a complete config. +You may validate your config without starting the service by running `yarn validate-config`. + Copy `registration.sample.yml` into `registration.yml` and fill in: - At a minimum, you will need to replace the `as_token` and `hs_token` and change the domain part of the namespaces. diff --git a/package.json b/package.json index 9cbf5690..345f0536 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "lint": "yarn run lint:js && yarn run lint:rs", "lint:js": "eslint -c .eslintrc.js src/**/*.ts", "lint:rs": "cargo fmt --all -- --check", - "generate-default-config": "ts-node src/Config/Defaults.ts --config > config.sample.yml" + "generate-default-config": "ts-node src/Config/Defaults.ts --config > config.sample.yml", + "validate-config": "ts-node src/Config/Config.ts" }, "dependencies": { "@alloc/quick-lru": "^5.2.0", diff --git a/src/Config/Config.ts b/src/Config/Config.ts index b18fbf6b..b1dfa87f 100644 --- a/src/Config/Config.ts +++ b/src/Config/Config.ts @@ -272,3 +272,17 @@ export async function parseRegistrationFile(filename: string) { const file = await fs.readFile(filename, "utf-8"); return YAML.parse(file) as IAppserviceRegistration; } + + +// Can be called directly +if (require.main === module) { + BridgeConfig.parseConfig(process.argv[2] || "config.yml", process.env).then(() => { + // eslint-disable-next-line no-console + console.log('Config successfully validated.'); + process.exit(0); + }).catch(ex => { + // eslint-disable-next-line no-console + console.error('Error in config:', ex); + process.exit(1); + }); +}