From 048b18f887da988f6ba2f37e3f8d4da192aaffa7 Mon Sep 17 00:00:00 2001 From: Igor Vinokur Date: Mon, 6 Jul 2020 17:07:37 +0300 Subject: [PATCH 1/2] Align token request with hosted Che --- package.json | 3 ++- src/che-openshift-authentication.ts | 24 +++++++++++++++++++++++- yarn.lock | 20 +++++++++++++++++--- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 1962b7d..e0f5edf 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "@theia/plugin-packager": "latest", "rimraf": "2.6.2", "typescript-formatter": "7.2.2", - "typescript": "2.9.2" + "typescript": "2.9.2", + "axios": "0.19.2" }, "scripts": { "prepare": "yarn run clean && yarn run build", diff --git a/src/che-openshift-authentication.ts b/src/che-openshift-authentication.ts index 4649af5..781ba54 100644 --- a/src/che-openshift-authentication.ts +++ b/src/che-openshift-authentication.ts @@ -11,10 +11,26 @@ import * as theia from '@theia/plugin'; import * as che from '@eclipse-che/plugin'; import { spawn } from 'child_process'; +import axios, { AxiosInstance } from 'axios'; + +interface Attributes { + cluster: string +} + +interface Data { + attributes: Attributes +} + +interface OsUserResponse { + data: Data[] +} export async function start(context: theia.PluginContext) { const machineToken = process.env['CHE_MACHINE_TOKEN']; const isMultiUser = !!(machineToken && machineToken.length > 0); + const axiosInstance: AxiosInstance = axios; + const cheApi = process.env['CHE_API']; + const isHostedChe = cheApi && cheApi.indexOf('https://che.openshift.io/api') !== -1; // getProviders method is not supported for multi-user Mode if (isMultiUser) { if (!await che.oAuth.isRegistered('openshift-v3') && !await che.oAuth.isRegistered('openshift-v4')) { @@ -86,7 +102,13 @@ export async function start(context: theia.PluginContext) { } function getServerUrl(): Promise { - return new Promise((resolve, reject) => { + return new Promise(async (resolve, reject) => { + if (isHostedChe) { + const user = await che.user.getCurrentUser(); + const osUserResponse = await axiosInstance.get('https://api.openshift.io/api/users?filter[username]=' + user.name); + resolve(osUserResponse.data.data[0].attributes.cluster); + return; + } let result = ''; const versionCommand = spawn('odo', ['version']); // tslint:disable-next-line:no-any diff --git a/yarn.lock b/yarn.lock index 2515c1b..b08c600 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8,9 +8,9 @@ integrity sha512-4CgKEGCBOIOBGBNoH0dhN8TkP1Sj39fG4LGCXYw3JB7nQucVooJyq7AhIV+w7L4iZ+ln+y2KEfZugCmOIuzIeQ== "@eclipse-che/plugin@latest": - version "0.0.1-1586429785" - resolved "https://registry.yarnpkg.com/@eclipse-che/plugin/-/plugin-0.0.1-1586429785.tgz#6dea7faca00c261a9f14f45fd8398205f4948f62" - integrity sha512-C7VVc/XMPr52een6KIXnDCjZiOcelPTqy1uj2HcSOmBEpc/aXscIrpF8UE9UN+V5rr3GUlYlYGWJqTQFMjeILw== + version "0.0.1-1594040164" + resolved "https://registry.yarnpkg.com/@eclipse-che/plugin/-/plugin-0.0.1-1594040164.tgz#5501b9a032d989dd65dc32bc8044f61d6a6682f7" + integrity sha512-QOwu77veHvBmI/w1s8utCqa2mKUqEgIRgIByXQZsVO7Ba7GVqcnPRU/t4kSrKW41y525uHlkJor2iTk++ie3eQ== dependencies: "@eclipse-che/api" latest @@ -136,6 +136,13 @@ atob@^2.1.2: resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9" integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg== +axios@0.19.2: + version "0.19.2" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27" + integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA== + dependencies: + follow-redirects "1.5.10" + balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" @@ -501,6 +508,13 @@ find-up@^3.0.0: dependencies: locate-path "^3.0.0" +follow-redirects@1.5.10: + version "1.5.10" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a" + integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ== + dependencies: + debug "=3.1.0" + for-in@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" From 188d64d25d7b96ea6cce2735805f7fba3e9f01a2 Mon Sep 17 00:00:00 2001 From: Igor Vinokur Date: Mon, 6 Jul 2020 17:53:13 +0300 Subject: [PATCH 2/2] fixup! Align token request with hosted Che --- package.json | 2 +- yarn.lock | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index e0f5edf..ccffb6a 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "@theia/plugin-packager": "latest", "rimraf": "2.6.2", "typescript-formatter": "7.2.2", - "typescript": "2.9.2", + "typescript": "~3.9.2", "axios": "0.19.2" }, "scripts": { diff --git a/yarn.lock b/yarn.lock index b08c600..56dab43 100644 --- a/yarn.lock +++ b/yarn.lock @@ -366,6 +366,13 @@ cross-spawn@^5.0.1: shebang-command "^1.2.0" which "^1.2.9" +debug@=3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" + integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g== + dependencies: + ms "2.0.0" + debug@^2.2.0, debug@^2.3.3: version "2.6.9" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" @@ -1402,10 +1409,10 @@ typescript-formatter@7.2.2: commandpost "^1.0.0" editorconfig "^0.15.0" -typescript@2.9.2: - version "2.9.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c" - integrity sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w== +typescript@~3.9.2: + version "3.9.6" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a" + integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw== union-value@^1.0.0: version "1.0.1"