forked from rvichery/node-helm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelperMethods.js
52 lines (46 loc) · 1.45 KB
/
helperMethods.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
51
52
const YAML = require('yamljs');
const constants = require('./constants');
const flattenValuesToString = function (values) {
var valuesString = '';
for (var valueSet in values) {
if (values.hasOwnProperty(valueSet)) {
valuesString += `${valueSet}=${values[valueSet]},`;
}
}
return valuesString;
};
const flattenObject = function (obj) {
var toReturn = {};
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == "object") {
var flatObject = flattenObject(obj[i]);
for (var x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
toReturn[i + "." + x] = flatObject[x];
}
} else {
toReturn[i] = obj[i];
}
}
return toReturn;
};
function parseResponseToJson(rawData){
try{
var splitedData = rawData.split(constants.HelmResponseDelimiter);
var jsonData = splitedData.map(function(responseYml){
return YAML.parse(responseYml);
});
return jsonData;
}
catch(e){
console.log("could not parse helm response with error: " + e.message);
//ignore
return rawData;
}
}
module.exports = {
flattenValuesToString : flattenValuesToString,
flattenObject : flattenObject,
parseResponseToJson : parseResponseToJson
};