Add config validator (#125)

* Add config validator

* Add docs
This commit is contained in:
Will Hunt 2022-01-04 17:59:08 +00:00 committed by GitHub
parent d860b9acd1
commit 7be3458e8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 1 deletions

1
changelog.d/125.feature Normal file
View File

@ -0,0 +1 @@
Add new script `validate-config` which check your config file for simple errors.

View File

@ -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.

View File

@ -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",

View File

@ -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);
});
}