@@ -22,7 +22,8 @@ import { ParsedKey } from 'ssh2-streams';
2222import { isPortUsed } from '../../common/ports' ;
2323import { WrapError } from '../../common/utils' ;
2424import { ConnectError , Code } from '@bufbuild/connect' ;
25- import { rawWorkspaceToWorkspaceData } from '../../publicApi' ;
25+ import { WorkspaceInstanceStatus_Phase } from '@gitpod/public-api/lib/gitpod/experimental/v1' ;
26+ import { WorkspacePhase } from '../../publicApi' ;
2627
2728function isServiceError ( obj : any ) : obj is ServiceError {
2829 // eslint-disable-next-line eqeqeq
@@ -108,23 +109,26 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
108109 // TODO(lssh): Get auth info according to `request.gitpodHost`
109110 const gitpodHost = this . hostService . gitpodHost ;
110111
111- const rawWorkspace = await this . sessionService . getAPI ( ) . getWorkspace ( actualWorkspaceId , _context . signal ) ;
112- const wsData = rawWorkspaceToWorkspaceData ( rawWorkspace ) ;
113-
114- const ownerToken = await this . sessionService . getAPI ( ) . getOwnerToken ( actualWorkspaceId , _context . signal ) ;
115-
116- instanceId = rawWorkspace . status ! . instance ! . instanceId ;
117- const url = new URL ( wsData . workspaceUrl ) ;
118- const workspaceHost = url . host . substring ( url . host . indexOf ( '.' ) + 1 ) ;
119-
120- let actualWorkspaceUrl = wsData . workspaceUrl ;
121- if ( workspaceId !== actualWorkspaceId ) {
122- // Public api doesn't take into account "debug" workspaces, readd 'debug-' prefix
123- actualWorkspaceUrl = actualWorkspaceUrl . replace ( actualWorkspaceId , workspaceId ) ;
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 ) ;
124131 }
125-
126- const sshkey = wsData . phase === 'running' ? ( await this . getWorkspaceSSHKey ( ownerToken , actualWorkspaceUrl , _context . signal ) ) : '' ;
127-
128132 return {
129133 gitpodHost,
130134 userId,
@@ -133,7 +137,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
133137 workspaceHost,
134138 ownerToken,
135139 sshkey,
136- phase : wsData . phase ,
140+ phase,
137141 } ;
138142 } catch ( e ) {
139143 let code = Status . INTERNAL ;
0 commit comments