@@ -111,7 +111,6 @@ import {
111111 PortProtocol as ProtoPortProtocol ,
112112 StopWorkspacePolicy ,
113113 TakeSnapshotRequest ,
114- UpdateSSHKeyRequest ,
115114} from "@gitpod/ws-manager/lib/core_pb" ;
116115import * as crypto from "crypto" ;
117116import { inject , injectable } from "inversify" ;
@@ -194,6 +193,7 @@ import { RedisSubscriber } from "../messaging/redis-subscriber";
194193import { UsageService } from "../orgs/usage-service" ;
195194import { UserService } from "../user/user-service" ;
196195import { WorkspaceService } from "./workspace-service" ;
196+ import { SSHKeyService } from "../user/sshkey-service" ;
197197
198198// shortcut
199199export const traceWI = ( ctx : TraceContext , wi : Omit < LogContext , "userId" > ) => TraceContext . setOWI ( ctx , wi ) ; // userId is already taken care of in WebsocketConnectionManager
@@ -236,6 +236,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
236236 @inject ( UserDeletionService ) private readonly userDeletionService : UserDeletionService ,
237237 @inject ( IAnalyticsWriter ) private readonly analytics : IAnalyticsWriter ,
238238 @inject ( AuthorizationService ) private readonly authorizationService : AuthorizationService ,
239+ @inject ( SSHKeyService ) private readonly sshKeyservice : SSHKeyService ,
239240
240241 @inject ( TeamDB ) private readonly teamDB : TeamDB ,
241242 @inject ( OrganizationService ) private readonly organizationService : OrganizationService ,
@@ -2445,59 +2446,22 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
24452446
24462447 async hasSSHPublicKey ( ctx : TraceContext ) : Promise < boolean > {
24472448 const user = await this . checkUser ( "hasSSHPublicKey" ) ;
2448- return this . userDB . hasSSHPublicKey ( user . id ) ;
2449+ return this . sshKeyservice . hasSSHPublicKey ( user . id ) ;
24492450 }
24502451
24512452 async getSSHPublicKeys ( ctx : TraceContext ) : Promise < UserSSHPublicKeyValue [ ] > {
24522453 const user = await this . checkUser ( "getSSHPublicKeys" ) ;
2453- const list = await this . userDB . getSSHPublicKeys ( user . id ) ;
2454- return list . map ( ( e ) => ( {
2455- id : e . id ,
2456- name : e . name ,
2457- key : e . key ,
2458- fingerprint : e . fingerprint ,
2459- creationTime : e . creationTime ,
2460- lastUsedTime : e . lastUsedTime ,
2461- } ) ) ;
2454+ return this . sshKeyservice . getSSHPublicKeys ( user . id ) ;
24622455 }
24632456
24642457 async addSSHPublicKey ( ctx : TraceContext , value : SSHPublicKeyValue ) : Promise < UserSSHPublicKeyValue > {
24652458 const user = await this . checkUser ( "addSSHPublicKey" ) ;
2466- const data = await this . userDB . addSSHPublicKey ( user . id , value ) ;
2467- this . updateSSHKeysForRegularRunningInstances ( ctx , user . id ) . catch ( console . error ) ;
2468- return {
2469- id : data . id ,
2470- name : data . name ,
2471- key : data . key ,
2472- fingerprint : data . fingerprint ,
2473- creationTime : data . creationTime ,
2474- lastUsedTime : data . lastUsedTime ,
2475- } ;
2459+ return this . sshKeyservice . addSSHPublicKey ( user . id , value ) ;
24762460 }
24772461
24782462 async deleteSSHPublicKey ( ctx : TraceContext , id : string ) : Promise < void > {
24792463 const user = await this . checkUser ( "deleteSSHPublicKey" ) ;
2480- await this . userDB . deleteSSHPublicKey ( user . id , id ) ;
2481- this . updateSSHKeysForRegularRunningInstances ( ctx , user . id ) . catch ( console . error ) ;
2482- return ;
2483- }
2484-
2485- private async updateSSHKeysForRegularRunningInstances ( ctx : TraceContext , userId : string ) {
2486- const keys = ( await this . userDB . getSSHPublicKeys ( userId ) ) . map ( ( e ) => e . key ) ;
2487- const instances = await this . workspaceDb . trace ( ctx ) . findRegularRunningInstances ( userId ) ;
2488- const updateKeyOfInstance = async ( instance : WorkspaceInstance ) => {
2489- try {
2490- const req = new UpdateSSHKeyRequest ( ) ;
2491- req . setId ( instance . id ) ;
2492- req . setKeysList ( keys ) ;
2493- const cli = await this . workspaceManagerClientProvider . get ( instance . region ) ;
2494- await cli . updateSSHPublicKey ( ctx , req ) ;
2495- } catch ( err ) {
2496- const logCtx = { userId, instanceId : instance . id } ;
2497- log . error ( logCtx , "Could not update ssh public key for instance" , err ) ;
2498- }
2499- } ;
2500- return Promise . allSettled ( instances . map ( ( e ) => updateKeyOfInstance ( e ) ) ) ;
2464+ return this . sshKeyservice . deleteSSHPublicKey ( user . id , id ) ;
25012465 }
25022466
25032467 async setProjectEnvironmentVariable (
0 commit comments