@@ -22,8 +22,7 @@ import { ParsedKey } from 'ssh2-streams';
2222import { isPortUsed } from '../../common/ports' ;
2323import { WrapError } from '../../common/utils' ;
2424import { ConnectError , Code } from '@bufbuild/connect' ;
25- import { WorkspaceInstanceStatus_Phase } from '@gitpod/public-api/lib/gitpod/experimental/v1' ;
26- import { WorkspacePhase } from '../../publicApi' ;
25+ import { rawWorkspaceToWorkspaceData } from '../../publicApi' ;
2726
2827function isServiceError ( obj : any ) : obj is ServiceError {
2928 // eslint-disable-next-line eqeqeq
@@ -109,26 +108,34 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
109108 // TODO(lssh): Get auth info according to `request.gitpodHost`
110109 const gitpodHost = this . hostService . gitpodHost ;
111110
112- const ws = await this . sessionService . getAPI ( ) . getWorkspace ( actualWorkspaceId , _context . signal ) ;
113-
114- instanceId = ws . status ! . instance ! . instanceId ;
115-
116- let ownerToken = '' ;
117- let sshkey = '' ;
118- let workspaceHost = '' ;
119- const phase = WorkspaceInstanceStatus_Phase [ ws . status ! . instance ! . status ! . phase ?? WorkspaceInstanceStatus_Phase . UNSPECIFIED ] . toLowerCase ( ) as WorkspacePhase ;
120- // if workspace is not running, we may not compute its url yet
121- if ( phase === 'running' ) {
122- ownerToken = await this . sessionService . getAPI ( ) . getOwnerToken ( actualWorkspaceId , _context . signal ) ;
123- let workspaceUrl = ws . status ! . instance ! . status ! . url ;
124- const url = new URL ( workspaceUrl ) ;
125- workspaceHost = url . host . substring ( url . host . indexOf ( '.' ) + 1 ) ;
126- if ( workspaceId !== actualWorkspaceId ) {
127- // Public api doesn't take into account "debug" workspaces, readd 'debug-' prefix
128- workspaceUrl = workspaceUrl . replace ( actualWorkspaceId , workspaceId ) ;
129- }
130- sshkey = await this . getWorkspaceSSHKey ( ownerToken , workspaceUrl , _context . signal ) ;
111+ const rawWorkspace = await this . sessionService . getAPI ( ) . getWorkspace ( actualWorkspaceId , _context . signal ) ;
112+ const wsData = rawWorkspaceToWorkspaceData ( rawWorkspace ) ;
113+
114+ // Report if we couldn't parse contextUrl
115+ if ( ! wsData . contextUrl ) {
116+ this . telemetryService . sendTelemetryException ( new Error ( 'Unable to parse workspace contextUrl' ) , {
117+ gitpodHost : request . gitpodHost ,
118+ workspaceId : request . workspaceId ,
119+ instanceId,
120+ userId,
121+ contextUrl : rawWorkspace . context ?. contextUrl ,
122+ } ) ;
123+ }
124+
125+ const ownerToken = await this . sessionService . getAPI ( ) . getOwnerToken ( actualWorkspaceId , _context . signal ) ;
126+
127+ instanceId = rawWorkspace . status ! . instance ! . instanceId ;
128+
129+ const workspaceUrl = new URL ( wsData . workspaceUrl ) ;
130+ const workspaceHost = workspaceUrl . host . substring ( workspaceUrl . host . indexOf ( '.' ) + 1 ) ;
131+ let actualWorkspaceUrl = wsData . workspaceUrl ;
132+ if ( workspaceId !== actualWorkspaceId ) {
133+ // Public api doesn't take into account "debug" workspaces, readd 'debug-' prefix
134+ actualWorkspaceUrl = actualWorkspaceUrl . replace ( actualWorkspaceId , workspaceId ) ;
131135 }
136+
137+ const sshkey = wsData . phase === 'running' ? ( await this . getWorkspaceSSHKey ( ownerToken , actualWorkspaceUrl , _context . signal ) ) : '' ;
138+
132139 return {
133140 gitpodHost,
134141 userId,
@@ -137,7 +144,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
137144 workspaceHost,
138145 ownerToken,
139146 sshkey,
140- phase,
147+ phase : wsData . phase ,
141148 } ;
142149 } catch ( e ) {
143150 let code = Status . INTERNAL ;
0 commit comments