Skip to content

Commit 6705b04

Browse files
committed
support debug workspace
1 parent f300465 commit 6705b04

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

src/heartbeat.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class HeartbeatManager extends Disposable {
2424
readonly gitpodHost: string,
2525
readonly workspaceId: string,
2626
readonly instanceId: string,
27+
readonly debugWorkspace: boolean,
2728
private readonly accessToken: string,
2829
private readonly publicApi: GitpodPublicApi | undefined,
2930
private readonly logger: Log,
@@ -113,7 +114,7 @@ export class HeartbeatManager extends Disposable {
113114
? (!wasClosed ? await this.publicApi.sendHeartbeat(this.workspaceId) : await this.publicApi.sendDidClose(this.workspaceId))
114115
: await service.server.sendHeartBeat({ instanceId: this.instanceId, wasClosed });
115116
if (wasClosed) {
116-
this.telemetry.sendTelemetryEvent('ide_close_signal', { workspaceId: this.workspaceId, instanceId: this.instanceId, gitpodHost: this.gitpodHost, clientKind: 'vscode' });
117+
this.telemetry.sendTelemetryEvent('ide_close_signal', { workspaceId: this.workspaceId, instanceId: this.instanceId, gitpodHost: this.gitpodHost, clientKind: 'vscode', debugWorkspace: String(!!this.debugWorkspace) });
117118
this.logger.trace('Send ' + suffix);
118119
}
119120
} else {

src/remoteConnector.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ interface SSHConnectionParams {
4444
workspaceId: string;
4545
instanceId: string;
4646
gitpodHost: string;
47+
debugWorkspace?: boolean;
4748
}
4849

4950
interface LocalAppConfig {
@@ -532,7 +533,7 @@ export default class RemoteConnector extends Disposable {
532533
return preferredIdentityKeys;
533534
}
534535

535-
private async getWorkspaceSSHDestination(session: vscode.AuthenticationSession, { workspaceId, gitpodHost }: SSHConnectionParams): Promise<{ destination: string; password?: string }> {
536+
private async getWorkspaceSSHDestination(session: vscode.AuthenticationSession, { workspaceId, gitpodHost, debugWorkspace }: SSHConnectionParams): Promise<{ destination: string; password?: string }> {
536537
const serviceUrl = new URL(gitpodHost);
537538
const sshKeysSupported = session.scopes.includes(ScopeFeature.SSHPublicKeys);
538539

@@ -560,13 +561,15 @@ export default class RemoteConnector extends Disposable {
560561
throw new NoSSHGatewayError(gitpodHost);
561562
}
562563

563-
const sshHostKeys = (await sshHostKeyResponse.json()) as { type: string; host_key: string }[];
564-
565-
const sshDestInfo = {
566-
user: workspaceId,
567-
// See https://github.com/gitpod-io/gitpod/pull/9786 for reasoning about `.ssh` suffix
568-
hostName: workspaceUrl.host.replace(workspaceId, `${workspaceId}.ssh`)
569-
};
564+
const sshHostKeys = (await sshHostKeyResponse.json()) as { type: string; host_key: string }[];
565+
let user = workspaceId;
566+
// See https://github.com/gitpod-io/gitpod/pull/9786 for reasoning about `.ssh` suffix
567+
let hostName = workspaceUrl.host.replace(workspaceId, `${workspaceId}.ssh`)
568+
if (debugWorkspace) {
569+
user = 'debug-' + workspaceId;
570+
hostName = hostName.replace(workspaceId, user);
571+
}
572+
const sshDestInfo = { user, hostName };
570573

571574
let verifiedHostKey: Buffer | undefined;
572575
// Test ssh connection first
@@ -584,7 +587,7 @@ export default class RemoteConnector extends Disposable {
584587
authHandler(_methodsLeft, _partialSuccess, _callback) {
585588
return {
586589
type: 'password',
587-
username: workspaceId,
590+
username: user,
588591
password: ownerToken,
589592
};
590593
},
@@ -636,7 +639,7 @@ export default class RemoteConnector extends Disposable {
636639
identityKeys = identityKeys.filter(k => !!registeredKeys.find(regKey => regKey.fingerprint === k.fingerprint));
637640
} else {
638641
if (identityKeys.length) {
639-
sshDestInfo.user = `${workspaceId}#${ownerToken}`;
642+
sshDestInfo.user = `${user}#${ownerToken}`;
640643
}
641644
const gitpodVersion = await getGitpodVersion(gitpodHost, this.logger);
642645
this.logger.warn(`Registered SSH public keys not supported in ${gitpodHost}, using version ${gitpodVersion.raw}`);
@@ -885,7 +888,8 @@ export default class RemoteConnector extends Disposable {
885888

886889
const usingSSHGateway = !!sshDestination;
887890
let localAppSSHConfigPath: string | undefined;
888-
if (!usingSSHGateway) {
891+
if (!usingSSHGateway && !params.debugWorkspace) {
892+
// debug workspace does not support local app mode
889893
const localAppFlow = { kind: 'local-app', userOverride, ...sshFlow };
890894
try {
891895
this.telemetry.sendUserFlowStatus('connecting', localAppFlow);
@@ -966,18 +970,18 @@ export default class RemoteConnector extends Disposable {
966970
return;
967971
}
968972

969-
this.heartbeatManager = new HeartbeatManager(connectionInfo.gitpodHost, connectionInfo.workspaceId, connectionInfo.instanceId, session.accessToken, this.publicApi, this.logger, this.telemetry);
973+
this.heartbeatManager = new HeartbeatManager(connectionInfo.gitpodHost, connectionInfo.workspaceId, connectionInfo.instanceId, !!connectionInfo.debugWorkspace, session.accessToken, this.publicApi, this.logger, this.telemetry);
970974

971975
// gitpod remote extension installation is async so sometimes gitpod-desktop will activate before gitpod-remote
972976
// let's try a few times for it to finish install
973977
try {
974978
await retry(async () => {
975979
await vscode.commands.executeCommand('__gitpod.cancelGitpodRemoteHeartbeat');
976980
}, 3000, 15);
977-
this.telemetry.sendTelemetryEvent('vscode_desktop_heartbeat_state', { enabled: String(true), gitpodHost: connectionInfo.gitpodHost, workspaceId: connectionInfo.workspaceId, instanceId: connectionInfo.instanceId, gitpodVersion: gitpodVersion.raw });
981+
this.telemetry.sendTelemetryEvent('vscode_desktop_heartbeat_state', { enabled: String(true), gitpodHost: connectionInfo.gitpodHost, workspaceId: connectionInfo.workspaceId, instanceId: connectionInfo.instanceId, debugWorkspace: String(!!connectionInfo.debugWorkspace), gitpodVersion: gitpodVersion.raw });
978982
} catch {
979983
this.logger.error(`Could not execute '__gitpod.cancelGitpodRemoteHeartbeat' command`);
980-
this.telemetry.sendTelemetryEvent('vscode_desktop_heartbeat_state', { enabled: String(false), gitpodHost: connectionInfo.gitpodHost, workspaceId: connectionInfo.workspaceId, instanceId: connectionInfo.instanceId, gitpodVersion: gitpodVersion.raw });
984+
this.telemetry.sendTelemetryEvent('vscode_desktop_heartbeat_state', { enabled: String(false), gitpodHost: connectionInfo.gitpodHost, workspaceId: connectionInfo.workspaceId, instanceId: connectionInfo.instanceId, debugWorkspace: String(!!connectionInfo.debugWorkspace), gitpodVersion: gitpodVersion.raw });
981985
}
982986
}
983987

0 commit comments

Comments
 (0)