-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathcommand.ts
More file actions
320 lines (259 loc) · 10.1 KB
/
command.ts
File metadata and controls
320 lines (259 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
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import { workspace } from 'vscode';
import { Platform } from '../util/platform';
function verbose(_target: any, key: string, descriptor: any): void {
let fnKey: string | undefined;
let fn: Function | undefined;
if (typeof descriptor.value === 'function') {
fnKey = 'value';
fn = descriptor.value;
} else {
throw new Error('not supported');
}
descriptor[fnKey] = function(...args: any[]): any {
const v = workspace.getConfiguration('openshiftConnector').get('outputVerbosityLevel');
const command = fn.apply(this, args);
return command + (v > 0 ? ` -v ${v}` : '');
};
}
export class Command {
static printCatalogComponentImageStreamRefJson(name: string, namespace: string): string {
return `oc get imagestream ${name} -n ${namespace} -o json`;
}
static listProjects(): string {
return 'odo project list -o json';
}
@verbose
static listApplications(project: string): string {
return `odo application list --project ${project} -o json`;
}
static deleteProject(name: string): string {
return `odo project delete ${name} -w -o json`;
}
@verbose
static createProject(name: string): string {
return `odo project create ${name} -w`;
}
static listComponents(project: string, app: string): string {
return `odo list --app ${app} --project ${project} -o json`;
}
static listCatalogComponents(): string {
return 'odo catalog list components';
}
static listCatalogComponentsJson(): string {
return `${Command.listCatalogComponents()} -o json`;
}
static listCatalogServices(): string {
return 'odo catalog list services';
}
static listCatalogServicesJson(): string {
return `${Command.listCatalogServices()} -o json`;
}
static listStorageNames(): string {
return 'odo storage list -o json';
}
static printOcVersion(): string {
return 'oc version';
}
static listServiceInstances(project: string, app: string): string {
return `odo service list -o json --project ${project} --app ${app}`;
}
static describeApplication(project: string, app: string): string {
return `odo app describe ${app} --project ${project}`;
}
static deleteApplication(project: string, app: string): string {
return `odo app delete ${app} --project ${project} -f`;
}
static printOdoVersion(): string {
return 'odo version';
}
static printOdoVersionAndProjects(): string {
return 'odo version && odo project list';
}
static odoLogout(): string {
return 'odo logout';
}
static setOpenshiftContext(context: string): string {
return `oc config use-context ${context}`;
}
static odoLoginWithUsernamePassword(
clusterURL: string,
username: string,
passwd: string,
): string {
const quote = Platform.OS === 'win32' ? '"' : '\'';
return `odo login ${clusterURL} -u ${quote}${username}${quote} -p ${quote}${passwd}${quote} --insecure-skip-tls-verify`;
}
static odoLoginWithToken(clusterURL: string, ocToken: string): string {
return `odo login ${clusterURL} --token=${ocToken} --insecure-skip-tls-verify`;
}
@verbose
static createStorage(storageName: string, mountPath: string, storageSize: string): string {
return `odo storage create ${storageName} --path=${mountPath} --size=${storageSize}`;
}
static deleteStorage(storage: string): string {
return `odo storage delete ${storage} -f`;
}
static describeStorage(storage: string): string {
return `odo storage describe ${storage}`;
}
static waitForStorageToBeGone(project: string, app: string, storage: string): string {
return `oc wait pvc/${storage}-${app}-pvc --for=delete --namespace ${project}`;
}
static undeployComponent(project: string, app: string, component: string): string {
return `odo delete ${component} -f --app ${app} --project ${project}`;
}
static deleteComponent(project: string, app: string, component: string, s2i = false): string {
return `odo delete ${component} -f --app ${app} --project ${project} --all ${s2i? ' --s2i' : ''}`;
}
static describeComponentNoContext(project: string, app: string, component: string): string {
return `odo describe ${component} --app ${app} --project ${project}`;
}
static describeComponentNoContextJson(project: string, app: string, component: string): string {
return `${this.describeComponentNoContext(project, app, component)} -o json`;
}
static describeComponent(): string {
return 'odo describe';
}
static describeComponentJson(): string {
return `${Command.describeComponent()} -o json`;
}
static describeService(service: string): string {
return `odo catalog describe service ${service}`;
}
static describeCatalogComponent(component: string): string {
return `odo catalog describe component ${component} -o json`;
}
static describeUrl(url: string): string {
return `odo url describe ${url}`;
}
static showLog(): string {
return 'odo log';
}
static showLogAndFollow(): string {
return 'odo log -f';
}
static listComponentPorts(project: string, app: string, component: string): string {
return `oc get service ${component}-${app} --namespace ${project} -o jsonpath="{range .spec.ports[*]}{.port}{','}{end}"`;
}
static linkComponentTo(
project: string,
app: string,
component: string,
componentToLink: string,
port?: string,
): string {
return `odo link ${componentToLink} --project ${project} --app ${app} --component ${component} --wait${
port ? ` --port ${port}` : ''
}`;
}
static linkServiceTo(
project: string,
app: string,
component: string,
serviceToLink: string,
): string {
return `odo link ${serviceToLink} --project ${project} --app ${app} --component ${component} --wait --wait-for-target`;
}
@verbose
static pushComponent(configOnly = false): string {
return `odo push --debug${configOnly ? ' --config' : ''}`;
}
@verbose
static watchComponent(): string {
return 'odo watch';
}
@verbose
static createLocalComponent(
project: string,
app: string,
type = '', // will use empty string in case of undefined type passed in
version: string,
name: string,
folder: string,
starter: string = undefined,
useExistingDevfile = false
): string {
return `odo create ${type}${version?':':''}${version?version:''} ${name} ${version?'--s2i':''} --context ${folder} --app ${app} --project ${project}${starter ? ` --starter=${starter}` : ''}${useExistingDevfile ? ' --devfile devfile.yaml' : ''}`;
}
@verbose
static createGitComponent(
project: string,
app: string,
type: string,
version: string,
name: string,
git: string,
ref: string,
): string {
return `odo create ${type}${version?':':''}${version?version:''} ${name} ${version?'--s2i':''} --git ${git} --ref ${ref} --app ${app} --project ${project}`;
}
@verbose
static createBinaryComponent(
project: string,
app: string,
type: string,
version: string,
name: string,
binary: string,
context: string,
): string {
return `odo create ${type}:${version} ${name} ${version?'--s2i':''} --binary ${binary} --app ${app} --project ${project} --context ${context}`;
}
@verbose
static createService(
project: string,
app: string,
template: string,
plan: string,
name: string,
): string {
return `odo service create ${template} --plan ${plan} ${name} --app ${app} --project ${project} -w`;
}
static deleteService(project: string, app: string, name: string): string {
return `odo service delete ${name} -f --project ${project} --app ${app}`;
}
static getServiceTemplate(project: string, service: string): string {
return `oc get ServiceInstance ${service} --namespace ${project} -o jsonpath="{$.metadata.labels.app\\.kubernetes\\.io/name}"`;
}
static waitForServiceToBeGone(project: string, service: string): string {
return `oc wait ServiceInstance/${service} --for delete --namespace ${project}`;
}
@verbose
static createComponentCustomUrl(name: string, port: string, secure = false): string {
return `odo url create ${name} --port ${port} ${secure ? '--secure' : ''}`;
}
static getComponentUrl(): string {
return 'odo url list -o json';
}
static deleteComponentUrl(name: string): string {
return `odo url delete -f ${name} --now`;
}
static getComponentJson(): string {
return 'odo describe -o json';
}
static unlinkComponents(
project: string,
app: string,
comp1: string,
comp2: string,
port: string,
): string {
return `odo unlink --project ${project} --app ${app} ${comp2} --port ${port} --component ${comp1}`;
}
static unlinkService(project: string, app: string, service: string, comp: string): string {
return `odo unlink --project ${project} --app ${app} ${service} --component ${comp}`;
}
static getclusterVersion(): string {
return 'oc get clusterversion -ojson';
}
static showServerUrl(): string {
return 'oc whoami --show-server';
}
static showConsoleUrl(): string {
return 'oc get configmaps console-public -n openshift-config-managed -o json';
}
}