forked from adibenmati/node-helm
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhelm.js
214 lines (190 loc) · 7.04 KB
/
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
const commandBuilder = require('./commandBuilder');
const helperMethods = require('./helperMethods');
const Executer = require('./Executer');
module.exports = class Helm {
constructor(config) {
this.config = config;
this.executer = new Executer(config.helmCommand, config.output);
}
command(commandString, done, isJsonSupported = false) {
if (options.output && options.output == 'json') {
isJsonSupported = true;
}
this.executer.callByCommand(commandString, callbackHandler(done, isJsonSupported), isJsonSupported);
}
executeCommandByArguments(options, command, done) {
let isJsonSupported = false;
let jsonSupportedCommands = ['list', 'install', 'upgrade', 'history', 'status'];
if ((options.output && options.output == 'json') || (command.length > 0 && jsonSupportedCommands.includes(command[0]))) {
isJsonSupported = true;
}
commandBuilder.addParentOptions(options, command);
this.executer.callByArguments(command, callbackHandler(done, isJsonSupported), isJsonSupported);
}
install(options, done) {
let command = ['install'];
if (options.releaseName == null) {
throw new Error("Missing required parameters 'releaseName'");
}
command.push(options.releaseName);
if (options.chartName == null) {
throw new Error("Missing required parameter 'chartName'");
}
command.push(options.chartName);
if (options.namespace) {
command.push('--namespace');
command.push(options.namespace);
}
if (options.version) {
command.push('--version');
command.push(options.version);
}
if (options.values) {
command.push('--set');
command.push(helperMethods.flattenValuesToString(options.values));
}
this.executeCommandByArguments(options, command, done);
}
upgrade(options, done) {
let command = ['upgrade'];
if (options.releaseName == null) {
throw new Error("Missing required parameters 'releaseName'");
}
command.push(options.releaseName);
if (options.chartName == null) {
throw new Error ("Missing parameter 'chartName'");
}
command.push(options.chartName);
if (options.namespace) {
command.push('--namespace');
command.push(options.namespace);
}
if (options.version) {
command.push('--version');
command.push(options.version);
}
if (options.install) {
command.push('--install');
}
if (options.values) {
command.push('--set');
var valuesString = helperMethods.flattenValuesToString(options.values);
valuesString = valuesString.slice(0, -1);
command.push(valuesString);
}
if (options.reuseValues) {
command.push('--reuse-values');
}
if (options.resetValues) {
command.push('--reset-values');
}
this.executeCommandByArguments(options, command, done);
}
uninstall(options, done) {
let command = ['uninstall'];
if (options.releaseName == null) {
throw new Error("Missing parameter 'releaseName'");
}
command.push(options.releaseName);
if (options.namespace) {
command.push('--namespace');
command.push(options.namespace);
}
this.executeCommandByArguments(options, command, done);
}
list(options, done) {
let command = ['list'];
if (options.namespace) {
command.push('--namespace');
command.push(options.namespace);
} else if (options.allNamespaces) {
command.push('--all-namespaces');
}
if (options.max) {
command.push('--max');
command.push(options.max);
}
if (options.offset) {
command.push('--offset');
command.push(options.offset);
}
this.executeCommandByArguments(options, command, done);
}
get(options, done) {
let command = ['get'];
if (options.subCommand == null) {
throw new Error("Missing parameter 'subcommand'");
}
command.push(options.subCommand);
if (options.releaseName == null) {
throw new Error("Missing parameter 'releaseName'");
}
command.push(options.releaseName);
if (options.namespace) {
command.push('--namespace');
command.push(options.namespace);
}
this.executeCommandByArguments(options, command, done);
}
history(options, done) {
let command = ['history'];
if (options.releaseName == null) {
throw new Error("Missing parameter 'releaseName'");
}
command.push(options.releaseName);
if (options.namespace) {
command.push('--namespace');
command.push(options.namespace);
}
this.executeCommandByArguments(options, command, done);
}
test(options, done) {
let command = ['test'];
if (options.releaseName == null) {
throw new Error("Missing parameter 'releaseName'");
}
command.push(options.releaseName);
if (options.namespace) {
command.push('--namespace');
command.push(options.namespace);
}
this.executeCommandByArguments(options, command, done);
}
status(options, done) {
let command = ['status'];
if (options.releaseName == null) {
throw new Error("Missing parameter 'releaseName'");
}
command.push(options.releaseName);
if (options.namespace) {
command.push('--namespace');
command.push(options.namespace);
}
this.executeCommandByArguments(options, command, done);
}
rollback(options, done) {
let command = ['rollback'];
if (options.releaseName == null) {
throw new Error("Missing parameter 'releaseName'");
}
command.push(options.releaseName);
if (options.revision == null || typeof options.revision != 'number') {
throw new Error("Missing parameter 'revision'");
}
command.push(options.revision);
if (options.namespace) {
command.push('--namespace');
command.push(options.namespace);
}
this.executeCommandByArguments(options, command, done);
}
};
function callbackHandler(done, isJsonSupportedCommand) {
return function (err, data) {
if (err) {
done(err, data);
} else {
done(null, isJsonSupportedCommand ? helperMethods.parseJson(data) : helperMethods.parseResponseToJson(data));
}
};
}