Skip to content

Commit

Permalink
Implement
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Nov 23, 2023
1 parent 8b6f63f commit b897f2c
Show file tree
Hide file tree
Showing 7 changed files with 425 additions and 277 deletions.
13 changes: 9 additions & 4 deletions components/dashboard/src/service/json-rpc-workspace-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,11 @@ export class JsonRpcWorkspaceClient implements PromiseClient<typeof WorkspaceSer
if (!request.workspaceId) {
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "workspaceId is required");
}

// check if user can access workspace first
await this.getWorkspace({ workspaceId: request.workspaceId });

const server = getGitpodService().server;
// tasks to wait for promise all with type defined
const tasks: Array<Promise<any>> = [];

if (request.name) {
Expand All @@ -218,7 +221,6 @@ export class JsonRpcWorkspaceClient implements PromiseClient<typeof WorkspaceSer
tasks.push(server.updateWorkspaceUserPin(request.workspaceId, request.pinned ? "pin" : "unpin"));
}
if (Number(request.timeout?.seconds ?? 0) > 0) {
// convert request.timeout into format like 3h or 3d
const timeout = converter.toDurationString(request.timeout!);
tasks.push(server.setWorkspaceTimeout(request.workspaceId, timeout));
}
Expand Down Expand Up @@ -249,7 +251,10 @@ export class JsonRpcWorkspaceClient implements PromiseClient<typeof WorkspaceSer
request: PartialMessage<ListWorkspaceClassesRequest>,
_options?: CallOptions | undefined,
): Promise<ListWorkspaceClassesResponse> {
// const list = await getGitpodService().server.getSupportedWorkspaceClasses();
throw new ApplicationError(ErrorCodes.UNIMPLEMENTED, "not implemented");
const list = await getGitpodService().server.getSupportedWorkspaceClasses();
const response = new ListWorkspaceClassesResponse();
response.pagination = new PaginationResponse();
response.workspaceClasses = list.map((i) => converter.toWorkspaceClass(i));
return response;
}
}
19 changes: 19 additions & 0 deletions components/gitpod-protocol/src/public-api-converter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
ImageBuildLogsNotYetAvailableError,
TooManyRunningWorkspacesError,
} from "@gitpod/public-api/lib/gitpod/v1/error_pb";
import { SupportedWorkspaceClass } from "./workspace-class";

describe("PublicAPIConverter", () => {
const converter = new PublicAPIConverter();
Expand Down Expand Up @@ -1404,4 +1405,22 @@ describe("PublicAPIConverter", () => {
);
});
});

describe("toWorkspaceClass", () => {
it("should convert a SupportedWorkspaceClass to WorkspaceClass", () => {
const cls: SupportedWorkspaceClass = {
id: "g1-standard",
category: "GENERAL PURPOSE",
displayName: "Standard",
description: "Up to 4 cores, 8GB RAM, 30GB storage",
powerups: 1,
isDefault: true,
};
const converted = converter.toWorkspaceClass(cls);
expect(converted.id).to.equal(cls.id);
expect(converted.displayName).to.equal(cls.displayName);
expect(converted.description).to.equal(cls.description);
expect(converted.isDefault).to.equal(cls.isDefault);
});
});
});
11 changes: 11 additions & 0 deletions components/gitpod-protocol/src/public-api-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
AdmissionLevel,
EditorReference,
Workspace,
WorkspaceClass,
WorkspaceConditions,
WorkspaceEnvironmentVariable,
WorkspaceGitStatus,
Expand Down Expand Up @@ -107,6 +108,7 @@ import {
} from "./workspace-instance";
import { Author, Commit } from "@gitpod/public-api/lib/gitpod/v1/scm_pb";
import type { DeepPartial } from "./util/deep-partial";
import { SupportedWorkspaceClass } from "./workspace-class";

export type PartialConfiguration = DeepPartial<Configuration> & Pick<Configuration, "id">;

Expand Down Expand Up @@ -948,4 +950,13 @@ export class PublicAPIConverter {
nanos: (totalSeconds - Math.floor(totalSeconds)) * 1e9,
});
}

toWorkspaceClass(cls: SupportedWorkspaceClass): WorkspaceClass {
return new WorkspaceClass({
id: cls.id,
displayName: cls.displayName,
description: cls.description,
isDefault: cls.isDefault,
});
}
}
8 changes: 6 additions & 2 deletions components/public-api/gitpod/v1/workspace.proto
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,14 @@ message UpdateWorkspaceRequest {
optional WorkspaceGitStatus git_status = 6;
}

message ListWorkspaceClassesRequest {}
message ListWorkspaceClassesRequest {
PaginationRequest pagination = 1;
}

message ListWorkspaceClassesResponse {
repeated WorkspaceClass result = 1;
PaginationResponse pagination = 1;

repeated WorkspaceClass workspace_classes = 2;
}

message UpdateWorkspaceResponse {
Expand Down
Loading

0 comments on commit b897f2c

Please sign in to comment.