-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers-helm.js
77 lines (61 loc) · 1.7 KB
/
helpers-helm.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const path = require("path");
const { TOKEN_REGEXP } = require("./consts");
function splitDirectory(directory) {
return [
path.dirname(directory),
path.basename(directory),
];
}
// Make sure command isn't trying to overrride something parameterized
function sanitizeParameters(command, authenticationParamsMap) {
const sanitizedParameters = new Map();
authenticationParamsMap.forEach((value, key) => {
if (!command.includes(key)) {
sanitizedParameters.set(key, value);
}
});
return sanitizedParameters;
}
function generateEnvironmentalVariableName(parameterName) {
const regex = /-/g;
let result = parameterName.replace(regex, "_");
if (result.startsWith("_")) {
result = result.substring(1);
}
if (result.startsWith("_")) {
result = result.substring(1);
}
result = `$${result.toUpperCase()}`;
return result;
}
function paramsMapToParamsWithEnvironmentalVariablesArray(paramsMap) {
return Array.from(
paramsMap,
([key]) => ([key, generateEnvironmentalVariableName(key)]),
).flat();
}
function paramsMapToEnvironmentalVariablesObject(paramsMap) {
return Object.fromEntries(
Array.from(
paramsMap,
([key, value]) => ([generateEnvironmentalVariableName(key).substring(1), value]),
),
);
}
// Helm Docker image has ENTRYPOINT ["helm"]
function sanitizeCommand(command) {
return command.startsWith("helm")
? command.slice(4).trim()
: command;
}
function redactTokenValue(str) {
return str.replace(TOKEN_REGEXP, "$1redacted$3");
}
module.exports = {
splitDirectory,
sanitizeParameters,
paramsMapToParamsWithEnvironmentalVariablesArray,
paramsMapToEnvironmentalVariablesObject,
sanitizeCommand,
redactTokenValue,
};