From 59be8d0c246bd7708a706ac903f2fffbb8a94492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Wed, 8 Feb 2023 09:57:49 +0000 Subject: [PATCH] Add a 24-hour timeout limit to workspace timeouts --- components/gitpod-protocol/src/gitpod-service.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/gitpod-protocol/src/gitpod-service.ts b/components/gitpod-protocol/src/gitpod-service.ts index 31f626816a5038..6470073eff891c 100644 --- a/components/gitpod-protocol/src/gitpod-service.ts +++ b/components/gitpod-protocol/src/gitpod-service.ts @@ -358,6 +358,8 @@ export interface ClientHeaderFields { clientRegion?: string; } +const WORKSPACE_MAXIMUM_TIMEOUT_HOURS = 24; + export type WorkspaceTimeoutDuration = string; export namespace WorkspaceTimeoutDuration { export function validate(duration: string): WorkspaceTimeoutDuration { @@ -369,6 +371,12 @@ export namespace WorkspaceTimeoutDuration { if (isNaN(value) || value <= 0) { throw new Error(`Invalid timeout value: ${duration}`); } + if ( + (unit === "h" && value > WORKSPACE_MAXIMUM_TIMEOUT_HOURS) || + (unit === "m" && value > WORKSPACE_MAXIMUM_TIMEOUT_HOURS * 60) + ) { + throw new Error(`Timeouts cannot extend to more than a day`); + } return duration; } }