-
Notifications
You must be signed in to change notification settings - Fork 1
Align token request with hosted Che #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't it looking wired to hardcode an hosted platform there ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean, for example there is preview platform as well, etc, so maybe we need another way of saying it's an 'hosted che' ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have any other ideas how to detect |
||
// 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<string> { | ||
return new Promise<string>((resolve, reject) => { | ||
return new Promise<string>(async (resolve, reject) => { | ||
if (isHostedChe) { | ||
const user = await che.user.getCurrentUser(); | ||
const osUserResponse = await axiosInstance.get<OsUserResponse>('https://api.openshift.io/api/users?filter[username]=' + user.name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's possible to remove declarations of
WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This request is redundant in case when the plugin doesn't run on Hosted Che |
||
resolve(osUserResponse.data.data[0].attributes.cluster); | ||
return; | ||
} | ||
let result = ''; | ||
const versionCommand = spawn('odo', ['version']); | ||
// tslint:disable-next-line:no-any | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we somehow avoid hardcoding of domain name here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can make an API request but I think it is not a good solution.