|
| 1 | +/** |
| 2 | + * Copyright (c) 2023 Gitpod GmbH. All rights reserved. |
| 3 | + * Licensed under the GNU Affero General Public License (AGPL). |
| 4 | + * See License.AGPL.txt in the project root for license information. |
| 5 | + */ |
| 6 | + |
| 7 | +import { CallOptions, PromiseClient } from "@connectrpc/connect"; |
| 8 | +import { PartialMessage } from "@bufbuild/protobuf"; |
| 9 | +import { InstallationService } from "@gitpod/public-api/lib/gitpod/v1/installation_connect"; |
| 10 | +import { |
| 11 | + ListBlockedRepositoriesRequest, |
| 12 | + ListBlockedRepositoriesResponse, |
| 13 | + CreateBlockedRepositoryRequest, |
| 14 | + CreateBlockedRepositoryResponse, |
| 15 | + DeleteBlockedRepositoryRequest, |
| 16 | + DeleteBlockedRepositoryResponse, |
| 17 | + ListBlockedEmailDomainsRequest, |
| 18 | + ListBlockedEmailDomainsResponse, |
| 19 | + CreateBlockedEmailDomainRequest, |
| 20 | + CreateBlockedEmailDomainResponse, |
| 21 | +} from "@gitpod/public-api/lib/gitpod/v1/installation_pb"; |
| 22 | +import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; |
| 23 | +import { getGitpodService } from "./service"; |
| 24 | +import { converter } from "./public-api"; |
| 25 | +import { PaginationResponse } from "@gitpod/public-api/lib/gitpod/v1/pagination_pb"; |
| 26 | + |
| 27 | +export class JsonRpcInstallationClient implements PromiseClient<typeof InstallationService> { |
| 28 | + async listBlockedRepositories( |
| 29 | + request: PartialMessage<ListBlockedRepositoriesRequest>, |
| 30 | + _options?: CallOptions | undefined, |
| 31 | + ): Promise<ListBlockedRepositoriesResponse> { |
| 32 | + // dashboard params is constant, no need to implement |
| 33 | + const info = await getGitpodService().server.adminGetBlockedRepositories({ |
| 34 | + limit: 100, |
| 35 | + offset: 0, |
| 36 | + orderBy: "urlRegexp", |
| 37 | + orderDir: "asc", |
| 38 | + searchTerm: request.searchTerm, |
| 39 | + }); |
| 40 | + return new ListBlockedRepositoriesResponse({ |
| 41 | + blockedRepositories: info.rows.map((item) => converter.toBlockedRepository(item)), |
| 42 | + pagination: new PaginationResponse(), |
| 43 | + }); |
| 44 | + } |
| 45 | + |
| 46 | + async createBlockedRepository( |
| 47 | + request: PartialMessage<CreateBlockedRepositoryRequest>, |
| 48 | + _options?: CallOptions | undefined, |
| 49 | + ): Promise<CreateBlockedRepositoryResponse> { |
| 50 | + if (!request.urlRegexp) { |
| 51 | + throw new ApplicationError(ErrorCodes.BAD_REQUEST, "urlRegexp is required"); |
| 52 | + } |
| 53 | + if (request.blockUser === undefined) { |
| 54 | + throw new ApplicationError(ErrorCodes.BAD_REQUEST, "blockUser is required"); |
| 55 | + } |
| 56 | + const info = await getGitpodService().server.adminCreateBlockedRepository(request.urlRegexp, request.blockUser); |
| 57 | + return new CreateBlockedRepositoryResponse({ |
| 58 | + blockedRepository: converter.toBlockedRepository(info), |
| 59 | + }); |
| 60 | + } |
| 61 | + |
| 62 | + async deleteBlockedRepository( |
| 63 | + request: PartialMessage<DeleteBlockedRepositoryRequest>, |
| 64 | + _options?: CallOptions | undefined, |
| 65 | + ): Promise<DeleteBlockedRepositoryResponse> { |
| 66 | + if (!request.blockedRepositoryId) { |
| 67 | + throw new ApplicationError(ErrorCodes.BAD_REQUEST, "blockedRepositoryId is required"); |
| 68 | + } |
| 69 | + await getGitpodService().server.adminDeleteBlockedRepository(request.blockedRepositoryId); |
| 70 | + return new DeleteBlockedRepositoryResponse(); |
| 71 | + } |
| 72 | + |
| 73 | + async listBlockedEmailDomains( |
| 74 | + request: PartialMessage<ListBlockedEmailDomainsRequest>, |
| 75 | + _options?: CallOptions | undefined, |
| 76 | + ): Promise<ListBlockedEmailDomainsResponse> { |
| 77 | + const info = await getGitpodService().server.adminGetBlockedEmailDomains(); |
| 78 | + return new ListBlockedEmailDomainsResponse({ |
| 79 | + blockedEmailDomains: info.map((item) => converter.toBlockedEmailDomain(item)), |
| 80 | + pagination: new PaginationResponse(), |
| 81 | + }); |
| 82 | + } |
| 83 | + |
| 84 | + async createBlockedEmailDomain( |
| 85 | + request: PartialMessage<CreateBlockedEmailDomainRequest>, |
| 86 | + _options?: CallOptions | undefined, |
| 87 | + ): Promise<CreateBlockedEmailDomainResponse> { |
| 88 | + if (!request.domain) { |
| 89 | + throw new ApplicationError(ErrorCodes.BAD_REQUEST, "domain is required"); |
| 90 | + } |
| 91 | + if (request.negative === undefined) { |
| 92 | + throw new ApplicationError(ErrorCodes.BAD_REQUEST, "negative is required"); |
| 93 | + } |
| 94 | + await getGitpodService().server.adminSaveBlockedEmailDomain({ |
| 95 | + domain: request.domain, |
| 96 | + negative: request.negative, |
| 97 | + }); |
| 98 | + // There's no way to get blockedEmailDomain, just ignore it since dashboard don't care about the response data |
| 99 | + return new CreateBlockedEmailDomainResponse({}); |
| 100 | + } |
| 101 | +} |
0 commit comments