Skip to content

Commit

Permalink
chore: Delete auth and workspace command groups (#1910)
Browse files Browse the repository at this point in the history
* Delete auth and workspace command groups

Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
Signed-off-by: Anatolii Bazko <abazko@redhat.com>
Co-authored-by: Anatolii Bazko <abazko@redhat.com>
  • Loading branch information
mmorhun and tolusha authored Dec 24, 2021
1 parent 2bc4a9d commit 78565e0
Show file tree
Hide file tree
Showing 31 changed files with 94 additions and 3,623 deletions.
13 changes: 0 additions & 13 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@
},
"group": "build"
},
{
"label": "[Minikube] Install Che with custom che-operator and che-server images",
"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",
"type": "shell",
"args": [],
"problemMatcher": [
"$tsc"
],
"presentation": {
"reveal": "always"
},
"group": "build"
},
{
"label": "[Openshift] Install Che",
"command": "./bin/run server:deploy -n che -m -p openshift",
Expand Down
529 changes: 44 additions & 485 deletions README.md

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
"countries-and-timezones": "^3.2.3",
"debug": "^4.3.2",
"eclipse-che-operator": "git://github.com/eclipse-che/che-operator#main",
"esprima": "^4.0.1",
"execa": "^5.1.1",
"fancy-test": "^1.4.9",
"fs-extra": "^10.0.0",
"getos": "^3.2.1",
"gnirts": "^1.1.7",
"inquirer": "^8.2.0",
"js-yaml": "^4.0.2",
"listr": "^0.14.3",
"listr-verbose-renderer": "^0.6.0",
Expand All @@ -39,10 +37,8 @@
"node-forge": "^0.10.0",
"node-notifier": "^10.0.0",
"os-locale": "^5.0.0",
"querystring": "^0.2.1",
"rimraf": "^3.0.2",
"semver": "^7.3.4",
"stream-buffers": "^3.0.2",
"tslib": "^2",
"unzipper": "0.10.11",
"uuid": "^8.3.2"
Expand Down Expand Up @@ -73,13 +69,11 @@
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"chai": "^4.3.4",
"cpx": "^1.5.0",
"eslint": "^7.32.0",
"eslint-config-oclif": "^3.1.0",
"eslint-config-oclif-typescript": "^0.2.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-no-null": "^1.0.2",
"globby": "^11",
"jest": "^26.6.3",
"nock": "^13.2.1",
"ts-jest": "^26.5.6",
Expand Down Expand Up @@ -157,7 +151,6 @@
"test": "jest --collect-coverage",
"test-watch": "jest --watchAll",
"e2e-minikube-operator": "export PLATFORM=minikube && export INSTALLER=operator && yarn jest ./test/e2e/e2e.test.ts --testRegex='/test/(e2e)/.*.test.ts'",
"e2e-minishift": "export PLATFORM=minishift && export INSTALLER=operator && yarn jest ./test/e2e/e2e.test.ts --testRegex='/test/(e2e)/.*.test.ts'",
"e2e-openshift": "export PLATFORM=openshift && export INSTALLER=operator && yarn jest ./test/e2e/e2e.test.ts --testRegex='/test/(e2e)/.*.test.ts'",
"gnirts-ci": "node .ci/obfuscate/gnirts.js",
"prepack": "yarn lint && rm -rf lib && rm -rf tsconfig.tsbuildinfo && tsc -b && oclif-dev manifest && oclif-dev readme && yarn gnirts-ci",
Expand Down
233 changes: 0 additions & 233 deletions src/api/che-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
* Red Hat, Inc. - initial API and implementation
*/

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

import { newError, sleep } from '../util'
Expand Down Expand Up @@ -106,237 +104,6 @@ export class CheApiClient {
return response.data.status
}

async startCheServerShutdown(accessToken = '', responseTimeoutMs = this.defaultCheResponseTimeoutMs): Promise<void> {
const endpoint = `${this.cheApiEndpoint}/system/stop?shutdown=true`
const headers = accessToken ? { Authorization: accessToken } : null
let response = null
try {
response = await this.axios.post(endpoint, null, { headers, timeout: responseTimeoutMs })
} catch (error) {
if (error.response && error.response.status === 409) {
return
} else {
throw this.getCheApiError(error, endpoint)
}
}
if (!response || response.status !== 204) {
throw new Error('E_BAD_RESP_CHE_API')
}
}

async waitUntilCheServerReadyToShutdown(intervalMs = 500, timeoutMs = 60000): Promise<void> {
const iterations = timeoutMs / intervalMs
for (let index = 0; index < iterations; index++) {
const status = await this.getCheServerStatus()
if (status === 'READY_TO_SHUTDOWN') {
return
}
await cli.wait(intervalMs)
}
throw new Error('ERR_TIMEOUT')
}

/**
* Returns list of all workspaces of the user.
*/
async getAllWorkspaces(accessToken?: string): Promise<chetypes.workspace.Workspace[]> {
const all: chetypes.workspace.Workspace[] = []
const itemsPerPage = 30

let skipCount = 0
let workspaces: chetypes.workspace.Workspace[]
do {
workspaces = await this.getWorkspaces(skipCount, itemsPerPage, accessToken)
all.push(...workspaces)
skipCount += workspaces.length
} while (workspaces.length === itemsPerPage)

return all
}

/**
* Returns list of workspaces in given range.
* If lst of all workspaces is needed, getAllWorkspaces should be used insted.
*/
async getWorkspaces(skipCount = 0, maxItems = 30, accessToken?: string): Promise<chetypes.workspace.Workspace[]> {
const endpoint = `${this.cheApiEndpoint}/workspace?skipCount=${skipCount}&maxItems=${maxItems}`
const headers: any = { 'Content-Type': 'text/yaml' }
if (accessToken && accessToken.length > 0) {
headers.Authorization = accessToken
}

try {
const response = await this.axios.get(endpoint, { headers })
if (response && response.data) {
return response.data
} else {
throw new Error('E_BAD_RESP_CHE_SERVER')
}
} catch (error) {
throw this.getCheApiError(error, endpoint)
}
}

async getWorkspaceById(workspaceId: string, accessToken?: string): Promise<chetypes.workspace.Workspace> {
const endpoint = `${this.cheApiEndpoint}/workspace/${workspaceId}`
const headers: any = { 'Content-Type': 'text/yaml' }
if (accessToken) {
headers.Authorization = accessToken
}

try {
const response = await this.axios.get(endpoint, { headers })
return response.data
} catch (error) {
if (error.response.status === 404) {
throw new Error(`Workspace ${workspaceId} not found. Please use the command workspace:list to get list of the existed workspaces.`)
}
throw this.getCheApiError(error, endpoint)
}
}

async deleteWorkspaceById(workspaceId: string, accessToken?: string): Promise<void> {
const endpoint = `${this.cheApiEndpoint}/workspace/${workspaceId}`
const headers: any = {}
if (accessToken) {
headers.Authorization = accessToken
}

try {
await this.axios.delete(endpoint, { headers })
} catch (error) {
if (error.response.status === 404) {
throw new Error(`Workspace ${workspaceId} not found. Please use the command workspace:list to get list of the existed workspaces.`)
} else if (error.response.status === 409) {
throw new Error('Cannot delete a running workspace. Please stop it using the command workspace:stop and try again')
}
throw this.getCheApiError(error, endpoint)
}
}

async startWorkspace(workspaceId: string, debug: boolean, accessToken?: string): Promise<void> {
let endpoint = `${this.cheApiEndpoint}/workspace/${workspaceId}/runtime`
if (debug) {
endpoint += '?debug-workspace-start=true'
}
let response

const headers: { [key: string]: string } = {}
if (accessToken) {
headers.Authorization = accessToken
}
try {
response = await this.axios.post(endpoint, undefined, { headers })
} catch (error) {
if (error.response && error.response.status === 404) {
throw new Error(`E_WORKSPACE_NOT_EXIST - workspace with "${workspaceId}" id doesn't exist`)
} else {
throw this.getCheApiError(error, endpoint)
}
}

this.checkResponse(response, endpoint)
}

async stopWorkspace(workspaceId: string, accessToken?: string): Promise<void> {
const endpoint = `${this.cheApiEndpoint}/workspace/${workspaceId}/runtime`
let response

const headers: { [key: string]: string } = {}
if (accessToken) {
headers.Authorization = accessToken
}
try {
response = await this.axios.delete(endpoint, { headers })
} catch (error) {
if (error.response && error.response.status === 404) {
throw new Error(`E_WORKSPACE_NOT_EXIST - workspace with "${workspaceId}" id doesn't exist`)
} else {
throw this.getCheApiError(error, endpoint)
}
}

if (!response || response.status !== 204) {
throw new Error('E_BAD_RESP_CHE_API')
}
}

async createWorkspaceFromDevfile(devfileContent: string, accessToken?: string): Promise<chetypes.workspace.Workspace> {
const endpoint = `${this.cheApiEndpoint}/workspace/devfile`
const headers: any = { 'Content-Type': 'text/yaml' }
if (accessToken) {
headers.Authorization = accessToken
}

let response: any
try {
response = await this.axios.post(endpoint, devfileContent, { headers })
} catch (error) {
if (error.response) {
if (error.response.status === 400) {
throw new Error(`E_BAD_DEVFILE_FORMAT - Message: ${error.response.data.message}`)
}
if (error.response.status === 409) {
let message = ''
if (error.response.data) {
message = error.response.data.message
}
throw new Error(`E_CONFLICT - Message: ${message}`)
}
}

throw this.getCheApiError(error, endpoint)
}

if (response && response.data) {
return response.data as chetypes.workspace.Workspace
} else {
throw new Error('E_BAD_RESP_CHE_SERVER')
}
}

/**
* Returns Keycloak settings or undefined for single user mode.
*/
async getKeycloakSettings(responseTimeoutMs = this.defaultCheResponseTimeoutMs): Promise<any | undefined> {
const endpoint = `${this.cheApiEndpoint}/keycloak/settings`
let response
try {
response = await this.axios.get(endpoint, { timeout: responseTimeoutMs })
} catch (error) {
if (error.response && error.response.status === 404) {
return
}
throw this.getCheApiError(error, endpoint)
}
this.checkResponse(response, endpoint)
if (!response.data['che.keycloak.token.endpoint']) {
// The response is not keycloak response, but a default fallback
throw new Error('E_BAD_CHE_API_URL')
}
return response.data
}

async isAuthenticationEnabled(responseTimeoutMs = this.defaultCheResponseTimeoutMs): Promise<boolean> {
const endpoint = `${this.cheApiEndpoint}/keycloak/settings`
let response
try {
response = await this.axios.get(endpoint, { timeout: responseTimeoutMs })
} catch (error) {
if (error.response && (error.response.status === 404 || error.response.status === 503)) {
return false
} else {
throw this.getCheApiError(error, endpoint)
}
}
this.checkResponse(response, endpoint)
if (!response.data['che.keycloak.token.endpoint']) {
// The response is not keycloak response, but a default fallback
return false
}
return true
}

private checkResponse(response: any, endpoint?: string): void {
if (!response || response.status !== 200 || !response.data) {
throw new Error(`E_BAD_RESP_CHE_API - Response code: ${response.status}` + endpoint ? `, endpoint: ${endpoint}` : '')
Expand Down
Loading

0 comments on commit 78565e0

Please sign in to comment.