Skip to content

Commit

Permalink
Fix auth codenvy issue 1917 by using machine Token when discussing wi…
Browse files Browse the repository at this point in the history
…th WS Agent

Change-Id: I8f01dba956c698bdc0c96ca29f48b8705726e0e0
Signed-off-by: Florent BENOIT <fbenoit@codenvy.com>
  • Loading branch information
benoitf committed Mar 17, 2017
1 parent 4521969 commit f3ef223
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export class DiagnosticsRunningWorkspaceCheck {
*/
checkWebSocketWsAgent(diagnosticCallback : DiagnosticCallback) : ng.IPromise {
let workspace: che.IWorkspace = diagnosticCallback.getShared('workspace');
let machineToken: string = diagnosticCallback.getShared('machineToken');

let wsAgentSocketWebLink = this.lodash.find(workspace.runtime.links, (link: any) => {
return link.rel === 'wsagent.websocket';
Expand All @@ -166,6 +167,10 @@ export class DiagnosticsRunningWorkspaceCheck {
} else {
wsAgentSocketWebLink = wsAgentSocketWebLink.href;
}
if (machineToken) {
wsAgentSocketWebLink += '?token=' + machineToken;
}

let wsAgentRemoteBus : MessageBus = this.cheWebsocket.getRemoteBus(wsAgentSocketWebLink);
diagnosticCallback.setMessageBus(wsAgentRemoteBus);

Expand Down Expand Up @@ -201,8 +206,15 @@ export class DiagnosticsRunningWorkspaceCheck {
* @returns {Promise}
*/
callSCM(diagnosticCallback : DiagnosticCallback, wsAgentHRef : string, errorInsteadOfFailure : boolean) : ng.IPromise {

let uriWsAgent : string = wsAgentHRef + '/';
let machineToken: string = diagnosticCallback.getShared('machineToken');
if (machineToken) {
uriWsAgent += '?token=' + machineToken;
}

// connect to the workspace agent
let resourceAPI : any = this.$resource(wsAgentHRef + '/', {}, {
let resourceAPI : any = this.$resource(uriWsAgent, {}, {
getDetails: {method: 'OPTIONS', timeout : 15000}
}, {
stripTrailingSlashes: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ export class DiagnosticsWorkspaceStartCheck {
this.workspaceCallback.stateRunning('RUNNING');
this.cheWorkspace.fetchWorkspaces().then(() => {
let workspace = diagnosticCallback.getShared('workspace');
let workspaceId = workspace.id;
this.cheWorkspace.fetchWorkspaceDetails(workspace.id).then(() => {
diagnosticCallback.shared('workspace', this.cheWorkspace.getWorkspaceById(workspace.id));
let workspace = this.cheWorkspace.getWorkspaceById(workspaceId);
diagnosticCallback.shared('workspace', workspace);
diagnosticCallback.shared('machineToken', workspace.runtime.devMachine.runtime.envVariables['USER_TOKEN']);
diagnosticCallback.success('Starting workspace OK');
})
});
Expand Down Expand Up @@ -248,8 +251,11 @@ export class DiagnosticsWorkspaceStartCheck {
}
hint += 'specific to your environment. See the `' + this.cheBranding.getCLI().configName + '` file for specifics.';
diagnosticCallback.notifyFailure('The workspace started, but ' + this.cheBranding.getName() + ' <--> Workspace connection not established', hint);
let workspaceId = workspace.id;
this.cheWorkspace.fetchWorkspaceDetails(workspace.id).then(() => {
diagnosticCallback.shared('workspace', this.cheWorkspace.getWorkspaceById(workspace.id));
let workspace = this.cheWorkspace.getWorkspaceById(workspaceId);
diagnosticCallback.shared('workspace', workspace);
diagnosticCallback.shared('machineToken', workspace.runtime.devMachine.runtime.envVariables['USER_TOKEN']);
let newCallback : DiagnosticCallback = diagnosticCallback.newCallback('Test connection from browser to workspace agent by using Workspace Agent IP');
this.diagnosticsRunningWorkspaceCheck.checkWsAgent(newCallback, false);
let websocketCallback : DiagnosticCallback = diagnosticCallback.newCallback('Test connection from browser to workspace agent with websocket');
Expand Down

0 comments on commit f3ef223

Please sign in to comment.