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 , SendErrorReportRequest , SendLocalSSHUserFlowStatusRequest , SendLocalSSHUserFlowStatusRequest_Code , SendLocalSSHUserFlowStatusRequest_ConnType , SendLocalSSHUserFlowStatusRequest_Status } from '../../proto/typescript/ipc/v1/ipc' ;
6
+ import { ExtensionServiceDefinition , ExtensionServiceImplementation , GetWorkspaceAuthInfoRequest , GetWorkspaceAuthInfoResponse , SendErrorReportRequest , SendLocalSSHUserFlowStatusRequest } from '../../proto/typescript/ipc/v1/ipc' ;
7
7
import { Disposable } from '../../common/dispose' ;
8
8
export { ExtensionServiceDefinition } from '../../proto/typescript/ipc/v1/ipc' ;
9
9
import { withServerApi } from '../../internalApi' ;
@@ -49,28 +49,28 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
49
49
50
50
}
51
51
52
- private async getWorkspaceSSHKey ( ownerToken :string , workspaceId : string , workspaceHost : string ) {
53
- const workspaceUrl = `https://${ workspaceId } .${ workspaceHost } ` ;
54
- const metadata = new BrowserHeaders ( ) ;
55
- metadata . append ( 'x-gitpod-owner-token' , ownerToken ) ;
56
- const client = new ControlServiceClient ( `${ workspaceUrl } /_supervisor/v1` , { transport : NodeHttpTransport ( ) } ) ;
57
-
58
- const privateKey = await new Promise < string > ( ( resolve , reject ) => {
59
- client . createSSHKeyPair ( new CreateSSHKeyPairRequest ( ) , metadata , ( err , resp ) => {
60
- if ( err ) {
61
- return reject ( err ) ;
62
- }
63
- resolve ( resp ! . toObject ( ) . privateKey ) ;
64
- } ) ;
65
- } ) ;
66
-
67
- const parsedResult = ssh2 . utils . parseKey ( privateKey ) ;
68
- if ( parsedResult instanceof Error || ! parsedResult ) {
69
- throw new Error ( 'Error while parsing workspace SSH private key' ) ;
70
- }
71
-
72
- return ( parsedResult as ParsedKey ) . getPrivatePEM ( ) ;
73
- }
52
+ private async getWorkspaceSSHKey ( ownerToken : string , workspaceId : string , workspaceHost : string ) {
53
+ const workspaceUrl = `https://${ workspaceId } .${ workspaceHost } ` ;
54
+ const metadata = new BrowserHeaders ( ) ;
55
+ metadata . append ( 'x-gitpod-owner-token' , ownerToken ) ;
56
+ const client = new ControlServiceClient ( `${ workspaceUrl } /_supervisor/v1` , { transport : NodeHttpTransport ( ) } ) ;
57
+
58
+ const privateKey = await new Promise < string > ( ( resolve , reject ) => {
59
+ client . createSSHKeyPair ( new CreateSSHKeyPairRequest ( ) , metadata , ( err , resp ) => {
60
+ if ( err ) {
61
+ return reject ( err ) ;
62
+ }
63
+ resolve ( resp ! . toObject ( ) . privateKey ) ;
64
+ } ) ;
65
+ } ) ;
66
+
67
+ const parsedResult = ssh2 . utils . parseKey ( privateKey ) ;
68
+ if ( parsedResult instanceof Error || ! parsedResult ) {
69
+ throw new Error ( 'Error while parsing workspace SSH private key' ) ;
70
+ }
71
+
72
+ return ( parsedResult as ParsedKey ) . getPrivatePEM ( ) ;
73
+ }
74
74
75
75
async getWorkspaceAuthInfo ( request : GetWorkspaceAuthInfoRequest , _context : CallContext ) : Promise < GetWorkspaceAuthInfoResponse > {
76
76
try {
@@ -90,7 +90,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
90
90
91
91
const phase = usePublicApi ? phaseMap [ ( workspace as Workspace ) . status ?. instance ?. status ?. phase ?? WorkspaceInstanceStatus_Phase . UNSPECIFIED ] : ( workspace as WorkspaceInfo ) . latestInstance ?. status . phase ;
92
92
if ( phase !== 'running' ) {
93
- // TODO(lssh): extension child ipc broadcasts this error to all windows (window itself will figure it out if it needs to be shown)
93
+ // TODO(lssh): notification?
94
94
throw new ServerError ( Status . UNAVAILABLE , 'workspace is not running, current phase: ' + phase ) ;
95
95
}
96
96
@@ -102,7 +102,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
102
102
const workspaceHost = url . host . substring ( url . host . indexOf ( '.' ) + 1 ) ;
103
103
const instanceId = ( usePublicApi ? ( workspace as Workspace ) . status ?. instance ?. instanceId : ( workspace as WorkspaceInfo ) . latestInstance ?. id ) as string ;
104
104
105
- const sshkey = await this . getWorkspaceSSHKey ( ownerToken , workspaceId , workspaceHost ) ;
105
+ const sshkey = await this . getWorkspaceSSHKey ( ownerToken , workspaceId , workspaceHost ) ;
106
106
107
107
return {
108
108
gitpodHost,
@@ -121,22 +121,19 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
121
121
122
122
// TODO remove from protocol, don't pass sensitive info back and forth, only once for auth, daemon should do telemetry directly
123
123
async sendLocalSSHUserFlowStatus ( request : SendLocalSSHUserFlowStatusRequest , _context : CallContext ) : Promise < { } > {
124
+ if ( ! request . flowStatus || request . flowStatus === '' ) {
125
+ return { } ;
126
+ }
124
127
const flow : UserFlowTelemetry = {
125
- flow : 'ssh' ,
126
- kind : 'local-ssh' ,
127
- connType : request . connType === SendLocalSSHUserFlowStatusRequest_ConnType . CONN_TYPE_SSH ? 'ssh' : 'tunnel' ,
128
+ flow : 'local_ssh' ,
128
129
workspaceId : request . workspaceId ,
129
130
instanceId : request . instanceId ,
130
131
daemonVersion : request . daemonVersion ,
131
132
userId : request . userId ,
132
133
gitpodHost : request . gitpodHost ,
133
- // extensionVersion : request.extensionVersion ,
134
+ failureCode : request . flowFailureCode ,
134
135
} ;
135
- if ( request . status !== SendLocalSSHUserFlowStatusRequest_Status . STATUS_SUCCESS && request . failureCode !== SendLocalSSHUserFlowStatusRequest_Code . CODE_UNSPECIFIED ) {
136
- flow . reasonCode = SendLocalSSHUserFlowStatusRequest_Code [ request . failureCode ] ;
137
- }
138
- const status = request . status === SendLocalSSHUserFlowStatusRequest_Status . STATUS_SUCCESS ? 'local-ssh-success' : 'local-ssh-failure' ;
139
- this . telemetryService . sendUserFlowStatus ( status , flow ) ;
136
+ this . telemetryService . sendUserFlowStatus ( request . flowStatus , flow ) ;
140
137
return { } ;
141
138
}
142
139
0 commit comments