@@ -58,6 +58,7 @@ import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messag
5858import  {  ContextService  }  from  "../workspace/context-service" ; 
5959import  {  UserService  }  from  "../user/user-service" ; 
6060import  {  ContextParser  }  from  "../workspace/context-parser-service" ; 
61+ import  {  matchesNewWorkspaceIdExactly  as  isWorkspaceId  }  from  "@gitpod/gitpod-protocol/lib/util/parse-workspace-id" ; 
6162
6263@injectable ( ) 
6364export  class  WorkspaceServiceAPI  implements  ServiceImpl < typeof  WorkspaceServiceInterface >  { 
@@ -68,8 +69,8 @@ export class WorkspaceServiceAPI implements ServiceImpl<typeof WorkspaceServiceI
6869    @inject ( ContextParser )  private  contextParser : ContextParser ; 
6970
7071    async  getWorkspace ( req : GetWorkspaceRequest ,  _ : HandlerContext ) : Promise < GetWorkspaceResponse >  { 
71-         if  ( ! req . workspaceId )  { 
72-             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "workspaceId is required" ) ; 
72+         if  ( ! isWorkspaceId ( req . workspaceId ) )  { 
73+             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "a valid  workspaceId is required" ) ; 
7374        } 
7475        const  info  =  await  this . workspaceService . getWorkspace ( ctxUserId ( ) ,  req . workspaceId ) ; 
7576        const  response  =  new  GetWorkspaceResponse ( ) ; 
@@ -198,8 +199,8 @@ export class WorkspaceServiceAPI implements ServiceImpl<typeof WorkspaceServiceI
198199
199200    async  startWorkspace ( req : StartWorkspaceRequest ) : Promise < StartWorkspaceResponse >  { 
200201        // We rely on FGA to do the permission checking 
201-         if  ( ! req . workspaceId )  { 
202-             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "workspaceId is required" ) ; 
202+         if  ( ! isWorkspaceId ( req . workspaceId ) )  { 
203+             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "a valid  workspaceId is required" ) ; 
203204        } 
204205        const  user  =  await  this . userService . findUserById ( ctxUserId ( ) ,  ctxUserId ( ) ) ; 
205206        const  {  workspace,  latestInstance : instance  }  =  await  this . workspaceService . getWorkspace ( 
@@ -227,8 +228,8 @@ export class WorkspaceServiceAPI implements ServiceImpl<typeof WorkspaceServiceI
227228        req : GetWorkspaceDefaultImageRequest , 
228229        _ : HandlerContext , 
229230    ) : Promise < GetWorkspaceDefaultImageResponse >  { 
230-         if  ( ! req . workspaceId )  { 
231-             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "workspaceId is required" ) ; 
231+         if  ( ! isWorkspaceId ( req . workspaceId ) )  { 
232+             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "a valid  workspaceId is required" ) ; 
232233        } 
233234        const  result  =  await  this . workspaceService . getWorkspaceDefaultImage ( ctxUserId ( ) ,  req . workspaceId ) ; 
234235        const  response  =  new  GetWorkspaceDefaultImageResponse ( { 
@@ -246,8 +247,8 @@ export class WorkspaceServiceAPI implements ServiceImpl<typeof WorkspaceServiceI
246247    } 
247248
248249    async  sendHeartBeat ( req : SendHeartBeatRequest ,  _ : HandlerContext ) : Promise < SendHeartBeatResponse >  { 
249-         if  ( ! req . workspaceId )  { 
250-             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "workspaceId is required" ) ; 
250+         if  ( ! isWorkspaceId ( req . workspaceId ) )  { 
251+             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "a valid  workspaceId is required" ) ; 
251252        } 
252253        const  info  =  await  this . workspaceService . getWorkspace ( ctxUserId ( ) ,  req . workspaceId ) ; 
253254        if  ( ! info . latestInstance ?. id  ||  info . latestInstance . status . phase  !==  "running" )  { 
@@ -265,8 +266,8 @@ export class WorkspaceServiceAPI implements ServiceImpl<typeof WorkspaceServiceI
265266        req : GetWorkspaceOwnerTokenRequest , 
266267        _ : HandlerContext , 
267268    ) : Promise < GetWorkspaceOwnerTokenResponse >  { 
268-         if  ( ! req . workspaceId )  { 
269-             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "workspaceId is required" ) ; 
269+         if  ( ! isWorkspaceId ( req . workspaceId ) )  { 
270+             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "a valid  workspaceId is required" ) ; 
270271        } 
271272        const  ownerToken  =  await  this . workspaceService . getOwnerToken ( ctxUserId ( ) ,  req . workspaceId ) ; 
272273        const  response  =  new  GetWorkspaceOwnerTokenResponse ( ) ; 
@@ -278,8 +279,8 @@ export class WorkspaceServiceAPI implements ServiceImpl<typeof WorkspaceServiceI
278279        req : GetWorkspaceEditorCredentialsRequest , 
279280        _ : HandlerContext , 
280281    ) : Promise < GetWorkspaceEditorCredentialsResponse >  { 
281-         if  ( ! req . workspaceId )  { 
282-             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "workspaceId is required" ) ; 
282+         if  ( ! isWorkspaceId ( req . workspaceId ) )  { 
283+             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "a valid  workspaceId is required" ) ; 
283284        } 
284285        const  credentials  =  await  this . workspaceService . getIDECredentials ( ctxUserId ( ) ,  req . workspaceId ) ; 
285286        const  response  =  new  GetWorkspaceEditorCredentialsResponse ( ) ; 
@@ -288,8 +289,8 @@ export class WorkspaceServiceAPI implements ServiceImpl<typeof WorkspaceServiceI
288289    } 
289290
290291    async  updateWorkspace ( req : UpdateWorkspaceRequest ) : Promise < UpdateWorkspaceResponse >  { 
291-         if  ( ! req . workspaceId )  { 
292-             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "workspaceId is required" ) ; 
292+         if  ( ! isWorkspaceId ( req . workspaceId ) )  { 
293+             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "a valid  workspaceId is required" ) ; 
293294        } 
294295        if  ( req . spec ?. timeout ?. inactivity ?. seconds  ||  ( req . spec ?. sshPublicKeys  &&  req . spec ?. sshPublicKeys . length  >  0 ) )  { 
295296            throw  new  ApplicationError ( ErrorCodes . UNIMPLEMENTED ,  "not implemented" ) ; 
@@ -363,17 +364,17 @@ export class WorkspaceServiceAPI implements ServiceImpl<typeof WorkspaceServiceI
363364    } 
364365
365366    async  stopWorkspace ( req : StopWorkspaceRequest ) : Promise < StopWorkspaceResponse >  { 
366-         if  ( ! req . workspaceId )  { 
367-             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "workspaceId is required" ) ; 
367+         if  ( ! isWorkspaceId ( req . workspaceId ) )  { 
368+             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "a valid  workspaceId is required" ) ; 
368369        } 
369370        await  this . workspaceService . stopWorkspace ( ctxUserId ( ) ,  req . workspaceId ,  "stopped via API" ) ; 
370371        const  response  =  new  StopWorkspaceResponse ( ) ; 
371372        return  response ; 
372373    } 
373374
374375    async  deleteWorkspace ( req : DeleteWorkspaceRequest ) : Promise < DeleteWorkspaceResponse >  { 
375-         if  ( ! req . workspaceId )  { 
376-             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "workspaceId is required" ) ; 
376+         if  ( ! isWorkspaceId ( req . workspaceId ) )  { 
377+             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "a valid  workspaceId is required" ) ; 
377378        } 
378379        await  this . workspaceService . deleteWorkspace ( ctxUserId ( ) ,  req . workspaceId ,  "user" ) ; 
379380        const  response  =  new  DeleteWorkspaceResponse ( ) ; 
@@ -389,8 +390,8 @@ export class WorkspaceServiceAPI implements ServiceImpl<typeof WorkspaceServiceI
389390    } 
390391
391392    async  createWorkspaceSnapshot ( req : CreateWorkspaceSnapshotRequest ) : Promise < CreateWorkspaceSnapshotResponse >  { 
392-         if  ( ! req . workspaceId )  { 
393-             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "workspaceId is required" ) ; 
393+         if  ( ! isWorkspaceId ( req . workspaceId ) )  { 
394+             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "a valid  workspaceId is required" ) ; 
394395        } 
395396        const  snapshot  =  await  this . workspaceService . takeSnapshot ( ctxUserId ( ) ,  { 
396397            workspaceId : req . workspaceId , 
@@ -410,8 +411,8 @@ export class WorkspaceServiceAPI implements ServiceImpl<typeof WorkspaceServiceI
410411    } 
411412
412413    async  updateWorkspacePort ( req : UpdateWorkspacePortRequest ) : Promise < UpdateWorkspacePortResponse >  { 
413-         if  ( ! req . workspaceId )  { 
414-             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "workspaceId is required" ) ; 
414+         if  ( ! isWorkspaceId ( req . workspaceId ) )  { 
415+             throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "a valid  workspaceId is required" ) ; 
415416        } 
416417        if  ( ! req . port )  { 
417418            throw  new  ApplicationError ( ErrorCodes . BAD_REQUEST ,  "port is required" ) ; 
0 commit comments