Skip to content

Commit 8bc26b0

Browse files
committed
Implement
1 parent a852892 commit 8bc26b0

File tree

7 files changed

+425
-277
lines changed

7 files changed

+425
-277
lines changed

components/dashboard/src/service/json-rpc-workspace-client.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,11 @@ export class JsonRpcWorkspaceClient implements PromiseClient<typeof WorkspaceSer
200200
if (!request.workspaceId) {
201201
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "workspaceId is required");
202202
}
203+
204+
// check if user can access workspace first
205+
await this.getWorkspace({ workspaceId: request.workspaceId });
206+
203207
const server = getGitpodService().server;
204-
// tasks to wait for promise all with type defined
205208
const tasks: Array<Promise<any>> = [];
206209

207210
if (request.name) {
@@ -218,7 +221,6 @@ export class JsonRpcWorkspaceClient implements PromiseClient<typeof WorkspaceSer
218221
tasks.push(server.updateWorkspaceUserPin(request.workspaceId, request.pinned ? "pin" : "unpin"));
219222
}
220223
if (Number(request.timeout?.seconds ?? 0) > 0) {
221-
// convert request.timeout into format like 3h or 3d
222224
const timeout = converter.toDurationString(request.timeout!);
223225
tasks.push(server.setWorkspaceTimeout(request.workspaceId, timeout));
224226
}
@@ -249,7 +251,10 @@ export class JsonRpcWorkspaceClient implements PromiseClient<typeof WorkspaceSer
249251
request: PartialMessage<ListWorkspaceClassesRequest>,
250252
_options?: CallOptions | undefined,
251253
): Promise<ListWorkspaceClassesResponse> {
252-
// const list = await getGitpodService().server.getSupportedWorkspaceClasses();
253-
throw new ApplicationError(ErrorCodes.UNIMPLEMENTED, "not implemented");
254+
const list = await getGitpodService().server.getSupportedWorkspaceClasses();
255+
const response = new ListWorkspaceClassesResponse();
256+
response.pagination = new PaginationResponse();
257+
response.workspaceClasses = list.map((i) => converter.toWorkspaceClass(i));
258+
return response;
254259
}
255260
}

components/gitpod-protocol/src/public-api-converter.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import {
6464
TooManyRunningWorkspacesError,
6565
} from "@gitpod/public-api/lib/gitpod/v1/error_pb";
6666
import { SSHPublicKey } from "@gitpod/public-api/lib/gitpod/v1/ssh_pb";
67+
import { SupportedWorkspaceClass } from "./workspace-class";
6768

6869
describe("PublicAPIConverter", () => {
6970
const converter = new PublicAPIConverter();
@@ -1432,4 +1433,22 @@ describe("PublicAPIConverter", () => {
14321433
);
14331434
});
14341435
});
1436+
1437+
describe("toWorkspaceClass", () => {
1438+
it("should convert a SupportedWorkspaceClass to WorkspaceClass", () => {
1439+
const cls: SupportedWorkspaceClass = {
1440+
id: "g1-standard",
1441+
category: "GENERAL PURPOSE",
1442+
displayName: "Standard",
1443+
description: "Up to 4 cores, 8GB RAM, 30GB storage",
1444+
powerups: 1,
1445+
isDefault: true,
1446+
};
1447+
const converted = converter.toWorkspaceClass(cls);
1448+
expect(converted.id).to.equal(cls.id);
1449+
expect(converted.displayName).to.equal(cls.displayName);
1450+
expect(converted.description).to.equal(cls.description);
1451+
expect(converted.isDefault).to.equal(cls.isDefault);
1452+
});
1453+
});
14351454
});

components/gitpod-protocol/src/public-api-converter.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
AdmissionLevel,
4242
EditorReference,
4343
Workspace,
44+
WorkspaceClass,
4445
WorkspaceConditions,
4546
WorkspaceEnvironmentVariable,
4647
WorkspaceGitStatus,
@@ -109,6 +110,7 @@ import {
109110
} from "./workspace-instance";
110111
import { Author, Commit } from "@gitpod/public-api/lib/gitpod/v1/scm_pb";
111112
import type { DeepPartial } from "./util/deep-partial";
113+
import { SupportedWorkspaceClass } from "./workspace-class";
112114

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

@@ -961,4 +963,13 @@ export class PublicAPIConverter {
961963
nanos: (totalSeconds - Math.floor(totalSeconds)) * 1e9,
962964
});
963965
}
966+
967+
toWorkspaceClass(cls: SupportedWorkspaceClass): WorkspaceClass {
968+
return new WorkspaceClass({
969+
id: cls.id,
970+
displayName: cls.displayName,
971+
description: cls.description,
972+
isDefault: cls.isDefault,
973+
});
974+
}
964975
}

components/public-api/gitpod/v1/workspace.proto

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,14 @@ message UpdateWorkspaceRequest {
211211
optional WorkspaceGitStatus git_status = 6;
212212
}
213213

214-
message ListWorkspaceClassesRequest {}
214+
message ListWorkspaceClassesRequest {
215+
PaginationRequest pagination = 1;
216+
}
215217

216218
message ListWorkspaceClassesResponse {
217-
repeated WorkspaceClass result = 1;
219+
PaginationResponse pagination = 1;
220+
221+
repeated WorkspaceClass workspace_classes = 2;
218222
}
219223

220224
message UpdateWorkspaceResponse {

0 commit comments

Comments
 (0)