The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/apps/server/bridges/environmental.js

32 lines
1.0 KiB

export class AppEnvironmentalVariableBridge {
constructor(orch) {
this.orch = orch;
this.allowed = ['NODE_ENV', 'ROOT_URL', 'INSTANCE_IP'];
}
async getValueByName(envVarName, appId) {
this.orch.debugLog(`The App ${ appId } is getting the environmental variable value ${ envVarName }.`);
if (!await this.isReadable(envVarName, appId)) {
throw new Error(`The environmental variable "${ envVarName }" is not readable.`);
}
return process.env[envVarName];
}
async isReadable(envVarName, appId) {
this.orch.debugLog(`The App ${ appId } is checking if the environmental variable is readable ${ envVarName }.`);
return this.allowed.includes(envVarName.toUpperCase());
}
async isSet(envVarName, appId) {
this.orch.debugLog(`The App ${ appId } is checking if the environmental variable is set ${ envVarName }.`);
if (!await this.isReadable(envVarName, appId)) {
throw new Error(`The environmental variable "${ envVarName }" is not readable.`);
}
return typeof process.env[envVarName] !== 'undefined';
}
}