mirror of
https://github.com/gadgethd/ukmesh.git
synced 2026-12-06 03:14:09 +00:00
30 lines
1.5 KiB
JavaScript
30 lines
1.5 KiB
JavaScript
const fs = require('node:fs');
|
|
|
|
function publicConfig(config, streamToken, beaconToken) {
|
|
const sources = config.postgresSources;
|
|
const tail = config.redisSources ?? [];
|
|
const mqtt = config.mqttSources ?? [];
|
|
return config.publicProjection === true && config.dbPath === '/data/analyzer.db'
|
|
&& config.publicAuthorityURL === 'http://backend:3000/internal/ingest/public/policy'
|
|
&& typeof streamToken === 'string' && streamToken.length >= 32 && config.publicAuthorityToken === streamToken
|
|
&& typeof beaconToken === 'string' && beaconToken.length >= 32 && beaconToken !== streamToken
|
|
&& !config.mqtt?.broker && Array.isArray(mqtt) && mqtt.length === 0
|
|
&& Array.isArray(sources) && sources.length === 1 && typeof sources[0]?.dsn === 'string' && /^postgres(?:ql)?:\/\//.test(sources[0].dsn)
|
|
&& sources[0].requirePublicVisibility !== false
|
|
&& Array.isArray(tail) && tail.every(source =>
|
|
source.publicURL === 'http://backend:3000/internal/ingest/public/entries'
|
|
&& source.publicToken === config.publicAuthorityToken && source.requirePublicVisibility !== false
|
|
&& !source.url && !source.privacyDsn);
|
|
}
|
|
|
|
if (require.main === module) {
|
|
try {
|
|
if (!publicConfig(JSON.parse(fs.readFileSync('/config/config.json', 'utf8')),
|
|
process.env.MQTT_RAM_PUBLIC_READ_TOKEN, process.env.BEACON_PUBLIC_READ_TOKEN)) throw Error();
|
|
} catch {
|
|
console.error('CoreScope requires a dedicated public projection configuration');
|
|
process.exitCode = 1;
|
|
}
|
|
}
|
|
module.exports = { publicConfig };
|