Skip to content

Commit

Permalink
Migrate InstallationService GetInstallationWorkspaceDefaultImage meth…
Browse files Browse the repository at this point in the history
…od (#19221)
  • Loading branch information
mustard-mh authored Dec 8, 2023
1 parent 633f991 commit da125ed
Show file tree
Hide file tree
Showing 13 changed files with 581 additions and 247 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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 { useQuery } from "@tanstack/react-query";
import { installationClient } from "../../service/public-api";

export const useInstallationDefaultWorkspaceImageQuery = () => {
return useQuery({
queryKey: ["installation-default-workspace-image"],
staleTime: 1000 * 60 * 10, // 10 minute
queryFn: async () => {
const response = await installationClient.getInstallationWorkspaceDefaultImage({});
return response.defaultWorkspaceImage;
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,9 @@
*/

import { useQuery } from "@tanstack/react-query";
import { getGitpodService } from "../../service/service";
import { GetDefaultWorkspaceImageResult } from "@gitpod/gitpod-protocol";
import { GetWorkspaceDefaultImageResponse } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
import { workspaceClient } from "../../service/public-api";

export const useDefaultWorkspaceImageQuery = (workspaceId?: string) => {
return useQuery<GetDefaultWorkspaceImageResult>({
queryKey: ["default-workspace-image", { workspaceId }],
staleTime: 1000 * 60 * 10, // 10 minute
queryFn: async () => {
// without `workspaceId` getDefaultWorkspaceImage will return org setting and if not set fallback to installation
return await getGitpodService().server.getDefaultWorkspaceImage({ workspaceId });
},
});
};

export const useWorkspaceDefaultImageQuery = (workspaceId: string) => {
return useQuery<GetWorkspaceDefaultImageResponse>({
queryKey: ["default-workspace-image-v2", { workspaceId }],
Expand Down
13 changes: 13 additions & 0 deletions components/dashboard/src/service/json-rpc-installation-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,26 @@ import {
ListBlockedEmailDomainsResponse,
CreateBlockedEmailDomainRequest,
CreateBlockedEmailDomainResponse,
GetInstallationWorkspaceDefaultImageRequest,
GetInstallationWorkspaceDefaultImageResponse,
} from "@gitpod/public-api/lib/gitpod/v1/installation_pb";
import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
import { getGitpodService } from "./service";
import { converter } from "./public-api";
import { PaginationResponse } from "@gitpod/public-api/lib/gitpod/v1/pagination_pb";

export class JsonRpcInstallationClient implements PromiseClient<typeof InstallationService> {
async getInstallationWorkspaceDefaultImage(
_request: PartialMessage<GetInstallationWorkspaceDefaultImageRequest>,
_options?: CallOptions,
): Promise<GetInstallationWorkspaceDefaultImageResponse> {
const result = await getGitpodService().server.getDefaultWorkspaceImage({});
if (result.source !== "installation") {
throw new ApplicationError(ErrorCodes.INTERNAL_SERVER_ERROR, "unexpected image source");
}
return new GetInstallationWorkspaceDefaultImageResponse({ defaultWorkspaceImage: result.image });
}

async listBlockedRepositories(
request: PartialMessage<ListBlockedRepositoriesRequest>,
_options?: CallOptions | undefined,
Expand Down
16 changes: 8 additions & 8 deletions components/dashboard/src/teams/TeamSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { useOrgSettingsQuery } from "../data/organizations/org-settings-query";
import { useCurrentOrg, useOrganizationsInvalidator } from "../data/organizations/orgs-query";
import { useUpdateOrgMutation } from "../data/organizations/update-org-mutation";
import { useUpdateOrgSettingsMutation } from "../data/organizations/update-org-settings-mutation";
import { useDefaultWorkspaceImageQuery } from "../data/workspaces/default-workspace-image-query";
import { useOnBlurError } from "../hooks/use-onblur-error";
import { ReactComponent as Stack } from "../icons/Stack.svg";
import { organizationClient } from "../service/public-api";
Expand All @@ -28,6 +27,7 @@ import { useCurrentUser } from "../user-context";
import { OrgSettingsPage } from "./OrgSettingsPage";
import { ErrorCode } from "@gitpod/gitpod-protocol/lib/messaging/error";
import { Button } from "@podkit/buttons/Button";
import { useInstallationDefaultWorkspaceImageQuery } from "../data/installation/default-workspace-image-query";

export default function TeamSettingsPage() {
const user = useCurrentUser();
Expand Down Expand Up @@ -176,7 +176,7 @@ export default function TeamSettingsPage() {
function OrgSettingsForm(props: { org?: Organization; isOwner: boolean }) {
const { org, isOwner } = props;
const { data: settings, isLoading } = useOrgSettingsQuery();
const { data: imageInfo } = useDefaultWorkspaceImageQuery();
const { data: installationDefaultImage } = useInstallationDefaultWorkspaceImageQuery();
const updateTeamSettings = useUpdateOrgSettingsMutation();

const [showImageEditModal, setShowImageEditModal] = useState(false);
Expand Down Expand Up @@ -238,14 +238,14 @@ function OrgSettingsForm(props: { org?: Organization; isOwner: boolean }) {
<WorkspaceImageButton
disabled={!isOwner}
settings={settings}
defaultWorkspaceImage={imageInfo?.image}
installationDefaultWorkspaceImage={installationDefaultImage}
onClick={() => setShowImageEditModal(true)}
/>

{showImageEditModal && (
<OrgDefaultWorkspaceImageModal
settings={settings}
globalDefaultImage={imageInfo?.image}
installationDefaultWorkspaceImage={installationDefaultImage}
onClose={() => setShowImageEditModal(false)}
/>
)}
Expand All @@ -255,7 +255,7 @@ function OrgSettingsForm(props: { org?: Organization; isOwner: boolean }) {

function WorkspaceImageButton(props: {
settings?: OrganizationSettings;
defaultWorkspaceImage?: string;
installationDefaultWorkspaceImage?: string;
onClick: () => void;
disabled?: boolean;
}) {
Expand All @@ -282,7 +282,7 @@ function WorkspaceImageButton(props: {
};
}

const image = props.settings?.defaultWorkspaceImage || props.defaultWorkspaceImage || "";
const image = props.settings?.defaultWorkspaceImage || props.installationDefaultWorkspaceImage || "";

const descList = useMemo(() => {
const arr: ReactNode[] = [<span>Default image</span>];
Expand Down Expand Up @@ -335,7 +335,7 @@ function WorkspaceImageButton(props: {
}

interface OrgDefaultWorkspaceImageModalProps {
globalDefaultImage: string | undefined;
installationDefaultWorkspaceImage: string | undefined;
settings: OrganizationSettings | undefined;
onClose: () => void;
}
Expand Down Expand Up @@ -385,7 +385,7 @@ function OrgDefaultWorkspaceImageModal(props: OrgDefaultWorkspaceImageModalProps
<TextInputField
label="Default Image"
hint="Use any official or custom workspace image from Docker Hub or any private container registry that the Gitpod instance can access."
placeholder={props.globalDefaultImage}
placeholder={props.installationDefaultWorkspaceImage}
value={defaultWorkspaceImage}
onChange={setDefaultWorkspaceImage}
/>
Expand Down
10 changes: 10 additions & 0 deletions components/public-api/gitpod/v1/installation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import "google/protobuf/timestamp.proto";
option go_package = "github.com/gitpod-io/gitpod/components/public-api/go/v1";

service InstallationService {
// GetInstallationWorkspaceDefaultImage returns the default image for current
// Gitpod Installation.
rpc GetInstallationWorkspaceDefaultImage(GetInstallationWorkspaceDefaultImageRequest) returns (GetInstallationWorkspaceDefaultImageResponse) {}

// ListBlockedRepositories lists blocked repositories.
rpc ListBlockedRepositories(ListBlockedRepositoriesRequest) returns (ListBlockedRepositoriesResponse) {}

Expand All @@ -25,6 +29,12 @@ service InstallationService {
rpc CreateBlockedEmailDomain(CreateBlockedEmailDomainRequest) returns (CreateBlockedEmailDomainResponse) {}
}

message GetInstallationWorkspaceDefaultImageRequest {}

message GetInstallationWorkspaceDefaultImageResponse {
string default_workspace_image = 1;
}

message ListBlockedRepositoriesRequest {
// pagination contains the pagination options for listing blocked repositories
PaginationRequest pagination = 1;
Expand Down
Loading

0 comments on commit da125ed

Please sign in to comment.