Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow tunnel factory providers to opt out of protocol support #202067

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/vs/platform/remote/common/remoteAuthorityResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface TunnelInformation {
elevation: boolean;
public?: boolean;
privacyOptions: TunnelPrivacy[];
protocol: boolean;
};
}

Expand Down
8 changes: 8 additions & 0 deletions src/vs/platform/tunnel/common/tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface TunnelProviderFeatures {
*/
public?: boolean;
privacyOptions: TunnelPrivacy[];
protocol: boolean;
}

export interface ITunnelProvider {
Expand Down Expand Up @@ -126,6 +127,7 @@ export interface ITunnelService {
readonly onTunnelOpened: Event<RemoteTunnel>;
readonly onTunnelClosed: Event<{ host: string; port: number }>;
readonly canElevate: boolean;
readonly canChangeProtocol: boolean;
readonly hasTunnelProvider: boolean;
readonly onAddedTunnelProvider: Event<void>;

Expand Down Expand Up @@ -208,6 +210,7 @@ export abstract class AbstractTunnelService implements ITunnelService {
protected readonly _tunnels = new Map</*host*/ string, Map</* port */ number, { refcount: number; readonly value: Promise<RemoteTunnel | string | undefined> }>>();
protected _tunnelProvider: ITunnelProvider | undefined;
protected _canElevate: boolean = false;
private _canChangeProtocol: boolean = true;
private _privacyOptions: TunnelPrivacy[] = [];
private _factoryInProgress: Set<number/*port*/> = new Set();

Expand Down Expand Up @@ -250,6 +253,11 @@ export abstract class AbstractTunnelService implements ITunnelService {
setTunnelFeatures(features: TunnelProviderFeatures): void {
this._canElevate = features.elevation;
this._privacyOptions = features.privacyOptions;
this._canChangeProtocol = features.protocol;
}

public get canChangeProtocol(): boolean {
return this._canChangeProtocol;
}

public get canElevate(): boolean {
Expand Down
6 changes: 5 additions & 1 deletion src/vs/workbench/api/common/extHostExtensionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,11 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme

const tunnelInformation: TunnelInformation = {
environmentTunnels: result.environmentTunnels,
features: result.tunnelFeatures
features: result.tunnelFeatures ? {
elevation: result.tunnelFeatures.elevation,
privacyOptions: result.tunnelFeatures.privacyOptions,
protocol: result.tunnelFeatures.protocol === undefined ? true : result.tunnelFeatures.protocol,
} : undefined
};

// Split merged API result into separate authority/options
Expand Down
6 changes: 4 additions & 2 deletions src/vs/workbench/api/common/extHostTunnelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe

const tunnelFeatures = information.tunnelFeatures ? {
elevation: !!information.tunnelFeatures?.elevation,
privacyOptions: information.tunnelFeatures?.privacyOptions
privacyOptions: information.tunnelFeatures?.privacyOptions,
protocol: information.tunnelFeatures.protocol === undefined ? true : information.tunnelFeatures.protocol,
} : undefined;

this._proxy.$setTunnelProvider(tunnelFeatures);
Expand Down Expand Up @@ -206,7 +207,8 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe
const tunnelFeatures = provider.tunnelFeatures ? {
elevation: !!provider.tunnelFeatures?.elevation,
public: !!provider.tunnelFeatures?.public,
privacyOptions
privacyOptions,
protocol: true
} : undefined;

this._proxy.$setTunnelProvider(tunnelFeatures);
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/contrib/remote/browser/tunnelFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export class TunnelFactoryContribution extends Disposable implements IWorkbenchC
features: {
elevation: !!environmentService.options?.tunnelProvider?.features?.elevation,
public: !!environmentService.options?.tunnelProvider?.features?.public,
privacyOptions
privacyOptions,
protocol: environmentService.options?.tunnelProvider?.features?.protocol === undefined ? true : !!environmentService.options?.tunnelProvider?.features?.protocol
}
} : undefined;
remoteExplorerService.setTunnelInformation(tunnelInformation);
Expand Down
14 changes: 13 additions & 1 deletion src/vs/workbench/contrib/remote/browser/tunnelView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ const TunnelViewMultiSelectionKeyName = 'tunnelViewMultiSelection';
// host:port[]
const TunnelViewMultiSelectionContextKey = new RawContextKey<string[] | undefined>(TunnelViewMultiSelectionKeyName, undefined, true);
const PortChangableContextKey = new RawContextKey<boolean>('portChangable', false, true);
const ProtocolChangeableContextKey = new RawContextKey<boolean>('protocolChangable', true, true);

export class TunnelPanel extends ViewPane {

Expand All @@ -756,6 +757,7 @@ export class TunnelPanel extends ViewPane {
private tunnelViewSelectionContext: IContextKey<string | undefined>;
private tunnelViewMultiSelectionContext: IContextKey<string[] | undefined>;
private portChangableContextKey: IContextKey<boolean>;
private protocolChangableContextKey: IContextKey<boolean>;
private isEditing: boolean = false;
private titleActions: IAction[] = [];
private lastFocus: number[] = [];
Expand Down Expand Up @@ -786,6 +788,8 @@ export class TunnelPanel extends ViewPane {
this.tunnelPrivacyContext = TunnelPrivacyContextKey.bindTo(contextKeyService);
this.tunnelPrivacyEnabledContext = TunnelPrivacyEnabledContextKey.bindTo(contextKeyService);
this.tunnelPrivacyEnabledContext.set(tunnelService.canChangePrivacy);
this.protocolChangableContextKey = ProtocolChangeableContextKey.bindTo(contextKeyService);
this.protocolChangableContextKey.set(tunnelService.canChangeProtocol);
this.tunnelProtocolContext = TunnelProtocolContextKey.bindTo(contextKeyService);
this.tunnelViewFocusContext = TunnelViewFocusContextKey.bindTo(contextKeyService);
this.tunnelViewSelectionContext = TunnelViewSelectionContextKey.bindTo(contextKeyService);
Expand All @@ -809,8 +813,16 @@ export class TunnelPanel extends ViewPane {

this.registerPrivacyActions();
this._register(Event.once(this.tunnelService.onAddedTunnelProvider)(() => {
let updated = false;
if (this.tunnelPrivacyEnabledContext.get() === false) {
this.tunnelPrivacyEnabledContext.set(tunnelService.canChangePrivacy);
updated = true;
}
if (this.protocolChangableContextKey.get() === true) {
this.protocolChangableContextKey.set(tunnelService.canChangeProtocol);
updated = true;
}
if (updated) {
updateActions();
this.registerPrivacyActions();
this.createTable();
Expand Down Expand Up @@ -1704,7 +1716,7 @@ MenuRegistry.appendMenuItem(MenuId.TunnelContext, ({
order: 3,
submenu: MenuId.TunnelProtocol,
title: nls.localize('tunnelContext.protocolMenu', "Change Port Protocol"),
when: ContextKeyExpr.and(isForwardedExpr, isNotMultiSelectionExpr)
when: ContextKeyExpr.and(isForwardedExpr, isNotMultiSelectionExpr, ProtocolChangeableContextKey)
}));
MenuRegistry.appendMenuItem(MenuId.TunnelContext, ({
group: '3_forward',
Expand Down
4 changes: 4 additions & 0 deletions src/vscode-dts/vscode.proposed.resolvers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ declare module 'vscode' {
* One of the the options must have the ID "private".
*/
privacyOptions: TunnelPrivacy[];
/**
* Defaults to true for backwards compatibility.
*/
protocol?: boolean;
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/vscode-dts/vscode.proposed.tunnelFactory.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ declare module 'vscode' {
* One of the the options must have the ID "private".
*/
privacyOptions: TunnelPrivacy[];
/**
* Defaults to true for backwards compatibility.
*/
protocol?: boolean;
};
}

Expand Down