-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsecretConfig.js
More file actions
47 lines (40 loc) · 1.46 KB
/
Copy pathsecretConfig.js
File metadata and controls
47 lines (40 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import fs from 'fs';
import path from 'path';
export function readSecretValue(name, options = {}) {
const env = options.env || process.env;
const secretDir = options.secretDir || env.RTMS_SECRET_DIR || '/var/run/rtms/secrets';
if (env[name]) return env[name];
const fileEnvName = `${name}_FILE`;
if (env[fileEnvName]) {
return readSecretFile(env[fileEnvName], options);
}
const mountedPath = path.join(secretDir, name);
if (fs.existsSync(mountedPath)) {
return readSecretFile(mountedPath, options);
}
return options.defaultValue || '';
}
export function readZoomCredentials(options = {}) {
const env = options.env || process.env;
return {
meeting: {
clientId: readSecretValue('ZOOM_CLIENT_ID', { env }),
clientSecret: readSecretValue('ZOOM_CLIENT_SECRET', { env }),
secretToken: readSecretValue('ZOOM_SECRET_TOKEN', { env })
},
webinar: {
clientId: readSecretValue('ZOOM_CLIENT_ID', { env }),
clientSecret: readSecretValue('ZOOM_CLIENT_SECRET', { env }),
secretToken: readSecretValue('ZOOM_SECRET_TOKEN', { env })
},
videoSdk: {
clientId: readSecretValue('VIDEO_CLIENT_ID', { env }),
clientSecret: readSecretValue('VIDEO_CLIENT_SECRET', { env }),
secretToken: readSecretValue('VIDEO_SECRET_TOKEN', { env })
}
};
}
function readSecretFile(filePath, options = {}) {
const value = fs.readFileSync(filePath, 'utf8');
return options.preserveWhitespace ? value : value.trimEnd();
}