From 73c4753a5d1ef4976121139b8c0ae3909f67075b Mon Sep 17 00:00:00 2001 From: Huiwen Date: Thu, 21 Sep 2023 10:17:13 +0000 Subject: [PATCH] [server] update getDefaultWorkspaceImage api --- .../gitpod-protocol/src/gitpod-service.ts | 16 +++++++++++- .../src/workspace/gitpod-server-impl.ts | 26 ++++++++++++++++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/components/gitpod-protocol/src/gitpod-service.ts b/components/gitpod-protocol/src/gitpod-service.ts index 466aab0210dddd..5ca937ca914636 100644 --- a/components/gitpod-protocol/src/gitpod-service.ts +++ b/components/gitpod-protocol/src/gitpod-service.ts @@ -173,7 +173,7 @@ export interface GitpodServer extends JsonRpcServer, AdminServer, getOrgAuthProviders(params: GitpodServer.GetOrgAuthProviderParams): Promise; deleteOrgAuthProvider(params: GitpodServer.DeleteOrgAuthProviderParams): Promise; - getDefaultWorkspaceImage(): Promise; + getDefaultWorkspaceImage(params: GetDefaultWorkspaceImageParams): Promise; // Dedicated, Dedicated, Dedicated getOnboardingState(): Promise; @@ -280,6 +280,20 @@ export interface RateLimiterError { retryAfter: number; } +export interface GetDefaultWorkspaceImageParams { + // filter with workspaceId (actually we will find with organizationId, and it's a real time finding) + workspaceId?: string; +} + +export type DefaultImageSource = + | "installation" // Source installation means the image comes from Gitpod instance install config + | "organization"; // Source organization means the image comes from Organization settings + +export interface GetDefaultWorkspaceImageResult { + image: string; + source: DefaultImageSource; +} + export interface CreateProjectParams { name: string; /** @deprecated unused */ diff --git a/components/server/src/workspace/gitpod-server-impl.ts b/components/server/src/workspace/gitpod-server-impl.ts index 878ef3970eeaab..fc3d01c7d39170 100644 --- a/components/server/src/workspace/gitpod-server-impl.ts +++ b/components/server/src/workspace/gitpod-server-impl.ts @@ -68,6 +68,8 @@ import { WorkspaceInstanceRepoStatus, GetProviderRepositoriesParams, SuggestedRepository, + GetDefaultWorkspaceImageParams, + GetDefaultWorkspaceImageResult, } from "@gitpod/gitpod-protocol"; import { BlockedRepository } from "@gitpod/gitpod-protocol/lib/blocked-repositories-protocol"; import { @@ -2518,10 +2520,26 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable { return this.organizationService.updateSettings(user.id, orgId, settings); } - async getDefaultWorkspaceImage(ctx: TraceContextWithSpan): Promise { - const userId = this.userID; - traceAPIParams(ctx, { userId }); - return this.config.workspaceDefaults.workspaceImage; + async getDefaultWorkspaceImage( + ctx: TraceContextWithSpan, + params: GetDefaultWorkspaceImageParams, + ): Promise { + const user = await this.checkAndBlockUser("getDefaultWorkspaceImage"); + traceAPIParams(ctx, { params, userId: user.id }); + if (params.workspaceId) { + const workspace = await this.getWorkspace(ctx, params.workspaceId); + const orgSettings = await this.organizationService.getSettings(user.id, workspace.workspace.organizationId); + if (orgSettings.defaultWorkspaceImage) { + return { + image: orgSettings.defaultWorkspaceImage, + source: "organization", + }; + } + } + return { + image: this.config.workspaceDefaults.workspaceImage, + source: "installation", + }; } public async getTeamProjects(ctx: TraceContext, teamId: string): Promise {