@@ -22,8 +22,7 @@ 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 { WorkspaceInstanceStatus_Phase } from '@gitpod/public-api/lib/gitpod/experimental/v1' ;
26
- import { WorkspacePhase } from '../../publicApi' ;
25
+ import { rawWorkspaceToWorkspaceData } from '../../publicApi' ;
27
26
28
27
function isServiceError ( obj : any ) : obj is ServiceError {
29
28
// eslint-disable-next-line eqeqeq
@@ -109,26 +108,34 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
109
108
// TODO(lssh): Get auth info according to `request.gitpodHost`
110
109
const gitpodHost = this . hostService . gitpodHost ;
111
110
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 ) ;
131
135
}
136
+
137
+ const sshkey = wsData . phase === 'running' ? ( await this . getWorkspaceSSHKey ( ownerToken , actualWorkspaceUrl , _context . signal ) ) : '' ;
138
+
132
139
return {
133
140
gitpodHost,
134
141
userId,
@@ -137,7 +144,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
137
144
workspaceHost,
138
145
ownerToken,
139
146
sshkey,
140
- phase,
147
+ phase : wsData . phase ,
141
148
} ;
142
149
} catch ( e ) {
143
150
let code = Status . INTERNAL ;
0 commit comments