forked from Vero-protocol/vero-guardian-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvault-node.js
More file actions
41 lines (35 loc) · 1.24 KB
/
Copy pathvault-node.js
File metadata and controls
41 lines (35 loc) · 1.24 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
function getVaultEnvName(name) {
return `RELAYER_VAULT_${assertSecretName(name).replace(/[^a-zA-Z0-9]/g, '_').toUpperCase()}`;
}
function getVaultSecretStatus(name, env = process.env) {
const normalizedName = assertSecretName(name);
const rawSecretPresent = Boolean(env[normalizedName]);
const encryptedRecordPresent = Boolean(
env[getVaultEnvName(normalizedName)] ||
env.RELAYER_VAULT_STORE ||
env.RELAYER_VAULT_FILE,
);
const providerName = String(env.RELAYER_VAULT_KEY_PROVIDER || '').toLowerCase();
const hardwareBacked =
env.RELAYER_VAULT_HARDWARE_BACKED === 'true' ||
Boolean(providerName && providerName !== 'software' && providerName !== 'env');
return {
configured: encryptedRecordPresent,
hardwareBacked,
rawSecretPresent,
warning: rawSecretPresent
? `${normalizedName} is a raw environment secret and will be ignored; use ${getVaultEnvName(normalizedName)}`
: undefined,
};
}
function assertSecretName(name) {
const normalizedName = String(name).trim();
if (!/^[a-zA-Z0-9_.:-]{1,128}$/.test(normalizedName)) {
throw new Error('Vault secret name contains unsupported characters');
}
return normalizedName;
}
module.exports = {
getVaultEnvName,
getVaultSecretStatus,
};