3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { ExtensionServiceDefinition , ExtensionServiceImplementation , GetWorkspaceAuthInfoRequest , GetWorkspaceAuthInfoResponse , PingRequest , SendErrorReportRequest , SendLocalSSHUserFlowStatusRequest } from '../../proto/typescript/ipc/v1/ipc' ;
6
+ import { ExtensionServiceDefinition , ExtensionServiceImplementation , GetWorkspaceAuthInfoRequest , GetWorkspaceAuthInfoResponse , PingRequest } from '../../proto/typescript/ipc/v1/ipc' ;
7
7
import { Disposable } from '../../common/dispose' ;
8
8
import { ILogService } from '../../services/logService' ;
9
9
import { ISessionService } from '../../services/sessionService' ;
10
10
import { CallContext , ServerError , Status } from 'nice-grpc-common' ;
11
11
import { IHostService } from '../../services/hostService' ;
12
12
import { Server , createChannel , createClient , createServer } from 'nice-grpc' ;
13
- import { ITelemetryService , UserFlowTelemetryProperties } from '../../common/telemetry' ;
13
+ import { ITelemetryService } from '../../common/telemetry' ;
14
14
import { Configuration } from '../../configuration' ;
15
15
import { timeout } from '../../common/async' ;
16
16
import { BrowserHeaders } from 'browser-headers' ;
17
17
import { ControlServiceClient , ServiceError } from '@gitpod/supervisor-api-grpcweb/lib/control_pb_service' ;
18
18
import { NodeHttpTransport } from '@improbable-eng/grpc-web-node-http-transport' ;
19
- import { CreateSSHKeyPairRequest } from '@gitpod/supervisor-api-grpcweb/lib/control_pb' ;
19
+ import { CreateSSHKeyPairRequest , CreateSSHKeyPairResponse } from '@gitpod/supervisor-api-grpcweb/lib/control_pb' ;
20
20
import * as ssh2 from 'ssh2' ;
21
21
import { ParsedKey } from 'ssh2-streams' ;
22
22
import { WrapError } from '../../common/utils' ;
@@ -66,15 +66,15 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
66
66
private async getWorkspaceSSHKey ( ownerToken : string , workspaceUrl : string , signal : AbortSignal ) {
67
67
const url = new URL ( workspaceUrl ) ;
68
68
url . pathname = '/_supervisor/v1' ;
69
- const privateKey = await wrapSupervisorAPIError ( ( ) => new Promise < string > ( ( resolve , reject ) => {
69
+ const { privateKey, userName } = await wrapSupervisorAPIError ( ( ) => new Promise < CreateSSHKeyPairResponse . AsObject > ( ( resolve , reject ) => {
70
70
const metadata = new BrowserHeaders ( ) ;
71
71
metadata . append ( 'x-gitpod-owner-token' , ownerToken ) ;
72
72
const client = new ControlServiceClient ( url . toString ( ) , { transport : NodeHttpTransport ( ) } ) ;
73
73
client . createSSHKeyPair ( new CreateSSHKeyPairRequest ( ) , metadata , ( err , resp ) => {
74
74
if ( err ) {
75
75
return reject ( err ) ;
76
76
}
77
- resolve ( resp ! . toObject ( ) . privateKey ) ;
77
+ resolve ( resp ! . toObject ( ) ) ;
78
78
} ) ;
79
79
} ) , { signal } ) ;
80
80
@@ -83,7 +83,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
83
83
throw new Error ( 'Error while parsing workspace SSH private key' ) ;
84
84
}
85
85
86
- return ( parsedResult as ParsedKey ) . getPrivatePEM ( ) ;
86
+ return { sshkey : ( parsedResult as ParsedKey ) . getPrivatePEM ( ) , username : userName } ;
87
87
}
88
88
89
89
async getWorkspaceAuthInfo ( request : GetWorkspaceAuthInfoRequest , _context : CallContext ) : Promise < GetWorkspaceAuthInfoResponse > {
@@ -126,6 +126,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
126
126
let ownerToken = '' ;
127
127
let workspaceHost = '' ;
128
128
let sshkey = '' ;
129
+ let username = '' ;
129
130
if ( wsData . phase === 'running' ) {
130
131
ownerToken = await this . sessionService . getAPI ( ) . getOwnerToken ( actualWorkspaceId , _context . signal ) ;
131
132
@@ -137,7 +138,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
137
138
actualWorkspaceUrl = actualWorkspaceUrl . replace ( actualWorkspaceId , workspaceId ) ;
138
139
}
139
140
140
- sshkey = await this . getWorkspaceSSHKey ( ownerToken , actualWorkspaceUrl , _context . signal ) ;
141
+ ( { sshkey, username } = await this . getWorkspaceSSHKey ( ownerToken , actualWorkspaceUrl , _context . signal ) ) ;
141
142
}
142
143
143
144
return {
@@ -149,6 +150,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
149
150
ownerToken,
150
151
sshkey,
151
152
phase : wsData . phase ,
153
+ username,
152
154
} ;
153
155
} catch ( e ) {
154
156
let code = Status . INTERNAL ;
@@ -169,41 +171,6 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
169
171
}
170
172
}
171
173
172
- // TODO remove from protocol, don't pass sensitive info back and forth, only once for auth, daemon should do telemetry directly
173
- async sendLocalSSHUserFlowStatus ( request : SendLocalSSHUserFlowStatusRequest , _context : CallContext ) : Promise < { } > {
174
- if ( ! request . flowStatus || request . flowStatus === '' ) {
175
- return { } ;
176
- }
177
- const flow : UserFlowTelemetryProperties = {
178
- flow : 'local_ssh' ,
179
- workspaceId : request . workspaceId ,
180
- instanceId : request . instanceId ,
181
- daemonVersion : request . daemonVersion ,
182
- userId : request . userId ,
183
- gitpodHost : request . gitpodHost ,
184
- failureCode : request . flowFailureCode ,
185
- } ;
186
- this . telemetryService . sendUserFlowStatus ( request . flowStatus , flow ) ;
187
- return { } ;
188
- }
189
-
190
- // TODO remove from protocol, don't pass sensitive info back and forth, only once for auth, daemon should do telemetry directly
191
- // local ssh daemon should be own component in reporting?
192
- async sendErrorReport ( request : SendErrorReportRequest , _context : CallContext ) : Promise < { } > {
193
- const err = new Error ( request . errorMessage ) ;
194
- err . name = `${ request . errorName } [local-ssh]` ;
195
- err . stack = request . errorStack ;
196
- this . telemetryService . sendTelemetryException ( err , {
197
- gitpodHost : request . gitpodHost ,
198
- workspaceId : request . workspaceId ,
199
- instanceId : request . instanceId ,
200
- daemonVersion : request . daemonVersion ,
201
- extensionVersion : request . extensionVersion ,
202
- userId : request . userId ,
203
- } ) ;
204
- return { } ;
205
- }
206
-
207
174
async ping ( _request : PingRequest , _context : CallContext ) : Promise < { } > {
208
175
return { } ;
209
176
}
0 commit comments