-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[public-api] Add installation service (#19150)
* Add installation service * Fix dashboard * Fix * Fix --------- Co-authored-by: Huiwen <[email protected]>
- Loading branch information
1 parent
d327e5c
commit a997229
Showing
27 changed files
with
2,845 additions
and
779 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
components/dashboard/src/service/json-rpc-installation-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/** | ||
* 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 { CallOptions, PromiseClient } from "@connectrpc/connect"; | ||
import { PartialMessage } from "@bufbuild/protobuf"; | ||
import { InstallationService } from "@gitpod/public-api/lib/gitpod/v1/installation_connect"; | ||
import { | ||
ListBlockedRepositoriesRequest, | ||
ListBlockedRepositoriesResponse, | ||
CreateBlockedRepositoryRequest, | ||
CreateBlockedRepositoryResponse, | ||
DeleteBlockedRepositoryRequest, | ||
DeleteBlockedRepositoryResponse, | ||
ListBlockedEmailDomainsRequest, | ||
ListBlockedEmailDomainsResponse, | ||
CreateBlockedEmailDomainRequest, | ||
CreateBlockedEmailDomainResponse, | ||
} 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 listBlockedRepositories( | ||
request: PartialMessage<ListBlockedRepositoriesRequest>, | ||
_options?: CallOptions | undefined, | ||
): Promise<ListBlockedRepositoriesResponse> { | ||
// dashboard params is constant, no need to implement | ||
const info = await getGitpodService().server.adminGetBlockedRepositories({ | ||
limit: 100, | ||
offset: 0, | ||
orderBy: "urlRegexp", | ||
orderDir: "asc", | ||
searchTerm: request.searchTerm, | ||
}); | ||
return new ListBlockedRepositoriesResponse({ | ||
blockedRepositories: info.rows.map((item) => converter.toBlockedRepository(item)), | ||
pagination: new PaginationResponse(), | ||
}); | ||
} | ||
|
||
async createBlockedRepository( | ||
request: PartialMessage<CreateBlockedRepositoryRequest>, | ||
_options?: CallOptions | undefined, | ||
): Promise<CreateBlockedRepositoryResponse> { | ||
if (!request.urlRegexp) { | ||
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "urlRegexp is required"); | ||
} | ||
if (request.blockUser === undefined) { | ||
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "blockUser is required"); | ||
} | ||
const info = await getGitpodService().server.adminCreateBlockedRepository(request.urlRegexp, request.blockUser); | ||
return new CreateBlockedRepositoryResponse({ | ||
blockedRepository: converter.toBlockedRepository(info), | ||
}); | ||
} | ||
|
||
async deleteBlockedRepository( | ||
request: PartialMessage<DeleteBlockedRepositoryRequest>, | ||
_options?: CallOptions | undefined, | ||
): Promise<DeleteBlockedRepositoryResponse> { | ||
if (!request.blockedRepositoryId) { | ||
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "blockedRepositoryId is required"); | ||
} | ||
await getGitpodService().server.adminDeleteBlockedRepository(request.blockedRepositoryId); | ||
return new DeleteBlockedRepositoryResponse(); | ||
} | ||
|
||
async listBlockedEmailDomains( | ||
request: PartialMessage<ListBlockedEmailDomainsRequest>, | ||
_options?: CallOptions | undefined, | ||
): Promise<ListBlockedEmailDomainsResponse> { | ||
const info = await getGitpodService().server.adminGetBlockedEmailDomains(); | ||
return new ListBlockedEmailDomainsResponse({ | ||
blockedEmailDomains: info.map((item) => converter.toBlockedEmailDomain(item)), | ||
pagination: new PaginationResponse(), | ||
}); | ||
} | ||
|
||
async createBlockedEmailDomain( | ||
request: PartialMessage<CreateBlockedEmailDomainRequest>, | ||
_options?: CallOptions | undefined, | ||
): Promise<CreateBlockedEmailDomainResponse> { | ||
if (!request.domain) { | ||
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "domain is required"); | ||
} | ||
if (request.negative === undefined) { | ||
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "negative is required"); | ||
} | ||
await getGitpodService().server.adminSaveBlockedEmailDomain({ | ||
domain: request.domain, | ||
negative: request.negative, | ||
}); | ||
// There's no way to get blockedEmailDomain, just ignore it since dashboard don't care about the response data | ||
return new CreateBlockedEmailDomainResponse({}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.