Skip to content

Commit 78565e0

Browse files
mmorhuntolusha
andauthored
chore: Delete auth and workspace command groups (#1910)
* Delete auth and workspace command groups Signed-off-by: Mykola Morhun <[email protected]> Signed-off-by: Anatolii Bazko <[email protected]> Co-authored-by: Anatolii Bazko <[email protected]>
1 parent 2bc4a9d commit 78565e0

31 files changed

+94
-3623
lines changed

.vscode/tasks.json

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,6 @@
2727
},
2828
"group": "build"
2929
},
30-
{
31-
"label": "[Minikube] Install Che with custom che-operator and che-server images",
32-
"command": "./bin/run server:deploy -n che -m -p minikube --che-operator-image=${IMAGE_REGISTRY_HOST}/${IMAGE_REGISTRY_USER_NAME}/che-operator:next --cheimage=${IMAGE_REGISTRY_HOST}/${IMAGE_REGISTRY_USER_NAME}/che-server:next",
33-
"type": "shell",
34-
"args": [],
35-
"problemMatcher": [
36-
"$tsc"
37-
],
38-
"presentation": {
39-
"reveal": "always"
40-
},
41-
"group": "build"
42-
},
4330
{
4431
"label": "[Openshift] Install Che",
4532
"command": "./bin/run server:deploy -n che -m -p openshift",

README.md

Lines changed: 44 additions & 485 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424
"countries-and-timezones": "^3.2.3",
2525
"debug": "^4.3.2",
2626
"eclipse-che-operator": "git://github.com/eclipse-che/che-operator#main",
27-
"esprima": "^4.0.1",
2827
"execa": "^5.1.1",
2928
"fancy-test": "^1.4.9",
3029
"fs-extra": "^10.0.0",
3130
"getos": "^3.2.1",
3231
"gnirts": "^1.1.7",
33-
"inquirer": "^8.2.0",
3432
"js-yaml": "^4.0.2",
3533
"listr": "^0.14.3",
3634
"listr-verbose-renderer": "^0.6.0",
@@ -39,10 +37,8 @@
3937
"node-forge": "^0.10.0",
4038
"node-notifier": "^10.0.0",
4139
"os-locale": "^5.0.0",
42-
"querystring": "^0.2.1",
4340
"rimraf": "^3.0.2",
4441
"semver": "^7.3.4",
45-
"stream-buffers": "^3.0.2",
4642
"tslib": "^2",
4743
"unzipper": "0.10.11",
4844
"uuid": "^8.3.2"
@@ -73,13 +69,11 @@
7369
"@typescript-eslint/eslint-plugin": "^4.33.0",
7470
"@typescript-eslint/parser": "^4.33.0",
7571
"chai": "^4.3.4",
76-
"cpx": "^1.5.0",
7772
"eslint": "^7.32.0",
7873
"eslint-config-oclif": "^3.1.0",
7974
"eslint-config-oclif-typescript": "^0.2.0",
8075
"eslint-plugin-header": "^3.1.1",
8176
"eslint-plugin-no-null": "^1.0.2",
82-
"globby": "^11",
8377
"jest": "^26.6.3",
8478
"nock": "^13.2.1",
8579
"ts-jest": "^26.5.6",
@@ -157,7 +151,6 @@
157151
"test": "jest --collect-coverage",
158152
"test-watch": "jest --watchAll",
159153
"e2e-minikube-operator": "export PLATFORM=minikube && export INSTALLER=operator && yarn jest ./test/e2e/e2e.test.ts --testRegex='/test/(e2e)/.*.test.ts'",
160-
"e2e-minishift": "export PLATFORM=minishift && export INSTALLER=operator && yarn jest ./test/e2e/e2e.test.ts --testRegex='/test/(e2e)/.*.test.ts'",
161154
"e2e-openshift": "export PLATFORM=openshift && export INSTALLER=operator && yarn jest ./test/e2e/e2e.test.ts --testRegex='/test/(e2e)/.*.test.ts'",
162155
"gnirts-ci": "node .ci/obfuscate/gnirts.js",
163156
"prepack": "yarn lint && rm -rf lib && rm -rf tsconfig.tsbuildinfo && tsc -b && oclif-dev manifest && oclif-dev readme && yarn gnirts-ci",

src/api/che-api-client.ts

Lines changed: 0 additions & 233 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
* Red Hat, Inc. - initial API and implementation
1111
*/
1212

13-
import { che as chetypes } from '@eclipse-che/api'
1413
import axios, { AxiosInstance } from 'axios'
15-
import { cli } from 'cli-ux'
1614
import * as https from 'https'
1715

1816
import { newError, sleep } from '../util'
@@ -106,237 +104,6 @@ export class CheApiClient {
106104
return response.data.status
107105
}
108106

109-
async startCheServerShutdown(accessToken = '', responseTimeoutMs = this.defaultCheResponseTimeoutMs): Promise<void> {
110-
const endpoint = `${this.cheApiEndpoint}/system/stop?shutdown=true`
111-
const headers = accessToken ? { Authorization: accessToken } : null
112-
let response = null
113-
try {
114-
response = await this.axios.post(endpoint, null, { headers, timeout: responseTimeoutMs })
115-
} catch (error) {
116-
if (error.response && error.response.status === 409) {
117-
return
118-
} else {
119-
throw this.getCheApiError(error, endpoint)
120-
}
121-
}
122-
if (!response || response.status !== 204) {
123-
throw new Error('E_BAD_RESP_CHE_API')
124-
}
125-
}
126-
127-
async waitUntilCheServerReadyToShutdown(intervalMs = 500, timeoutMs = 60000): Promise<void> {
128-
const iterations = timeoutMs / intervalMs
129-
for (let index = 0; index < iterations; index++) {
130-
const status = await this.getCheServerStatus()
131-
if (status === 'READY_TO_SHUTDOWN') {
132-
return
133-
}
134-
await cli.wait(intervalMs)
135-
}
136-
throw new Error('ERR_TIMEOUT')
137-
}
138-
139-
/**
140-
* Returns list of all workspaces of the user.
141-
*/
142-
async getAllWorkspaces(accessToken?: string): Promise<chetypes.workspace.Workspace[]> {
143-
const all: chetypes.workspace.Workspace[] = []
144-
const itemsPerPage = 30
145-
146-
let skipCount = 0
147-
let workspaces: chetypes.workspace.Workspace[]
148-
do {
149-
workspaces = await this.getWorkspaces(skipCount, itemsPerPage, accessToken)
150-
all.push(...workspaces)
151-
skipCount += workspaces.length
152-
} while (workspaces.length === itemsPerPage)
153-
154-
return all
155-
}
156-
157-
/**
158-
* Returns list of workspaces in given range.
159-
* If lst of all workspaces is needed, getAllWorkspaces should be used insted.
160-
*/
161-
async getWorkspaces(skipCount = 0, maxItems = 30, accessToken?: string): Promise<chetypes.workspace.Workspace[]> {
162-
const endpoint = `${this.cheApiEndpoint}/workspace?skipCount=${skipCount}&maxItems=${maxItems}`
163-
const headers: any = { 'Content-Type': 'text/yaml' }
164-
if (accessToken && accessToken.length > 0) {
165-
headers.Authorization = accessToken
166-
}
167-
168-
try {
169-
const response = await this.axios.get(endpoint, { headers })
170-
if (response && response.data) {
171-
return response.data
172-
} else {
173-
throw new Error('E_BAD_RESP_CHE_SERVER')
174-
}
175-
} catch (error) {
176-
throw this.getCheApiError(error, endpoint)
177-
}
178-
}
179-
180-
async getWorkspaceById(workspaceId: string, accessToken?: string): Promise<chetypes.workspace.Workspace> {
181-
const endpoint = `${this.cheApiEndpoint}/workspace/${workspaceId}`
182-
const headers: any = { 'Content-Type': 'text/yaml' }
183-
if (accessToken) {
184-
headers.Authorization = accessToken
185-
}
186-
187-
try {
188-
const response = await this.axios.get(endpoint, { headers })
189-
return response.data
190-
} catch (error) {
191-
if (error.response.status === 404) {
192-
throw new Error(`Workspace ${workspaceId} not found. Please use the command workspace:list to get list of the existed workspaces.`)
193-
}
194-
throw this.getCheApiError(error, endpoint)
195-
}
196-
}
197-
198-
async deleteWorkspaceById(workspaceId: string, accessToken?: string): Promise<void> {
199-
const endpoint = `${this.cheApiEndpoint}/workspace/${workspaceId}`
200-
const headers: any = {}
201-
if (accessToken) {
202-
headers.Authorization = accessToken
203-
}
204-
205-
try {
206-
await this.axios.delete(endpoint, { headers })
207-
} catch (error) {
208-
if (error.response.status === 404) {
209-
throw new Error(`Workspace ${workspaceId} not found. Please use the command workspace:list to get list of the existed workspaces.`)
210-
} else if (error.response.status === 409) {
211-
throw new Error('Cannot delete a running workspace. Please stop it using the command workspace:stop and try again')
212-
}
213-
throw this.getCheApiError(error, endpoint)
214-
}
215-
}
216-
217-
async startWorkspace(workspaceId: string, debug: boolean, accessToken?: string): Promise<void> {
218-
let endpoint = `${this.cheApiEndpoint}/workspace/${workspaceId}/runtime`
219-
if (debug) {
220-
endpoint += '?debug-workspace-start=true'
221-
}
222-
let response
223-
224-
const headers: { [key: string]: string } = {}
225-
if (accessToken) {
226-
headers.Authorization = accessToken
227-
}
228-
try {
229-
response = await this.axios.post(endpoint, undefined, { headers })
230-
} catch (error) {
231-
if (error.response && error.response.status === 404) {
232-
throw new Error(`E_WORKSPACE_NOT_EXIST - workspace with "${workspaceId}" id doesn't exist`)
233-
} else {
234-
throw this.getCheApiError(error, endpoint)
235-
}
236-
}
237-
238-
this.checkResponse(response, endpoint)
239-
}
240-
241-
async stopWorkspace(workspaceId: string, accessToken?: string): Promise<void> {
242-
const endpoint = `${this.cheApiEndpoint}/workspace/${workspaceId}/runtime`
243-
let response
244-
245-
const headers: { [key: string]: string } = {}
246-
if (accessToken) {
247-
headers.Authorization = accessToken
248-
}
249-
try {
250-
response = await this.axios.delete(endpoint, { headers })
251-
} catch (error) {
252-
if (error.response && error.response.status === 404) {
253-
throw new Error(`E_WORKSPACE_NOT_EXIST - workspace with "${workspaceId}" id doesn't exist`)
254-
} else {
255-
throw this.getCheApiError(error, endpoint)
256-
}
257-
}
258-
259-
if (!response || response.status !== 204) {
260-
throw new Error('E_BAD_RESP_CHE_API')
261-
}
262-
}
263-
264-
async createWorkspaceFromDevfile(devfileContent: string, accessToken?: string): Promise<chetypes.workspace.Workspace> {
265-
const endpoint = `${this.cheApiEndpoint}/workspace/devfile`
266-
const headers: any = { 'Content-Type': 'text/yaml' }
267-
if (accessToken) {
268-
headers.Authorization = accessToken
269-
}
270-
271-
let response: any
272-
try {
273-
response = await this.axios.post(endpoint, devfileContent, { headers })
274-
} catch (error) {
275-
if (error.response) {
276-
if (error.response.status === 400) {
277-
throw new Error(`E_BAD_DEVFILE_FORMAT - Message: ${error.response.data.message}`)
278-
}
279-
if (error.response.status === 409) {
280-
let message = ''
281-
if (error.response.data) {
282-
message = error.response.data.message
283-
}
284-
throw new Error(`E_CONFLICT - Message: ${message}`)
285-
}
286-
}
287-
288-
throw this.getCheApiError(error, endpoint)
289-
}
290-
291-
if (response && response.data) {
292-
return response.data as chetypes.workspace.Workspace
293-
} else {
294-
throw new Error('E_BAD_RESP_CHE_SERVER')
295-
}
296-
}
297-
298-
/**
299-
* Returns Keycloak settings or undefined for single user mode.
300-
*/
301-
async getKeycloakSettings(responseTimeoutMs = this.defaultCheResponseTimeoutMs): Promise<any | undefined> {
302-
const endpoint = `${this.cheApiEndpoint}/keycloak/settings`
303-
let response
304-
try {
305-
response = await this.axios.get(endpoint, { timeout: responseTimeoutMs })
306-
} catch (error) {
307-
if (error.response && error.response.status === 404) {
308-
return
309-
}
310-
throw this.getCheApiError(error, endpoint)
311-
}
312-
this.checkResponse(response, endpoint)
313-
if (!response.data['che.keycloak.token.endpoint']) {
314-
// The response is not keycloak response, but a default fallback
315-
throw new Error('E_BAD_CHE_API_URL')
316-
}
317-
return response.data
318-
}
319-
320-
async isAuthenticationEnabled(responseTimeoutMs = this.defaultCheResponseTimeoutMs): Promise<boolean> {
321-
const endpoint = `${this.cheApiEndpoint}/keycloak/settings`
322-
let response
323-
try {
324-
response = await this.axios.get(endpoint, { timeout: responseTimeoutMs })
325-
} catch (error) {
326-
if (error.response && (error.response.status === 404 || error.response.status === 503)) {
327-
return false
328-
} else {
329-
throw this.getCheApiError(error, endpoint)
330-
}
331-
}
332-
this.checkResponse(response, endpoint)
333-
if (!response.data['che.keycloak.token.endpoint']) {
334-
// The response is not keycloak response, but a default fallback
335-
return false
336-
}
337-
return true
338-
}
339-
340107
private checkResponse(response: any, endpoint?: string): void {
341108
if (!response || response.status !== 200 || !response.data) {
342109
throw new Error(`E_BAD_RESP_CHE_API - Response code: ${response.status}` + endpoint ? `, endpoint: ${endpoint}` : '')

0 commit comments

Comments
 (0)