@@ -28,7 +28,6 @@ import {
28
28
GitpodToken ,
29
29
GitpodTokenType ,
30
30
PermissionName ,
31
- PortVisibility ,
32
31
PrebuiltWorkspace ,
33
32
PrebuiltWorkspaceContext ,
34
33
SetWorkspaceTimeoutResult ,
@@ -69,7 +68,6 @@ import {
69
68
PrebuildEvent ,
70
69
RoleOrPermission ,
71
70
WORKSPACE_TIMEOUT_DEFAULT_SHORT ,
72
- PortProtocol ,
73
71
WorkspaceInstanceRepoStatus ,
74
72
} from "@gitpod/gitpod-protocol" ;
75
73
import { BlockedRepository } from "@gitpod/gitpod-protocol/lib/blocked-repositories-protocol" ;
@@ -101,13 +99,9 @@ import { WorkspaceManagerClientProvider } from "@gitpod/ws-manager/lib/client-pr
101
99
import {
102
100
AdmissionLevel ,
103
101
ControlAdmissionRequest ,
104
- ControlPortRequest ,
105
102
DescribeWorkspaceRequest ,
106
103
MarkActiveRequest ,
107
- PortSpec ,
108
- PortVisibility as ProtoPortVisibility ,
109
104
SetTimeoutRequest ,
110
- PortProtocol as ProtoPortProtocol ,
111
105
StopWorkspacePolicy ,
112
106
TakeSnapshotRequest ,
113
107
} from "@gitpod/ws-manager/lib/core_pb" ;
@@ -158,7 +152,6 @@ import { EntitlementService } from "../billing/entitlement-service";
158
152
import { formatPhoneNumber } from "../user/phone-numbers" ;
159
153
import { IDEService } from "../ide-service" ;
160
154
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution" ;
161
- import * as grpc from "@grpc/grpc-js" ;
162
155
import { CostCenterJSON } from "@gitpod/gitpod-protocol/lib/usage" ;
163
156
import { createCookielessId , maskIp } from "../analytics" ;
164
157
import {
@@ -188,7 +181,7 @@ import { RedisSubscriber } from "../messaging/redis-subscriber";
188
181
import { UsageService } from "../orgs/usage-service" ;
189
182
import { UserService } from "../user/user-service" ;
190
183
import { SSHKeyService } from "../user/sshkey-service" ;
191
- import { StartWorkspaceOptions , WorkspaceService } from "./workspace-service" ;
184
+ import { StartWorkspaceOptions , WorkspaceService , mapGrpcError } from "./workspace-service" ;
192
185
import { GitpodTokenService } from "../user/gitpod-token-service" ;
193
186
import { EnvVarService } from "../user/env-var-service" ;
194
187
@@ -1143,7 +1136,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1143
1136
// This is an old tab with open workspace: drop silently
1144
1137
return ;
1145
1138
} else {
1146
- e = this . mapGrpcError ( e ) ;
1139
+ e = mapGrpcError ( e ) ;
1147
1140
throw e ;
1148
1141
}
1149
1142
}
@@ -1837,7 +1830,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1837
1830
traceAPIParams ( ctx , { workspaceId } ) ;
1838
1831
traceWI ( ctx , { workspaceId } ) ;
1839
1832
1840
- await this . checkAndBlockUser ( "getOpenPorts" ) ;
1833
+ const user = await this . checkAndBlockUser ( "getOpenPorts" ) ;
1841
1834
1842
1835
const instance = await this . workspaceDb . trace ( ctx ) . findRunningInstance ( workspaceId ) ;
1843
1836
const workspace = await this . workspaceDb . trace ( ctx ) . findById ( workspaceId ) ;
@@ -1847,30 +1840,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1847
1840
1848
1841
await this . guardAccess ( { kind : "workspaceInstance" , subject : instance , workspace } , "get" ) ;
1849
1842
1850
- const req = new DescribeWorkspaceRequest ( ) ;
1851
- req . setId ( instance . id ) ;
1852
- const client = await this . workspaceManagerClientProvider . get ( instance . region ) ;
1853
- const desc = await client . describeWorkspace ( ctx , req ) ;
1854
-
1855
- if ( ! desc . hasStatus ( ) ) {
1856
- throw new Error ( "describeWorkspace returned no status" ) ;
1857
- }
1858
-
1859
- const status = desc . getStatus ( ) ! ;
1860
- const ports = status
1861
- . getSpec ( ) !
1862
- . getExposedPortsList ( )
1863
- . map (
1864
- ( p ) =>
1865
- < WorkspaceInstancePort > {
1866
- port : p . getPort ( ) ,
1867
- url : p . getUrl ( ) ,
1868
- visibility : this . portVisibilityFromProto ( p . getVisibility ( ) ) ,
1869
- protocol : this . portProtocolFromProto ( p . getProtocol ( ) ) ,
1870
- } ,
1871
- ) ;
1872
-
1873
- return ports ;
1843
+ return await this . workspaceService . getOpenPorts ( user . id , workspaceId ) ;
1874
1844
}
1875
1845
1876
1846
public async updateGitStatus (
@@ -1924,61 +1894,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1924
1894
traceWI ( ctx , { instanceId : runningInstance . id } ) ;
1925
1895
await this . guardAccess ( { kind : "workspaceInstance" , subject : runningInstance , workspace } , "update" ) ;
1926
1896
1927
- const req = new ControlPortRequest ( ) ;
1928
- req . setId ( runningInstance . id ) ;
1929
- const spec = new PortSpec ( ) ;
1930
- spec . setPort ( port . port ) ;
1931
- spec . setVisibility ( this . portVisibilityToProto ( port . visibility ) ) ;
1932
- spec . setProtocol ( this . portProtocolToProto ( port . protocol ) ) ;
1933
- req . setSpec ( spec ) ;
1934
- req . setExpose ( true ) ;
1935
-
1936
- try {
1937
- const client = await this . workspaceManagerClientProvider . get ( runningInstance . region ) ;
1938
- await client . controlPort ( ctx , req ) ;
1939
- } catch ( e ) {
1940
- throw this . mapGrpcError ( e ) ;
1941
- }
1942
- }
1943
-
1944
- private portVisibilityFromProto ( visibility : ProtoPortVisibility ) : PortVisibility {
1945
- switch ( visibility ) {
1946
- default : // the default in the protobuf def is: private
1947
- case ProtoPortVisibility . PORT_VISIBILITY_PRIVATE :
1948
- return "private" ;
1949
- case ProtoPortVisibility . PORT_VISIBILITY_PUBLIC :
1950
- return "public" ;
1951
- }
1952
- }
1953
-
1954
- private portVisibilityToProto ( visibility : PortVisibility | undefined ) : ProtoPortVisibility {
1955
- switch ( visibility ) {
1956
- default : // the default for requests is: private
1957
- case "private" :
1958
- return ProtoPortVisibility . PORT_VISIBILITY_PRIVATE ;
1959
- case "public" :
1960
- return ProtoPortVisibility . PORT_VISIBILITY_PUBLIC ;
1961
- }
1962
- }
1963
-
1964
- private portProtocolFromProto ( protocol : ProtoPortProtocol ) : PortProtocol {
1965
- switch ( protocol ) {
1966
- default : // the default in the protobuf def is: http
1967
- case ProtoPortProtocol . PORT_PROTOCOL_HTTP :
1968
- return "http" ;
1969
- case ProtoPortProtocol . PORT_PROTOCOL_HTTPS :
1970
- return "https" ;
1971
- }
1972
- }
1973
-
1974
- private portProtocolToProto ( protocol : PortProtocol | undefined ) : ProtoPortProtocol {
1975
- switch ( protocol ) {
1976
- default : // the default for requests is: http
1977
- case "http" :
1978
- return ProtoPortProtocol . PORT_PROTOCOL_HTTP ;
1979
- case "https" :
1980
- return ProtoPortProtocol . PORT_PROTOCOL_HTTPS ;
1981
- }
1897
+ return await this . workspaceService . openPort ( user . id , workspaceId , port ) ;
1982
1898
}
1983
1899
1984
1900
public async closePort ( ctx : TraceContext , workspaceId : string , port : number ) {
@@ -1999,15 +1915,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1999
1915
traceWI ( ctx , { instanceId : instance . id } ) ;
2000
1916
await this . guardAccess ( { kind : "workspaceInstance" , subject : instance , workspace } , "update" ) ;
2001
1917
2002
- const req = new ControlPortRequest ( ) ;
2003
- req . setId ( instance . id ) ;
2004
- const spec = new PortSpec ( ) ;
2005
- spec . setPort ( port ) ;
2006
- req . setSpec ( spec ) ;
2007
- req . setExpose ( false ) ;
2008
-
2009
- const client = await this . workspaceManagerClientProvider . get ( instance . region ) ;
2010
- await client . controlPort ( ctx , req ) ;
1918
+ await this . workspaceService . closePort ( user . id , workspaceId , port ) ;
2011
1919
}
2012
1920
2013
1921
async watchWorkspaceImageBuildLogs ( ctx : TraceContext , workspaceId : string ) : Promise < void > {
@@ -3523,23 +3431,6 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
3523
3431
increaseDashboardErrorBoundaryCounter ( ) ;
3524
3432
}
3525
3433
3526
- private mapGrpcError ( err : Error ) : Error {
3527
- function isGrpcError ( err : any ) : err is grpc . StatusObject {
3528
- return err . code && err . details ;
3529
- }
3530
-
3531
- if ( ! isGrpcError ( err ) ) {
3532
- return err ;
3533
- }
3534
-
3535
- switch ( err . code ) {
3536
- case grpc . status . RESOURCE_EXHAUSTED :
3537
- return new ApplicationError ( ErrorCodes . TOO_MANY_REQUESTS , err . details ) ;
3538
- default :
3539
- return new ApplicationError ( ErrorCodes . INTERNAL_SERVER_ERROR , err . details ) ;
3540
- }
3541
- }
3542
-
3543
3434
async getIDToken ( ) : Promise < void > { }
3544
3435
3545
3436
public async controlAdmission ( ctx : TraceContext , workspaceId : string , level : "owner" | "everyone" ) : Promise < void > {
0 commit comments