Skip to content

Commit

Permalink
Wider support vscode support (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanp413 authored Oct 4, 2023
1 parent fcc9b6e commit deb627f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/commands/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ export class ConnectInCurrentWindowCommand implements Command {

private async initializeLocalSSH(workspaceId: string) {
try {
await this.remoteService.updateRemoteSSHConfig(true, undefined);
await Promise.all([
this.remoteService.setupSSHProxy(),
this.remoteService.startLocalSSHServiceServer()
Expand Down
31 changes: 6 additions & 25 deletions src/remoteConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,31 +580,12 @@ export class RemoteConnector extends Disposable {
});
}

private async updateRemoteSSHConfig(usingSSHGateway: boolean, localAppSSHConfigPath: string | undefined) {
const remoteSSHconfig = vscode.workspace.getConfiguration('remote.SSH');
const defaultExtConfigInfo = remoteSSHconfig.inspect<string[]>('defaultExtensions');
const defaultExtensions = defaultExtConfigInfo?.globalValue ?? [];
if (!defaultExtensions.includes('gitpod.gitpod-remote-ssh')) {
defaultExtensions.unshift('gitpod.gitpod-remote-ssh');
await remoteSSHconfig.update('defaultExtensions', defaultExtensions, vscode.ConfigurationTarget.Global);
}

const currentConfigFile = remoteSSHconfig.get<string>('configFile');
if (usingSSHGateway) {
if (currentConfigFile?.includes('gitpod_ssh_config')) {
await remoteSSHconfig.update('configFile', undefined, vscode.ConfigurationTarget.Global);
}
} else {
// TODO(ak) notify a user about config file changes?
if (currentConfigFile === localAppSSHConfigPath) {
// invalidate cached SSH targets from the current config file
await remoteSSHconfig.update('configFile', undefined, vscode.ConfigurationTarget.Global);
}
await remoteSSHconfig.update('configFile', localAppSSHConfigPath, vscode.ConfigurationTarget.Global);
private async ensureRemoteSSHExtInstalled(flow: UserFlowTelemetryProperties): Promise<boolean> {
const isOfficialVscode = vscode.env.uriScheme === 'vscode' || vscode.env.uriScheme === 'vscode-insiders';
if (!isOfficialVscode) {
return true;
}
}

private async ensureRemoteSSHExtInstalled(flow: UserFlowTelemetryProperties): Promise<boolean> {
const msVscodeRemoteExt = vscode.extensions.getExtension('ms-vscode-remote.remote-ssh');
if (msVscodeRemoteExt) {
return true;
Expand Down Expand Up @@ -704,7 +685,7 @@ export class RemoteConnector extends Disposable {
try {
this.telemetryService.sendUserFlowStatus('connecting', localSSHFlow);
// If needed, revert local-app changes first
await this.updateRemoteSSHConfig(true, undefined);
await this.remoteService.updateRemoteSSHConfig(true, undefined);

this.remoteService.flow = sshFlow;
await Promise.all([
Expand Down Expand Up @@ -834,7 +815,7 @@ export class RemoteConnector extends Disposable {
}
}

await this.updateRemoteSSHConfig(usingSSHGateway, localAppSSHConfigPath);
await this.remoteService.updateRemoteSSHConfig(usingSSHGateway, localAppSSHConfigPath);

await this.context.globalState.update(`${SSH_DEST_KEY}${sshDestination!.toRemoteSSHString()}`, { ...params } as SSHConnectionParams);

Expand Down
30 changes: 28 additions & 2 deletions src/services/remoteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface IRemoteService {
getWorkspaceSSHDestination(wsData: WorkspaceData): Promise<{ destination: SSHDestination; password?: string }>;
showSSHPasswordModal(wsData: WorkspaceData, password: string): Promise<void>;

updateRemoteSSHConfig(usingSSHGateway: boolean, localAppSSHConfigPath: string | undefined): Promise<void>;
initializeRemoteExtensions(): Promise<void>;
}

Expand Down Expand Up @@ -177,11 +178,12 @@ export class RemoteService extends Disposable implements IRemoteService {
await SSHConfiguration.saveGitpodSSHConfig(gitpodConfig);
}

private getHostSSHConfig(host: string, launcher: string, proxyScript: string, extIpcPort: number, logLevel:string) {
private getHostSSHConfig(host: string, launcher: string, proxyScript: string, extIpcPort: number, logLevel: string) {
const extraArgs = (process.versions['electron'] && process.versions['microsoft-build']) ? '--ms-enable-electron-run-as-node' : '';
return {
Host: '*.' + getLocalSSHDomain(host),
StrictHostKeyChecking: 'no',
ProxyCommand: `"${launcher}" "${process.execPath}" "${proxyScript}" --ms-enable-electron-run-as-node %h ${extIpcPort} ${vscode.env.machineId} ${logLevel}`
ProxyCommand: `"${launcher}" "${process.execPath}" "${proxyScript}" ${extraArgs} %h ${extIpcPort} ${vscode.env.machineId} ${logLevel}`
};
}

Expand Down Expand Up @@ -326,6 +328,30 @@ export class RemoteService extends Disposable implements IRemoteService {
throw new Error('SSH password modal dialog, Canceled');
}

async updateRemoteSSHConfig(usingSSHGateway: boolean, localAppSSHConfigPath: string | undefined) {
const remoteSSHconfig = vscode.workspace.getConfiguration('remote.SSH');
const defaultExtConfigInfo = remoteSSHconfig.inspect<string[]>('defaultExtensions');
const defaultExtensions = defaultExtConfigInfo?.globalValue ?? [];
if (!defaultExtensions.includes('gitpod.gitpod-remote-ssh')) {
defaultExtensions.unshift('gitpod.gitpod-remote-ssh');
await remoteSSHconfig.update('defaultExtensions', defaultExtensions, vscode.ConfigurationTarget.Global);
}

const currentConfigFile = remoteSSHconfig.get<string>('configFile');
if (usingSSHGateway) {
if (currentConfigFile?.includes('gitpod_ssh_config')) {
await remoteSSHconfig.update('configFile', undefined, vscode.ConfigurationTarget.Global);
}
} else {
// TODO(ak) notify a user about config file changes?
if (currentConfigFile === localAppSSHConfigPath) {
// invalidate cached SSH targets from the current config file
await remoteSSHconfig.update('configFile', undefined, vscode.ConfigurationTarget.Global);
}
await remoteSSHconfig.update('configFile', localAppSSHConfigPath, vscode.ConfigurationTarget.Global);
}
}

async initializeRemoteExtensions() {
let flowData = this.flow ?? { gitpodHost: this.hostService.gitpodHost, userId: this.sessionService.safeGetUserId() };
flowData = { ...flowData, flow: 'sync_local_extensions', useLocalAPP: String(Configuration.getUseLocalApp()) };
Expand Down

0 comments on commit deb627f

Please sign in to comment.