@@ -22,7 +22,8 @@ import { ParsedKey } from 'ssh2-streams';
22
22
import { isPortUsed } from '../../common/ports' ;
23
23
import { WrapError } from '../../common/utils' ;
24
24
import { 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' ;
26
27
27
28
function isServiceError ( obj : any ) : obj is ServiceError {
28
29
// eslint-disable-next-line eqeqeq
@@ -108,23 +109,26 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
108
109
// TODO(lssh): Get auth info according to `request.gitpodHost`
109
110
const gitpodHost = this . hostService . gitpodHost ;
110
111
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 ) ;
124
131
}
125
-
126
- const sshkey = wsData . phase === 'running' ? ( await this . getWorkspaceSSHKey ( ownerToken , actualWorkspaceUrl , _context . signal ) ) : '' ;
127
-
128
132
return {
129
133
gitpodHost,
130
134
userId,
@@ -133,7 +137,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
133
137
workspaceHost,
134
138
ownerToken,
135
139
sshkey,
136
- phase : wsData . phase ,
140
+ phase,
137
141
} ;
138
142
} catch ( e ) {
139
143
let code = Status . INTERNAL ;
0 commit comments