-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckSecretParameters.js
50 lines (35 loc) · 1.35 KB
/
checkSecretParameters.js
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
48
49
50
'use strict';
const
_ = require('lodash'),
fs = require('fs-extra'),
yaml = require('yamljs'),
moduleConfig = require('./getModuleConfig')()
;
module.exports = checkSecretParameters;
// Check if parameters and dist parameters are keys iso
function checkSecretParameters (parametersPath) {
const distParametersPath = parametersPath + '.dist';
let distParameters,
parameters
;
if (!fs.existsSync(distParametersPath)) return;
distParameters = _.get(yaml.load(distParametersPath), 'parameters');
if (!distParameters) return;
if (!fs.existsSync(parametersPath)) {
fs.copySync(distParametersPath, parametersPath);
console.warn(`ConfigComponent: Created ${parametersPath} from ${distParametersPath}, please check the keys.`);
return;
}
parameters = yaml.load(parametersPath).parameters;
let diff = _.difference(_.keys(distParameters), _.keys(parameters)),
diff2 = _.difference(_.keys(parameters), _.keys(distParameters))
;
diff = diff.concat(diff2);
if (diff.length) throw distParametersException(diff);
}
function distParametersException (diff) {
let err = new Error(`${moduleConfig.SECRET_PARAMETERS_FILE} and ${moduleConfig.SECRET_PARAMETERS_FILE}.dist must have the exact same keys, mismatch on: ${diff.join(
', ')}`);
err.name = 'distParametersException';
return err;
}