Skip to content

Commit 350159f

Browse files
authored
separate local ssh and gateway (ssh flow) (#74)
* separate local ssh and gateway (ssh flow) * add useLocalSSH property
1 parent ea3040b commit 350159f

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

src/remoteConnector.ts

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -687,40 +687,51 @@ export class RemoteConnector extends Disposable {
687687
this.usePublicApi = await this.experiments.getUsePublicAPI(params.gitpodHost);
688688
this.logService.info(`Going to use ${this.usePublicApi ? 'public' : 'server'} API`);
689689

690-
let useLocalSSH = await this.experiments.getUseLocalSSHProxy();
691-
if (useLocalSSH) {
692-
// If needed, revert local-app changes first
693-
await this.updateRemoteSSHConfig(true, undefined);
694-
695-
this.localSSHService.flow = sshFlow;
696-
const [isSupportLocalSSH, isExtensionServerReady] = await Promise.all([
697-
this.localSSHService.initialize(),
698-
this.localSSHService.extensionServerReady()
699-
]);
700-
if (!isExtensionServerReady) {
701-
this.logService.error('Extension IPC server is not ready');
702-
useLocalSSH = false;
703-
}
704-
if (!isSupportLocalSSH) {
705-
this.logService.error('Local SSH is not supported on this platform');
706-
useLocalSSH = false;
707-
}
708-
}
709-
if (useLocalSSH) {
710-
this.logService.info('Going to use lssh');
711-
}
712-
713690
const forceUseLocalApp = Configuration.getUseLocalApp();
714691
const userOverride = String(isUserOverrideSetting('gitpod.remote.useLocalApp'));
715692
let sshDestination: SSHDestination | undefined;
716-
if (!forceUseLocalApp) {
693+
const useLocalSSH = await this.experiments.getUseLocalSSHProxy();
694+
sshFlow.useLocalSSH = String(useLocalSSH);
695+
if (!forceUseLocalApp && useLocalSSH) {
696+
const openSSHVersion = await getOpenSSHVersion();
697+
const localSSHFlow: UserFlowTelemetryProperties = { kind: 'local-ssh', openSSHVersion, userOverride, ...sshFlow };
698+
try {
699+
this.telemetryService.sendUserFlowStatus('connecting', localSSHFlow);
700+
// If needed, revert local-app changes first
701+
await this.updateRemoteSSHConfig(true, undefined);
702+
703+
this.localSSHService.flow = sshFlow;
704+
const [isSupportLocalSSH, isExtensionServerReady] = await Promise.all([
705+
this.localSSHService.initialize(),
706+
this.localSSHService.extensionServerReady()
707+
]);
708+
if (!isExtensionServerReady) {
709+
throw new Error('NoExtensionIPCServer')
710+
}
711+
if (!isSupportLocalSSH) {
712+
throw new Error('NoLocalSSHSupport')
713+
}
714+
this.logService.info('Going to use lssh');
715+
716+
const { destination } = await this.getLocalSSHWorkspaceSSHDestination(params);
717+
params.connType = 'local-ssh';
718+
sshDestination = destination;
719+
720+
this.telemetryService.sendUserFlowStatus('connected', localSSHFlow);
721+
} catch (e) {
722+
this.telemetryService.sendUserFlowStatus('failed', { ...localSSHFlow, reason: e.toString() });
723+
this.logService.error(`Local SSH: failed to connect to ${params.workspaceId} Gitpod workspace:`, e);
724+
}
725+
}
726+
727+
if (!forceUseLocalApp && sshDestination === undefined) {
717728
const openSSHVersion = await getOpenSSHVersion();
718-
const gatewayFlow: UserFlowTelemetryProperties = { kind: useLocalSSH ? 'local-ssh' : 'gateway', openSSHVersion, userOverride, ...sshFlow };
729+
const gatewayFlow: UserFlowTelemetryProperties = { kind: 'gateway', openSSHVersion, userOverride, ...sshFlow };
719730
try {
720731
this.telemetryService.sendUserFlowStatus('connecting', gatewayFlow);
721732

722-
const { destination, password } = useLocalSSH ? await this.getLocalSSHWorkspaceSSHDestination(params) : await this.getWorkspaceSSHDestination(params);
723-
params.connType = useLocalSSH ? 'local-ssh' : 'ssh-gateway';
733+
const { destination, password } = await this.getWorkspaceSSHDestination(params);
734+
params.connType = 'ssh-gateway';
724735

725736
sshDestination = destination;
726737

@@ -771,7 +782,7 @@ export class RemoteConnector extends Disposable {
771782

772783
const usingSSHGateway = !!sshDestination;
773784
let localAppSSHConfigPath: string | undefined;
774-
if (!usingSSHGateway && !params.debugWorkspace) {
785+
if (sshDestination === undefined && !params.debugWorkspace) {
775786
// debug workspace does not support local app mode
776787
const localAppFlow = { kind: 'local-app', userOverride, ...sshFlow };
777788
try {

0 commit comments

Comments
 (0)