Skip to content

Commit

Permalink
[papi] add getDefaultWorkspaceImage method
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Sep 21, 2023
1 parent 82652d5 commit 00ee208
Show file tree
Hide file tree
Showing 10 changed files with 636 additions and 204 deletions.
26 changes: 26 additions & 0 deletions components/public-api-server/pkg/apiv1/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,32 @@ func (s *WorkspaceService) ListWorkspaceClasses(ctx context.Context, req *connec
), nil
}

func (s *WorkspaceService) GetDefaultWorkspaceImage(ctx context.Context, req *connect.Request[v1.GetDefaultWorkspaceImageRequest]) (*connect.Response[v1.GetDefaultWorkspaceImageResponse], error) {
conn, err := getConnection(ctx, s.connectionPool)
if err != nil {
return nil, err
}
wsImage, err := conn.GetDefaultWorkspaceImage(ctx, &protocol.GetDefaultWorkspaceImageParams{
WorkspaceID: req.Msg.GetWorkspaceId(),
})
if err != nil {
log.Extract(ctx).WithError(err).Error("Failed to get default workspace image.")
return nil, proxy.ConvertError(err)
}

source := v1.GetDefaultWorkspaceImageResponse_IMAGE_SOURCE_UNSPECIFIED
if wsImage.Source == protocol.WorkspaceImageSourceInstallation {
source = v1.GetDefaultWorkspaceImageResponse_IMAGE_SOURCE_INSTALLATION
} else if wsImage.Source == protocol.WorkspaceImageSourceOrganization {
source = v1.GetDefaultWorkspaceImageResponse_IMAGE_SOURCE_ORGANIZATION
}

return connect.NewResponse(&v1.GetDefaultWorkspaceImageResponse{
Image: wsImage.Image,
Source: source,
}), nil
}

func getLimitFromPagination(pagination *v1.Pagination) (int, error) {
const (
defaultLimit = 20
Expand Down
25 changes: 25 additions & 0 deletions components/public-api/gitpod/experimental/v1/workspaces.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ service WorkspacesService {

// ListWorkspaceClasses enumerates all available workspace classes.
rpc ListWorkspaceClasses(ListWorkspaceClassesRequest) returns (ListWorkspaceClassesResponse) {}

// GetDefaultWorkspaceImage returns the default workspace image from different sources.
rpc GetDefaultWorkspaceImage(GetDefaultWorkspaceImageRequest) returns (GetDefaultWorkspaceImageResponse) {}
}

message ListWorkspacesRequest {
Expand Down Expand Up @@ -433,3 +436,25 @@ message WorkspaceClass {
// is_default indicates if this workspace class is the default one
bool is_default = 4;
}

message GetDefaultWorkspaceImageRequest {
optional string workspace_id = 1;
}

message GetDefaultWorkspaceImageResponse {
enum ImageSource {
IMAGE_SOURCE_UNSPECIFIED = 0;

// IMAGE_SOURCE_INSTALLATION means the image from Gitpod instance install config
IMAGE_SOURCE_INSTALLATION = 1;

// IMAGE_SOURCE_ORGANIZATION means the image from Organization settings
IMAGE_SOURCE_ORGANIZATION = 2;
}

// image is the image ref
string image = 1;

// source is the source of the image
ImageSource source = 2;
}
87 changes: 33 additions & 54 deletions components/public-api/go/experimental/v1/dummy.pb.go

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

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

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

Loading

0 comments on commit 00ee208

Please sign in to comment.