forked from redhat-developer/vscode-openshift-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.ts
More file actions
323 lines (273 loc) · 10.1 KB
/
command.ts
File metadata and controls
323 lines (273 loc) · 10.1 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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import { CommandOption, CommandText, verbose } from '../base/command';
export class Command {
static deletePreviouslyPushedResources(name: string): CommandText {
return new CommandText('oc delete', 'deployment', [
new CommandOption('-l', `component='${name}'`),
new CommandOption('--cascade')
])
}
static deploy(): CommandText {
return new CommandText('odo', 'deploy');
}
static undeploy(name?: string): CommandText {
const command = new CommandText('odo delete', 'component');
if (name) {
command.addOption(new CommandOption('--name', name));
}
return command;
}
static dev(debug: boolean, runOn?: undefined | 'podman'): CommandText {
const command = new CommandText('odo', 'dev');
if (debug) {
command.addOption(new CommandOption('--debug'));
}
if (runOn) {
command.addOption(new CommandOption('--platform', 'podman'));
command.addOption(new CommandOption('--forward-localhost'));
}
return command;
}
static ocCreate(fileName: string, namespace?: string): CommandText {
const cmd = new CommandText(
'oc create',
undefined,
[ new CommandOption('-f', fileName), ]
);
if (namespace) {
cmd.addOption(new CommandOption('--namespace', namespace));
}
return cmd;
}
static listProjects(): CommandText {
return new CommandText('odo', 'list project', [
new CommandOption('-o', 'json', false)
]);
}
static getDeployments(namespace: string): CommandText {
return new CommandText(
'oc get deployment',
undefined,
[
new CommandOption('--namespace', namespace),
new CommandOption('-o', 'json'),
]
);
}
static deleteProject(name: string): CommandText {
return new CommandText(
'odo delete namespace',
name, [
new CommandOption('-f'),
new CommandOption('-w'),
]
);
}
@verbose
static createProject(name: string): CommandText {
return new CommandText('odo create namespace',
name, [
new CommandOption('-w')
]
);
}
static listComponents(project: string): CommandText {
return new CommandText('odo list component',
undefined, [
new CommandOption('--namespace', project),
new CommandOption('-o', 'json', false)
]
);
}
static listRegistries(): CommandText {
return new CommandText('odo preference view -o json');
}
static addRegistry(name: string, url: string, token: string): CommandText {
const cTxt = new CommandText('odo preference add registry', `${name} ${url}`);
if (token) {
cTxt.addOption(new CommandOption('--token', token));
}
return cTxt;
}
static removeRegistry(name: string): CommandText {
return new CommandText('odo preference remove registry', name, [new CommandOption('--force')]);
}
static listCatalogComponents(): CommandText {
return new CommandText('odo registry');
}
static listCatalogComponentsJson(): CommandText {
return new CommandText(`${Command.listCatalogComponents().toString()} -o json`);
}
static listCatalogOperatorBackedServices(): CommandText {
return new CommandText('oc get csv -o jsonpath="{range .items[*]}{.metadata.name}{\'\\t\'}{.spec.version}{\'\\t\'}{.spec.displayName}{\'\\t\'}{.metadata.annotations.description}{\'\\t\'}{.spec.customresourcedefinitions.owned}{\'\\n\'}{end}"');
}
static printOcVersion(): CommandText {
return new CommandText('oc version');
}
static addHelmRepo(): CommandText {
return new CommandText('helm repo add openshift https://charts.openshift.io/');
}
static updateHelmRepo(): CommandText {
return new CommandText('helm repo update');
}
static installHelmChart(name: string, chartName: string, version: string): CommandText {
return new CommandText(`helm install ${name} openshift/${chartName} --version ${version}`);
}
static unInstallHelmChart(name: string): CommandText {
return new CommandText(`helm uninstall ${name}`);
}
static printOcVersionJson(): CommandText {
return new CommandText('oc version -ojson');
}
static listServiceInstances(namespace: string): CommandText {
return new CommandText('odo list service',
undefined, [
new CommandOption('--namespace', namespace),
new CommandOption('-o', 'json', false)
]
);
}
static printOdoVersion(): CommandText {
return new CommandText('odo version');
}
static odoLogout(): CommandText {
return new CommandText('odo logout');
}
static setOpenshiftContext(context: string): CommandText {
return new CommandText('oc config use-context',
context
);
}
static odoLoginWithUsernamePassword(
clusterURL: string,
username: string,
passwd: string,
): CommandText {
return new CommandText('oc login',
clusterURL, [
new CommandOption('-u', username, true, true),
new CommandOption('-p', passwd, true, true),
new CommandOption('--insecure-skip-tls-verify')
]
);
}
static odoLoginWithToken(clusterURL: string, ocToken: string): CommandText {
return new CommandText('oc login',
clusterURL, [
new CommandOption('--token', ocToken),
new CommandOption('--insecure-skip-tls-verify')
]
);
}
static describeComponent(): CommandText {
return new CommandText('odo', 'describe component');
}
static describeComponentJson(): CommandText {
return Command.describeComponent().addOption(new CommandOption('-o', 'json', false));
}
static describeCatalogComponent(component: string, registry: string): CommandText {
return new CommandText('odo',
'registry', [
new CommandOption('--details'),
new CommandOption('--devfile', component),
new CommandOption('--devfile-registry', registry),
new CommandOption('-o', 'json', false),
]
);
}
static showLog(platform?: string): CommandText {
const result = new CommandText('odo', 'logs', [
new CommandOption('--dev'),
]);
if (platform) {
result.addOption(new CommandOption('--platform', platform));
}
return result;
}
static showLogAndFollow(platform?: string): CommandText {
return Command.showLog(platform).addOption(new CommandOption('--follow'));
}
@verbose
static createLocalComponent(
type = '', // will use empty string in case of undefined type passed in
registryName: string,
name: string,
starter: string = undefined,
useExistingDevfile = false,
customDevfilePath = '',
devfileVersion: string = undefined,
): CommandText {
const cTxt = new CommandText('odo', 'init', [
new CommandOption('--name', name)
]
);
if (type !== '') {
cTxt.addOption(new CommandOption('--devfile', type));
}
if (registryName) {
cTxt.addOption(new CommandOption('--devfile-registry', registryName));
}
if (starter) {
cTxt.addOption(new CommandOption('--starter', starter, false));
}
if (useExistingDevfile && customDevfilePath.length === 0) {
cTxt.addOption(new CommandOption('--devfile-path', 'devfile.yaml', false));
}
if (customDevfilePath.length > 0) {
cTxt.addOption(new CommandOption('--devfile-path', customDevfilePath, false));
}
if (devfileVersion) {
cTxt.addOption(new CommandOption('--devfile-version', devfileVersion, false));
}
return cTxt;
}
static deleteContext(name: string): CommandText {
return new CommandText('oc config delete-context', name);
}
static deleteCluster(name: string): CommandText {
return new CommandText('oc config delete-cluster', `${name}`);
}
static deleteUser(name: string): CommandText {
return new CommandText('oc config delete-user', name);
}
static showServerUrl(): CommandText {
return new CommandText('oc whoami --show-server');
}
static getCurrentUserName(): CommandText {
return new CommandText('oc whoami');
}
static getCurrentUserToken(): CommandText {
return new CommandText('oc whoami -t');
}
static showConsoleUrl(): CommandText {
return new CommandText('oc get configmaps console-public -n openshift-config-managed -o json');
}
static getClusterServiceVersionJson(name: string) {
return new CommandText('oc get csv',
name, [
new CommandOption('-o', 'json')
]
);
}
static analyze(): CommandText {
return new CommandText('odo analyze -o json');
}
static setNamespace(namespace: string) {
return new CommandText('odo set namespace', namespace);
}
static deleteComponentConfiguration(): CommandText {
return new CommandText('odo delete component', undefined, [
new CommandOption('--files'),
new CommandOption('-f'),
]);
}
static canCreatePod(): CommandText {
return new CommandText('oc auth can-i create pod');
}
static isOpenshiftCluster(): CommandText {
return new CommandText('oc api-resources | grep openshift');
}
}