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

39 lines
1.5 KiB

import { EnvironmentalVariableBridge } from '@rocket.chat/apps-engine/server/bridges/EnvironmentalVariableBridge';
import { AppServerOrchestrator } from '../orchestrator';
export class AppEnvironmentalVariableBridge extends EnvironmentalVariableBridge {
allowed: Array<string>;
// eslint-disable-next-line no-empty-function
constructor(private readonly orch: AppServerOrchestrator) {
super();
this.allowed = ['NODE_ENV', 'ROOT_URL', 'INSTANCE_IP'];
}
protected async getValueByName(envVarName: string, appId: string): Promise<string | undefined> {
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];
}
protected async isReadable(envVarName: string, appId: string): Promise<boolean> {
this.orch.debugLog(`The App ${ appId } is checking if the environmental variable is readable ${ envVarName }.`);
return this.allowed.includes(envVarName.toUpperCase());
}
protected async isSet(envVarName: string, appId: string): Promise<boolean> {
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';
}
}