Skip to content

Commit

Permalink
[server] Unimplemented user service on internal port (gitpod-io#16999)
Browse files Browse the repository at this point in the history
  • Loading branch information
easyCZ authored Mar 27, 2023
1 parent a439080 commit d6629f3
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 0 deletions.
3 changes: 3 additions & 0 deletions components/server/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ packages:
- components/supervisor-api/typescript-grpcweb:lib
- components/usage-api/typescript:lib
- components/ide-service-api/typescript:lib
- components/public-api/typescript:lib
config:
packaging: offline-mirror
yarnLock: ${coreYarnLockBase}/yarn.lock
Expand Down Expand Up @@ -57,6 +58,7 @@ packages:
- components/supervisor-api/typescript-grpcweb:lib
- components/usage-api/typescript:lib
- components/ide-service-api/typescript:lib
- components/public-api/typescript:lib
- :dbtest
config:
packaging: library
Expand All @@ -83,6 +85,7 @@ packages:
- components/supervisor-api/typescript-grpcweb:lib
- components/usage-api/typescript:lib
- components/ide-service-api/typescript:lib
- components/public-api/typescript:lib
config:
packaging: library
yarnLock: ${coreYarnLockBase}/yarn.lock
Expand Down
3 changes: 3 additions & 0 deletions components/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
],
"dependencies": {
"@authzed/authzed-node": "^0.10.0",
"@bufbuild/connect": "^0.8.1",
"@bufbuild/connect-express": "^0.8.1",
"@gitbeaker/node": "^35.7.0",
"@gitpod/content-service": "0.1.5",
"@gitpod/gitpod-db": "0.1.5",
Expand All @@ -36,6 +38,7 @@
"@gitpod/gitpod-protocol": "0.1.5",
"@gitpod/ide-service-api": "0.1.5",
"@gitpod/image-builder": "0.1.5",
"@gitpod/public-api": "0.1.5",
"@gitpod/supervisor-api-grpcweb": "0.1.5",
"@gitpod/usage-api": "0.1.5",
"@gitpod/ws-manager": "0.1.5",
Expand Down
56 changes: 56 additions & 0 deletions components/server/src/api/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* 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 { injectable } from "inversify";
import { ServiceImpl, ConnectError, Code } from "@bufbuild/connect";
import { UserService as UserServiceInterface } from "@gitpod/public-api/lib/gitpod/experimental/v1/user_connectweb";
import {
GetAuthenticatedUserRequest,
ListSSHKeysRequest,
CreateSSHKeyRequest,
GetSSHKeyRequest,
DeleteSSHKeyRequest,
GetGitTokenRequest,
BlockUserRequest,
GetAuthenticatedUserResponse,
ListSSHKeysResponse,
CreateSSHKeyResponse,
GetSSHKeyResponse,
DeleteSSHKeyResponse,
GetGitTokenResponse,
BlockUserResponse,
} from "@gitpod/public-api/lib/gitpod/experimental/v1/user_pb";

@injectable()
export class APIUserService implements ServiceImpl<typeof UserServiceInterface> {
public async getAuthenticatedUser(req: GetAuthenticatedUserRequest): Promise<GetAuthenticatedUserResponse> {
throw new ConnectError("unimplemented", Code.Unimplemented);
}

public async listSSHKeys(req: ListSSHKeysRequest): Promise<ListSSHKeysResponse> {
throw new ConnectError("unimplemented", Code.Unimplemented);
}

public async createSSHKey(req: CreateSSHKeyRequest): Promise<CreateSSHKeyResponse> {
throw new ConnectError("unimplemented", Code.Unimplemented);
}

public async getSSHKey(req: GetSSHKeyRequest): Promise<GetSSHKeyResponse> {
throw new ConnectError("unimplemented", Code.Unimplemented);
}

public async deleteSSHKey(req: DeleteSSHKeyRequest): Promise<DeleteSSHKeyResponse> {
throw new ConnectError("unimplemented", Code.Unimplemented);
}

public async getGitToken(req: GetGitTokenRequest): Promise<GetGitTokenResponse> {
throw new ConnectError("unimplemented", Code.Unimplemented);
}

public async blockUser(req: BlockUserRequest): Promise<BlockUserResponse> {
throw new ConnectError("unimplemented", Code.Unimplemented);
}
}
4 changes: 4 additions & 0 deletions components/server/src/container-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ import { IamSessionApp } from "./iam/iam-session-app";
import { spicedbClientFromEnv, SpiceDBClient } from "./authorization/spicedb";
import { Authorizer, PermissionChecker } from "./authorization/perms";
import { EnvVarService } from "./workspace/env-var-service";
import { APIUserService } from "./api/user";

export const productionContainerModule = new ContainerModule((bind, unbind, isBound, rebind) => {
bind(Config).toConstantValue(ConfigFile.fromFile());
Expand Down Expand Up @@ -313,4 +314,7 @@ export const productionContainerModule = new ContainerModule((bind, unbind, isBo
.toDynamicValue(() => spicedbClientFromEnv())
.inSingletonScope();
bind(PermissionChecker).to(Authorizer).inSingletonScope();

// grpc / Connect API
bind(APIUserService).toSelf().inSingletonScope();
});
23 changes: 23 additions & 0 deletions components/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ import { WebhookEventGarbageCollector } from "./projects/webhook-event-garbage-c
import { LivenessController } from "./liveness/liveness-controller";
import { IamSessionApp } from "./iam/iam-session-app";
import { LongRunningMigrationService } from "@gitpod/gitpod-db/lib/long-running-migration/long-running-migration";
import { expressConnectMiddleware } from "@bufbuild/connect-express";
import { UserService as UserServiceDefinition } from "@gitpod/public-api/lib/gitpod/experimental/v1/user_connectweb";
import { APIUserService } from "./api/user";
import { ConnectRouter } from "@bufbuild/connect";

@injectable()
export class Server<C extends GitpodClient, S extends GitpodServer> {
Expand Down Expand Up @@ -93,6 +97,9 @@ export class Server<C extends GitpodClient, S extends GitpodServer> {
protected iamSessionApp?: express.Application;
protected iamSessionAppServer?: http.Server;

@inject(APIUserService) protected readonly apiUserService: APIUserService;
protected apiServer?: http.Server;

protected readonly eventEmitter = new EventEmitter();
protected app?: express.Application;
protected httpServer?: http.Server;
Expand Down Expand Up @@ -307,6 +314,7 @@ export class Server<C extends GitpodClient, S extends GitpodServer> {
.catch((err) => log.error("webhook-event-gc: error during startup", err));

this.app = app;

log.info("server initialized.");
}

Expand Down Expand Up @@ -388,6 +396,20 @@ export class Server<C extends GitpodClient, S extends GitpodServer> {
});
}

{
const apiApp = express();
apiApp.use(
expressConnectMiddleware({
routes: (router: ConnectRouter) => {
router.service(UserServiceDefinition, this.apiUserService);
},
}),
);
this.apiServer = apiApp.listen(9877, () => {
log.info(`Connect API server listening on: ${<AddressInfo>this.apiServer!.address()}`);
});
}

this.debugApp.start();
}

Expand All @@ -397,6 +419,7 @@ export class Server<C extends GitpodClient, S extends GitpodServer> {
await this.stopServer(this.monitoringHttpServer);
await this.stopServer(this.installationAdminHttpServer);
await this.stopServer(this.httpServer);
await this.stopServer(this.apiServer);
this.disposables.dispose();
log.info("server stopped.");
}
Expand Down
1 change: 1 addition & 0 deletions gitpod-ws.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
{ "path": "components/ws-proxy" },
{ "path": "components/public-api" },
{ "path": "components/public-api-server" },
{ "path": "components/public-api/typescript" },
{ "path": "components/gitpod-db" },
{ "path": "test" },
{ "path": "dev/blowtorch" },
Expand Down
46 changes: 46 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1238,11 +1238,33 @@
resolved "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@bufbuild/connect-express@^0.8.1":
version "0.8.1"
resolved "https://registry.yarnpkg.com/@bufbuild/connect-express/-/connect-express-0.8.1.tgz#54eb548896fad2488bc9cd16b968713e0799c955"
integrity sha512-DZkPfMYmL1doR8XaeQdwHI0YmKyWz7sG9HaZYEOcBoag+lnlbqXGaakx5gbMnE1OSX7qkSVEqrv7kB/B1tSXOQ==
dependencies:
"@bufbuild/connect" "0.8.1"
"@bufbuild/connect-node" "^0.8.1"
"@types/express" "^4.17.17"

"@bufbuild/connect-node@^0.8.1":
version "0.8.1"
resolved "https://registry.yarnpkg.com/@bufbuild/connect-node/-/connect-node-0.8.1.tgz#db371506a9c54cac78b0b73b25dd531d86dbe45a"
integrity sha512-yIdXWekNaKDBFVWY6S6L0js6Szh2fhunmVxxCd5taOL4KekO5joIfuA9eLuunTDlp1ie0fPPm7Dc5KlxWgOn0Q==
dependencies:
"@bufbuild/connect" "0.8.1"
headers-polyfill "^3.1.2"

"@bufbuild/connect-web@^0.2.1":
version "0.2.1"
resolved "https://registry.yarnpkg.com/@bufbuild/connect-web/-/connect-web-0.2.1.tgz#a7ee2914bf1b77d640fc4ee3c3a89d626f3015fa"
integrity sha512-L580cL9VZCXcjwXMCvIvdFBqdQofVBQcL+jmSis7m8ZxPj5NQ4p7fUhQRTsZMWHkyWINdlZnr7WsHQL0BT7wPQ==

"@bufbuild/[email protected]", "@bufbuild/connect@^0.8.1":
version "0.8.1"
resolved "https://registry.yarnpkg.com/@bufbuild/connect/-/connect-0.8.1.tgz#71afa90bf56bb833a7f3e2a492e6f9f83c2bebeb"
integrity sha512-cQA0jstYcLknJecTE7KbU4ePNBqiCNviBEcUCbFLve3x+vcSmtoH6jb8z39MeBqFy42ZoWhTGGc3RNCeOx2QUA==

"@bufbuild/[email protected]", "@bufbuild/protobuf@^0.1.1":
version "0.1.1"
resolved "https://registry.yarnpkg.com/@bufbuild/protobuf/-/protobuf-0.1.1.tgz#163dee03af49e82d300dfa2bf60c8c0f04c80b4c"
Expand Down Expand Up @@ -2880,6 +2902,15 @@
"@types/qs" "*"
"@types/range-parser" "*"

"@types/express-serve-static-core@^4.17.33":
version "4.17.33"
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.33.tgz#de35d30a9d637dc1450ad18dd583d75d5733d543"
integrity sha512-TPBqmR/HRYI3eC2E5hmiivIzv+bidAfXofM+sbonAGvyDhySGw9/PQZFt2BLOrjUUR++4eJVpx6KnLQK1Fk9tA==
dependencies:
"@types/node" "*"
"@types/qs" "*"
"@types/range-parser" "*"

"@types/express-session@*", "@types/[email protected]":
version "1.17.4"
resolved "https://registry.npmjs.org/@types/express-session/-/express-session-1.17.4.tgz"
Expand All @@ -2897,6 +2928,16 @@
"@types/qs" "*"
"@types/serve-static" "*"

"@types/express@^4.17.17":
version "4.17.17"
resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.17.tgz#01d5437f6ef9cfa8668e616e13c2f2ac9a491ae4"
integrity sha512-Q4FmmuLGBG58btUnfS1c1r/NQdlp3DMfGDGig8WhfpA2YRUtEkxAjkZb0yvplJGYdF1fsQ81iMDcH24sSCNC/Q==
dependencies:
"@types/body-parser" "*"
"@types/express-serve-static-core" "^4.17.33"
"@types/qs" "*"
"@types/serve-static" "*"

"@types/fs-extra@^9.0.12":
version "9.0.13"
resolved "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.13.tgz"
Expand Down Expand Up @@ -9355,6 +9396,11 @@ he@^1.2.0:
resolved "https://registry.npmjs.org/he/-/he-1.2.0.tgz"
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==

headers-polyfill@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/headers-polyfill/-/headers-polyfill-3.1.2.tgz#9a4dcb545c5b95d9569592ef7ec0708aab763fbe"
integrity sha512-tWCK4biJ6hcLqTviLXVR9DTRfYGQMXEIUj3gwJ2rZ5wO/at3XtkI4g8mCvFdUF9l1KMBNCfmNAdnahm1cgavQA==

heapdump@^0.3.15:
version "0.3.15"
resolved "https://registry.npmjs.org/heapdump/-/heapdump-0.3.15.tgz"
Expand Down

0 comments on commit d6629f3

Please sign in to comment.