Skip to content

Commit

Permalink
[server] update getDefaultWorkspaceImage api
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Sep 21, 2023
1 parent cebee56 commit 73c4753
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
16 changes: 15 additions & 1 deletion components/gitpod-protocol/src/gitpod-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
getOrgAuthProviders(params: GitpodServer.GetOrgAuthProviderParams): Promise<AuthProviderEntry[]>;
deleteOrgAuthProvider(params: GitpodServer.DeleteOrgAuthProviderParams): Promise<void>;

getDefaultWorkspaceImage(): Promise<string>;
getDefaultWorkspaceImage(params: GetDefaultWorkspaceImageParams): Promise<GetDefaultWorkspaceImageResult>;

// Dedicated, Dedicated, Dedicated
getOnboardingState(): Promise<GitpodServer.OnboardingState>;
Expand Down Expand Up @@ -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 */
Expand Down
26 changes: 22 additions & 4 deletions components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -2518,10 +2520,26 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
return this.organizationService.updateSettings(user.id, orgId, settings);
}

async getDefaultWorkspaceImage(ctx: TraceContextWithSpan): Promise<string> {
const userId = this.userID;
traceAPIParams(ctx, { userId });
return this.config.workspaceDefaults.workspaceImage;
async getDefaultWorkspaceImage(
ctx: TraceContextWithSpan,
params: GetDefaultWorkspaceImageParams,
): Promise<GetDefaultWorkspaceImageResult> {
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<Project[]> {
Expand Down

0 comments on commit 73c4753

Please sign in to comment.