Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 698b6d4

Browse files
authored
Merge pull request #3 from che-incubator/alignWithHostedChe
Align token request with hosted Che
2 parents 807c9c7 + 188d64d commit 698b6d4

File tree

3 files changed

+53
-9
lines changed

3 files changed

+53
-9
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"@theia/plugin-packager": "latest",
1919
"rimraf": "2.6.2",
2020
"typescript-formatter": "7.2.2",
21-
"typescript": "2.9.2"
21+
"typescript": "~3.9.2",
22+
"axios": "0.19.2"
2223
},
2324
"scripts": {
2425
"prepare": "yarn run clean && yarn run build",

src/che-openshift-authentication.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,26 @@
1111
import * as theia from '@theia/plugin';
1212
import * as che from '@eclipse-che/plugin';
1313
import { spawn } from 'child_process';
14+
import axios, { AxiosInstance } from 'axios';
15+
16+
interface Attributes {
17+
cluster: string
18+
}
19+
20+
interface Data {
21+
attributes: Attributes
22+
}
23+
24+
interface OsUserResponse {
25+
data: Data[]
26+
}
1427

1528
export async function start(context: theia.PluginContext) {
1629
const machineToken = process.env['CHE_MACHINE_TOKEN'];
1730
const isMultiUser = !!(machineToken && machineToken.length > 0);
31+
const axiosInstance: AxiosInstance = axios;
32+
const cheApi = process.env['CHE_API'];
33+
const isHostedChe = cheApi && cheApi.indexOf('https://che.openshift.io/api') !== -1;
1834
// getProviders method is not supported for multi-user Mode
1935
if (isMultiUser) {
2036
if (!await che.oAuth.isRegistered('openshift-v3') && !await che.oAuth.isRegistered('openshift-v4')) {
@@ -86,7 +102,13 @@ export async function start(context: theia.PluginContext) {
86102
}
87103

88104
function getServerUrl(): Promise<string> {
89-
return new Promise<string>((resolve, reject) => {
105+
return new Promise<string>(async (resolve, reject) => {
106+
if (isHostedChe) {
107+
const user = await che.user.getCurrentUser();
108+
const osUserResponse = await axiosInstance.get<OsUserResponse>('https://api.openshift.io/api/users?filter[username]=' + user.name);
109+
resolve(osUserResponse.data.data[0].attributes.cluster);
110+
return;
111+
}
90112
let result = '';
91113
const versionCommand = spawn('odo', ['version']);
92114
// tslint:disable-next-line:no-any

yarn.lock

+28-7
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
integrity sha512-4CgKEGCBOIOBGBNoH0dhN8TkP1Sj39fG4LGCXYw3JB7nQucVooJyq7AhIV+w7L4iZ+ln+y2KEfZugCmOIuzIeQ==
99

1010
"@eclipse-che/plugin@latest":
11-
version "0.0.1-1586429785"
12-
resolved "https://registry.yarnpkg.com/@eclipse-che/plugin/-/plugin-0.0.1-1586429785.tgz#6dea7faca00c261a9f14f45fd8398205f4948f62"
13-
integrity sha512-C7VVc/XMPr52een6KIXnDCjZiOcelPTqy1uj2HcSOmBEpc/aXscIrpF8UE9UN+V5rr3GUlYlYGWJqTQFMjeILw==
11+
version "0.0.1-1594040164"
12+
resolved "https://registry.yarnpkg.com/@eclipse-che/plugin/-/plugin-0.0.1-1594040164.tgz#5501b9a032d989dd65dc32bc8044f61d6a6682f7"
13+
integrity sha512-QOwu77veHvBmI/w1s8utCqa2mKUqEgIRgIByXQZsVO7Ba7GVqcnPRU/t4kSrKW41y525uHlkJor2iTk++ie3eQ==
1414
dependencies:
1515
"@eclipse-che/api" latest
1616

@@ -136,6 +136,13 @@ atob@^2.1.2:
136136
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
137137
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==
138138

139+
axios@0.19.2:
140+
version "0.19.2"
141+
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27"
142+
integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==
143+
dependencies:
144+
follow-redirects "1.5.10"
145+
139146
balanced-match@^1.0.0:
140147
version "1.0.0"
141148
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
@@ -359,6 +366,13 @@ cross-spawn@^5.0.1:
359366
shebang-command "^1.2.0"
360367
which "^1.2.9"
361368

369+
debug@=3.1.0:
370+
version "3.1.0"
371+
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
372+
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
373+
dependencies:
374+
ms "2.0.0"
375+
362376
debug@^2.2.0, debug@^2.3.3:
363377
version "2.6.9"
364378
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
@@ -501,6 +515,13 @@ find-up@^3.0.0:
501515
dependencies:
502516
locate-path "^3.0.0"
503517

518+
follow-redirects@1.5.10:
519+
version "1.5.10"
520+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
521+
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
522+
dependencies:
523+
debug "=3.1.0"
524+
504525
for-in@^1.0.2:
505526
version "1.0.2"
506527
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
@@ -1388,10 +1409,10 @@ typescript-formatter@7.2.2:
13881409
commandpost "^1.0.0"
13891410
editorconfig "^0.15.0"
13901411

1391-
typescript@2.9.2:
1392-
version "2.9.2"
1393-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c"
1394-
integrity sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==
1412+
typescript@~3.9.2:
1413+
version "3.9.6"
1414+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a"
1415+
integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==
13951416

13961417
union-value@^1.0.0:
13971418
version "1.0.1"

0 commit comments

Comments
 (0)