Skip to content

Commit f474839

Browse files
authored
Merge pull request #12 from gitpod-io/hw/port-view
Update Ports View to bring ability to change port forward protocol IDE-150
2 parents be5de7f + 85dd2c8 commit f474839

File tree

17 files changed

+159
-44
lines changed

17 files changed

+159
-44
lines changed

gitpod-remote/esbuild.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ build().catch((e) => {
4242
});
4343

4444
if (isWatch) {
45+
const srcDir = path.join(__dirname, '../gitpod-shared/portsview')
4546
const watcher = require('@parcel/watcher');
4647
watcher.subscribe(srcDir, () => {
4748
return build();

gitpod-remote/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@
144144
"title": "%makePublic%",
145145
"icon": "$(lock)"
146146
},
147+
{
148+
"command": "gitpod.ports.makeHTTPS",
149+
"title": "%makeHTTPS%",
150+
"icon": "$(workspace-untrusted)"
151+
},
152+
{
153+
"command": "gitpod.ports.makeHTTP",
154+
"title": "%makeHTTP%",
155+
"icon": "$(workspace-trusted)"
156+
},
147157
{
148158
"command": "gitpod.ports.tunnelNetwork",
149159
"title": "%tunnelNetwork%",
@@ -303,6 +313,14 @@
303313
"command": "gitpod.ports.makePrivate",
304314
"when": "false"
305315
},
316+
{
317+
"command": "gitpod.ports.makeHTTPS",
318+
"when": "false"
319+
},
320+
{
321+
"command": "gitpod.ports.makeHTTP",
322+
"when": "false"
323+
},
306324
{
307325
"command": "gitpod.ports.tunnelNetwork",
308326
"when": "false"

gitpod-remote/src/portViewProvider.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*--------------------------------------------------------------------------------------------*/
44
import * as vscode from 'vscode';
55
import { GitpodExtensionContext, ExposedServedGitpodWorkspacePort, GitpodWorkspacePort, isExposedServedGitpodWorkspacePort, isExposedServedPort, PortInfo, TunnelDescriptionI } from 'gitpod-shared';
6-
import { PortsStatus } from '@gitpod/supervisor-api-grpc/lib/status_pb';
6+
import { PortsStatus, PortProtocol, PortVisibility } from '@gitpod/supervisor-api-grpc/lib/status_pb';
77
import { TunnelVisiblity } from '@gitpod/supervisor-api-grpc/lib/port_pb';
88

99
const PortCommands = <const>['tunnelNetwork', 'tunnelHost', 'makePublic', 'makePrivate', 'preview', 'openBrowser', 'retryAutoExpose', 'urlCopy', 'queryPortData'];
@@ -34,14 +34,28 @@ export class GitpodPortViewProvider implements vscode.WebviewViewProvider {
3434
...context.getWorkspaceTelemetryProperties(),
3535
action: 'private'
3636
});
37-
context?.setPortVisibility(port.status.localPort, 'private');
37+
context.controlPort(port.status.localPort, port.status.exposed, { visibility: PortVisibility.PRIVATE });
3838
}));
3939
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.makePublic', ({ port }: PortItem) => {
4040
context.telemetryService.sendTelemetryEvent('vscode_execute_command_gitpod_ports', {
4141
...context.getWorkspaceTelemetryProperties(),
4242
action: 'public'
4343
});
44-
context?.setPortVisibility(port.status.localPort, 'public');
44+
context.controlPort(port.status.localPort, port.status.exposed, { visibility: PortVisibility.PUBLIC });
45+
}));
46+
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.makeHTTPS', ({ port }: PortItem) => {
47+
context.telemetryService.sendTelemetryEvent('vscode_execute_command_gitpod_ports', {
48+
...context.getWorkspaceTelemetryProperties(),
49+
action: 'https'
50+
});
51+
context.controlPort(port.status.localPort, port.status.exposed, { protocol: PortProtocol.HTTPS });
52+
}));
53+
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.makeHTTP', ({ port }: PortItem) => {
54+
context.telemetryService.sendTelemetryEvent('vscode_execute_command_gitpod_ports', {
55+
...context.getWorkspaceTelemetryProperties(),
56+
action: 'http'
57+
});
58+
context.controlPort(port.status.localPort, port.status.exposed, { protocol: PortProtocol.HTTP });
4559
}));
4660
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.preview', ({ port }: PortItem) => {
4761
context.telemetryService.sendTelemetryEvent('vscode_execute_command_gitpod_ports', {

gitpod-remote/yarn.lock

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@
132132
minimatch "^3.1.2"
133133
strip-json-comments "^3.1.1"
134134

135-
"@gitpod/gitpod-protocol@main":
136-
version "0.1.5-main.6379"
137-
resolved "https://registry.yarnpkg.com/@gitpod/gitpod-protocol/-/gitpod-protocol-0.1.5-main.6379.tgz#8c654e9d1658a62648ec4a1bc837f3d5756f8a14"
138-
integrity sha512-QLScSNODhMle/w23HSr3RihIh7S+ZE46JRbOqbFgR9+a0FBoxPtHi6kqUmeNgqvt+hfyjgdPG5/yddU7j0uznA==
135+
"@gitpod/gitpod-protocol@0.1.5-main-gha.10852":
136+
version "0.1.5-main-gha.10852"
137+
resolved "https://registry.yarnpkg.com/@gitpod/gitpod-protocol/-/gitpod-protocol-0.1.5-main-gha.10852.tgz#4792be291ba7021e939aa1e78200b1bd228a2a54"
138+
integrity sha512-n0Ga2Mzjdt/1Gze0SOWpk+xpG2/S1Yi0/hOmRtCFo3MUWA3cFvNQzdP5TByHKUMOxW3pKMZr4dBl9+LYrLvnzQ==
139139
dependencies:
140140
"@types/react" "17.0.32"
141141
abort-controller-x "^0.4.0"
@@ -150,6 +150,7 @@
150150
js-yaml "^3.10.0"
151151
nice-grpc-common "^2.0.0"
152152
opentracing "^0.14.5"
153+
parse-duration "^1.0.3"
153154
prom-client "^13.2.0"
154155
random-number-csprng "^1.0.2"
155156
react "17.0.2"
@@ -164,10 +165,10 @@
164165
vscode-ws-jsonrpc "^0.2.0"
165166
ws "^7.4.6"
166167

167-
"@gitpod/supervisor-api-grpc@ak-rebuild-debug":
168-
version "0.1.5-ak-rebuild-debug.65"
169-
resolved "https://registry.yarnpkg.com/@gitpod/supervisor-api-grpc/-/supervisor-api-grpc-0.1.5-ak-rebuild-debug.65.tgz#fe295c15a3b58d340d9111207c9eef1564bfff3c"
170-
integrity sha512-tuR/kEalT4/02ZDuO9OgkVg54+Fw3ZIfaQHHyanEZq52tPgSW0/sezoPN0TAJxg+D8mbd1NsiDeQZx/0Xg7TGA==
168+
"@gitpod/supervisor-api-grpc@0.1.5-main-gha.10852":
169+
version "0.1.5-main-gha.10852"
170+
resolved "https://registry.yarnpkg.com/@gitpod/supervisor-api-grpc/-/supervisor-api-grpc-0.1.5-main-gha.10852.tgz#83755a5c0539fe9482a141351a7441057e7d352c"
171+
integrity sha512-/OWTpEVZMYut0IbAH50sx6yVYeQB9TKZu+3kgkGiwT6LihgrH98BXteFT77yrlpKTHmAuvdoN3XJCGGPhfePRA==
171172
dependencies:
172173
"@grpc/grpc-js" "^1.3.7"
173174
google-protobuf "^3.19.1"
@@ -2328,6 +2329,11 @@ parent-module@^1.0.0:
23282329
dependencies:
23292330
callsites "^3.0.0"
23302331

2332+
parse-duration@^1.0.3:
2333+
version "1.1.0"
2334+
resolved "https://registry.yarnpkg.com/parse-duration/-/parse-duration-1.1.0.tgz#5192084c5d8f2a3fd676d04a451dbd2e05a1819c"
2335+
integrity sha512-z6t9dvSJYaPoQq7quMzdEagSFtpGu+utzHqqxmpVWNNZRIXnvqyCvn9XsTdh7c/w0Bqmdz3RB3YnRaKtpRtEXQ==
2336+
23312337
parseurl@~1.3.3:
23322338
version "1.3.3"
23332339
resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.3.tgz#9da19e7bee8d12dff0513ed5b76957793bc2e8d4"

gitpod-shared/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
},
3131
"dependencies": {
3232
"configcat-node": "^8.0.0",
33-
"@gitpod/gitpod-protocol": "main",
34-
"@gitpod/supervisor-api-grpc": "ak-rebuild-debug",
33+
"@gitpod/gitpod-protocol": "0.1.5-main-gha.10852",
34+
"@gitpod/supervisor-api-grpc": "0.1.5-main-gha.10852",
3535
"@vscode/codicons": "^0.0.31",
3636
"@vscode/webview-ui-toolkit": "^1.0.0",
3737
"bufferutil": "^4.0.1",

gitpod-shared/portsview/src/porttable/PortTable.svelte

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import PortLocalAddress from "./PortLocalAddress.svelte";
1515
import { vscode } from "../utils/vscodeApi";
1616
import type { GitpodPortObject, PortCommand } from "../protocol/gitpod";
17+
import { PortProtocol } from "../protocol/gitpod";
1718
import { getNLSTitle, getSplitCommands } from "../utils/commands";
1819
import type { MenuOption } from "../protocol/components";
1920
import PortHoverActions from './PortHoverActions.svelte';
@@ -76,9 +77,9 @@
7677
let innerWidth = 0
7778
7879
const responsiveMap: Record<number, {layout: string; headers: string[]; options?: { allInPort?: boolean; }}> = {
79-
850: {
80-
layout: "50px 180px 1fr 180px 180px",
81-
headers: ["", "Port", "Address", "Description", "State"],
80+
950: {
81+
layout: "50px 180px 1fr 90px 180px 180px",
82+
headers: ["", "Port", "Address", "Protocol", "Description", "State"],
8283
},
8384
700: {
8485
layout: "50px 180px 1fr 180px",
@@ -92,7 +93,7 @@
9293
9394
const sortedResponsiveKeys = Object.keys(responsiveMap).map(e => Number(e)).sort((a, b) => b - a)
9495
95-
$: useResponsive = responsiveMap[sortedResponsiveKeys.find(e => innerWidth > e) ?? 850]
96+
$: useResponsive = responsiveMap[sortedResponsiveKeys.find(e => innerWidth > e) ?? 950]
9697
9798
//#endregion
9899
@@ -162,6 +163,12 @@
162163
</vscode-data-grid-cell>
163164
{/if}
164165

166+
{#if useResponsive.headers.includes("Protocol")}
167+
<vscode-data-grid-cell grid-column={useResponsive.headers.indexOf("Protocol") + 1} class="td">
168+
<span title="Forward Protocol">{port.status.exposed?.protocol === PortProtocol.HTTPS ? 'HTTPS' : 'HTTP'}</span>
169+
</vscode-data-grid-cell>
170+
{/if}
171+
165172
{#if useResponsive.headers.includes("Description")}
166173
<vscode-data-grid-cell grid-column={useResponsive.headers.indexOf("Description") + 1} class="td">
167174
<span title={port.status.description}>{port.status.description}</span>

gitpod-shared/portsview/src/protocol/gitpod.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export enum PortVisibility {
2525
PUBLIC = 1,
2626
}
2727

28+
export enum PortProtocol {
29+
HTTP = 0,
30+
HTTPS = 1,
31+
}
32+
2833
export enum OnPortExposedAction {
2934
IGNORE = 0,
3035
OPEN_BROWSER = 1,
@@ -49,6 +54,7 @@ export enum TaskState {
4954
export namespace ExposedPortInfo {
5055
export type AsObject = {
5156
visibility: PortVisibility;
57+
protocol: PortProtocol;
5258
url: string;
5359
onExposed: OnPortExposedAction;
5460
};
@@ -81,6 +87,6 @@ export interface GitpodPortObject {
8187
status: PortsStatus.AsObject & { remotePort?: number };
8288
}
8389

84-
export const PortCommands = <const>['tunnelNetwork', 'tunnelHost', 'makePublic', 'makePrivate', 'preview', 'openBrowser', 'retryAutoExpose', 'urlCopy', 'queryPortData'];
90+
export const PortCommands = <const>['tunnelNetwork', 'tunnelHost', 'makePublic', 'makePrivate', 'preview', 'openBrowser', 'retryAutoExpose', 'urlCopy', 'queryPortData', 'makeHTTP', 'makeHTTPS'];
8591

8692
export type PortCommand = typeof PortCommands[number];

gitpod-shared/portsview/src/utils/commands.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export const commandIconMap: Record<PortCommand, string> = {
2222
tunnelHost: 'eye-closed',
2323
makePublic: 'lock',
2424
makePrivate: 'unlock',
25+
makeHTTP: 'workspace-trusted',
26+
makeHTTPS: 'workspace-untrusted',
2527
preview: 'open-preview',
2628
openBrowser: 'globe',
2729
retryAutoExpose: 'refresh',
@@ -37,7 +39,7 @@ window.addEventListener('message', (event) => {
3739
});
3840

3941
export function getCommands(port: GitpodPortObject): PortCommand[] {
40-
return getSplitCommands(port).filter(e => !!e) as PortCommand[];
42+
return getSplitCommands(port).filter(e => !!e && e !== 'makeHTTP' && e !== 'makeHTTPS') as PortCommand[];
4143
}
4244

4345
export function getSplitCommands(port: GitpodPortObject) {
@@ -68,6 +70,14 @@ export function getSplitCommands(port: GitpodPortObject) {
6870
}
6971
opts.push('retryAutoExpose');
7072
}
73+
if (opts.length > 0) {
74+
opts.push(null);
75+
}
76+
if (viewItem.includes('https')) {
77+
opts.push('makeHTTP');
78+
} else {
79+
opts.push('makeHTTPS');
80+
}
7181
if (supportedCommands.length > 0) {
7282
return opts.filter(e => e === null || supportedCommands.includes(e));
7383
}

gitpod-shared/src/gitpodContext.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import { GitpodClient, GitpodServer, GitpodServiceImpl, WorkspaceInstanceUpdateListener } from '@gitpod/gitpod-protocol/lib/gitpod-service';
66
import { User } from '@gitpod/gitpod-protocol/lib/protocol';
77
import { Team } from '@gitpod/gitpod-protocol/lib/teams-projects-protocol';
8-
import { PortVisibility } from '@gitpod/gitpod-protocol/lib/workspace-instance';
98
import { ControlServiceClient } from '@gitpod/supervisor-api-grpc/lib/control_grpc_pb';
109
import { ExposePortRequest } from '@gitpod/supervisor-api-grpc/lib/control_pb';
1110
import { InfoServiceClient } from '@gitpod/supervisor-api-grpc/lib/info_grpc_pb';
@@ -14,7 +13,7 @@ import { NotificationServiceClient } from '@gitpod/supervisor-api-grpc/lib/notif
1413
import { PortServiceClient } from '@gitpod/supervisor-api-grpc/lib/port_grpc_pb';
1514
import { CloseTunnelRequest, RetryAutoExposeRequest, TunnelPortRequest, TunnelVisiblity } from '@gitpod/supervisor-api-grpc/lib/port_pb';
1615
import { StatusServiceClient } from '@gitpod/supervisor-api-grpc/lib/status_grpc_pb';
17-
import { PortsStatus, PortsStatusRequest, PortsStatusResponse } from '@gitpod/supervisor-api-grpc/lib/status_pb';
16+
import { ExposedPortInfo, PortProtocol, PortVisibility, PortsStatus, PortsStatusRequest, PortsStatusResponse } from '@gitpod/supervisor-api-grpc/lib/status_pb';
1817
import { TerminalServiceClient } from '@gitpod/supervisor-api-grpc/lib/terminal_grpc_pb';
1918
import { TokenServiceClient } from '@gitpod/supervisor-api-grpc/lib/token_grpc_pb';
2019
import { GetTokenRequest } from '@gitpod/supervisor-api-grpc/lib/token_pb';
@@ -311,10 +310,14 @@ export class GitpodExtensionContext implements vscode.ExtensionContext {
311310
}
312311
}
313312

314-
async setPortVisibility(port: number, visibility: PortVisibility): Promise<void> {
313+
async controlPort(port: number, prevStatus: ExposedPortInfo.AsObject | undefined, updateOptions: Partial<Pick<ExposedPortInfo.AsObject, 'visibility' | 'protocol'>>): Promise<void> {
314+
const protocol = updateOptions.protocol ?? prevStatus?.protocol ?? PortProtocol.HTTP;
315+
const visibility = updateOptions.visibility ?? prevStatus?.visibility ?? PortVisibility.PRIVATE;
316+
315317
await this.gitpod.server.openPort(this.info.workspaceId, {
316318
port,
317-
visibility
319+
protocol: protocol === PortProtocol.HTTPS ? 'https' : 'http',
320+
visibility: visibility === PortVisibility.PUBLIC ? 'public' : 'private',
318321
});
319322
}
320323

gitpod-shared/src/workspacePort.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) Gitpod. All rights reserved.
33
*--------------------------------------------------------------------------------------------*/
44

5-
import { PortsStatus, PortAutoExposure, PortVisibility, ExposedPortInfo } from '@gitpod/supervisor-api-grpc/lib/status_pb';
5+
import { PortsStatus, PortAutoExposure, PortVisibility, ExposedPortInfo, PortProtocol } from '@gitpod/supervisor-api-grpc/lib/status_pb';
66
import { URL } from 'url';
77

88
export interface ExposedPort extends PortsStatus.AsObject {
@@ -153,6 +153,9 @@ export class GitpodWorkspacePort {
153153
if (!accessible && portStatus.autoExposure === PortAutoExposure.FAILED) {
154154
port.contextValue = 'failed-' + port.contextValue;
155155
}
156+
if (exposed?.protocol && exposed.protocol === PortProtocol.HTTPS) {
157+
port.contextValue = 'https-' + port.contextValue;
158+
}
156159
return port;
157160
}
158161

0 commit comments

Comments
 (0)