Skip to content

Commit

Permalink
Define proto
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Nov 12, 2023
1 parent 5c70155 commit 0584387
Show file tree
Hide file tree
Showing 14 changed files with 799 additions and 262 deletions.
25 changes: 25 additions & 0 deletions components/dashboard/src/service/json-rpc-workspace-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ import {
GetWorkspaceResponse,
WatchWorkspaceStatusRequest,
WatchWorkspaceStatusResponse,
ListWorkspacesRequest,
ListWorkspacesResponse,
} from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
import { converter } from "./public-api";
import { getGitpodService } from "./service";
import { PaginationResponse } from "@gitpod/public-api/lib/gitpod/v1/pagination_pb";
import { generateAsyncGenerator } from "@gitpod/gitpod-protocol/lib/generate-async-generator";
import { WorkspaceInstance } from "@gitpod/gitpod-protocol";
import { parsePagination } from "@gitpod/gitpod-protocol/lib/public-api-utils";

export class JsonRpcWorkspaceClient implements PromiseClient<typeof WorkspaceService> {
async getWorkspace(request: PartialMessage<GetWorkspaceRequest>): Promise<GetWorkspaceResponse> {
Expand Down Expand Up @@ -80,4 +84,25 @@ export class JsonRpcWorkspaceClient implements PromiseClient<typeof WorkspaceSer
yield response;
}
}

async listWorkspaces(
request: PartialMessage<ListWorkspacesRequest>,
_options?: CallOptions,
): Promise<ListWorkspacesResponse> {
const { limit } = parsePagination(request.pagination, 50);

let resultTotal = 0;
const results = await getGitpodService().server.getWorkspaces({
limit,
pinnedOnly: request.pinned,
searchString: request.searchTerm,
organizationId: request.organizationId,
});
resultTotal = results.length;
const response = new ListWorkspacesResponse();
response.workspaces = results.map((info) => converter.toWorkspace(info));
response.pagination = new PaginationResponse();
response.pagination.total = resultTotal;
return response;
}
}
3 changes: 3 additions & 0 deletions components/dashboard/src/service/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export const organizationClient = createServiceClient(
// No jsonrcp client for the configuration service as it's only used in new UI of the dashboard
export const configurationClient = createServiceClient(ConfigurationService);

// @ts-ignore
window.$workspaceClient = workspaceClient;

export async function listAllProjects(opts: { orgId: string }): Promise<ProtocolProject[]> {
let pagination = {
page: 1,
Expand Down
3 changes: 3 additions & 0 deletions components/gitpod-protocol/src/messaging/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ export const ErrorCodes = {
// 501 EE Feature
EE_FEATURE: 501 as const,

// 501 Not Implemented
NOT_IMPLEMENTED: 501 as const,

// 555 EE License Required
EE_LICENSE_REQUIRED: 555 as const,

Expand Down
31 changes: 31 additions & 0 deletions components/gitpod-protocol/src/public-api-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/

import { PaginationRequest } from "@gitpod/public-api/lib/gitpod/v1/pagination_pb";

export interface ParsedPagination {
offset: number;
limit: number;
}

const MAX_PAGE_SIZE = 100;
export function parsePagination(
pagination: Partial<PaginationRequest> | undefined,
defaultPageSize = 50,
): ParsedPagination {
let limit = pagination?.pageSize ?? defaultPageSize;
if (limit < 1) {
limit = defaultPageSize;
}
if (limit > MAX_PAGE_SIZE) {
limit = MAX_PAGE_SIZE;
}
const offset = (pagination?.page ?? 0) * limit;
return {
offset,
limit,
};
}
2 changes: 2 additions & 0 deletions components/public-api/buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ breaking:
ignore:
# Do not enforce breaking change detection for the experimental package
- gitpod/experimental
# TODO enable again after landing style changes
- gitpod/v1
lint:
use:
- DEFAULT
Expand Down
2 changes: 2 additions & 0 deletions components/public-api/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ rm -rf go/experimental
protoc_buf_generate

update_license

yarn --cwd typescript build
33 changes: 32 additions & 1 deletion components/public-api/gitpod/v1/workspace.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
package gitpod.v1;

import "google/protobuf/timestamp.proto";
import "gitpod/v1/pagination.proto";

option go_package = "github.com/gitpod-io/gitpod/components/public-api/go/v1";

Expand All @@ -16,7 +17,11 @@ service WorkspaceService {
// WatchWorkspaceStatus watchs the workspaces status changes
//
// workspace_id +return NOT_FOUND Workspace does not exist
rpc WatchWorkspaceStatus(WatchWorkspaceStatusRequest) returns (stream WatchWorkspaceStatusResponse) {}
rpc WatchWorkspaceStatus(WatchWorkspaceStatusRequest)
returns (stream WatchWorkspaceStatusResponse) {}

// ListWorkspaces returns a list of workspaces that match the query.
rpc ListWorkspaces(ListWorkspacesRequest) returns (ListWorkspacesResponse) {}
}

message GetWorkspaceRequest { string id = 1; }
Expand All @@ -38,6 +43,32 @@ message WatchWorkspaceStatusResponse {
WorkspaceStatus status = 2;
}

message ListWorkspacesRequest {
// pagination contains the pagination options for listing workspaces
PaginationRequest pagination = 1;

// organization_id is the ID of the organization that contains the workspaces
string organization_id = 2;

// pinned indicates whether to list only pinned workspaces
bool pinned = 3;

// search_term is a search term to filter workspaces by name
string search_term = 4;

string workspace_id = 5;

string owner_id = 6;
}

message ListWorkspacesResponse {
// workspaces are the workspaces that matched the query
repeated Workspace workspaces = 1;

// pagination contains the pagination options for listing workspaces
PaginationResponse pagination = 2;
}

// +resource get workspace
message Workspace {
string id = 1;
Expand Down
24 changes: 24 additions & 0 deletions components/public-api/go/v1/v1connect/workspace.connect.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions components/public-api/go/v1/v1connect/workspace.proxy.connect.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0584387

Please sign in to comment.