Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-db/src/container-module.ts
2497 views
1
/**
2
* Copyright (c) 2020 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 { ContainerModule } from "inversify";
8
9
import { WorkspaceDB } from "./workspace-db";
10
import { TypeORMWorkspaceDBImpl } from "./typeorm/workspace-db-impl";
11
import { TypeORMUserDBImpl } from "./typeorm/user-db-impl";
12
import { UserDB } from "./user-db";
13
import { Config } from "./config";
14
import { TypeORM } from "./typeorm/typeorm";
15
import { encryptionModule } from "@gitpod/gitpod-protocol/lib/encryption/container-module";
16
import { KeyProviderImpl, KeyProviderConfig } from "@gitpod/gitpod-protocol/lib/encryption/key-provider";
17
import { DBWithTracing, bindDbWithTracing, TracedWorkspaceDB, TracedUserDB, TracedOneTimeSecretDB } from "./traced-db";
18
import { OneTimeSecretDB } from "./one-time-secret-db";
19
import { TypeORMAppInstallationDBImpl } from "./typeorm/app-installation-db-impl";
20
import { AppInstallationDB } from "./app-installation-db";
21
import { TypeORMOneTimeSecretDBImpl } from "./typeorm/one-time-secret-db-impl";
22
import { GitpodTableDescriptionProvider, TableDescriptionProvider } from "./tables";
23
import { PeriodicDbDeleter } from "./periodic-deleter";
24
import { CodeSyncResourceDB } from "./typeorm/code-sync-resource-db";
25
26
import { WorkspaceClusterDBImpl } from "./typeorm/workspace-cluster-db-impl";
27
import { WorkspaceClusterDB } from "./workspace-cluster-db";
28
import { AuthCodeRepositoryDB } from "./typeorm/auth-code-repository-db";
29
import { AuthProviderEntryDB } from "./auth-provider-entry-db";
30
import { AuthProviderEntryDBImpl } from "./typeorm/auth-provider-entry-db-impl";
31
import { EmailDomainFilterDB } from "./email-domain-filter-db";
32
import { EmailDomainFilterDBImpl } from "./typeorm/email-domain-filter-db-impl";
33
import { TeamDB } from "./team-db";
34
import { TeamDBImpl } from "./typeorm/team-db-impl";
35
import { ProjectDB } from "./project-db";
36
import { ProjectDBImpl } from "./typeorm/project-db-impl";
37
import { PersonalAccessTokenDB } from "./personal-access-token-db";
38
import { TypeORMBlockedRepositoryDBImpl } from "./typeorm/blocked-repository-db-impl";
39
import { BlockedRepositoryDB } from "./blocked-repository-db";
40
import { WebhookEventDB } from "./webhook-event-db";
41
import { WebhookEventDBImpl } from "./typeorm/webhook-event-db-impl";
42
import { PersonalAccessTokenDBImpl } from "./typeorm/personal-access-token-db-impl";
43
import { LinkedInProfileDBImpl } from "./typeorm/linked-in-profile-db-impl";
44
import { LinkedInProfileDB } from "./linked-in-profile-db";
45
import { DataCache, DataCacheNoop } from "./data-cache";
46
import { TracingManager } from "@gitpod/gitpod-protocol/lib/util/tracing";
47
import { EncryptionService, GlobalEncryptionService } from "@gitpod/gitpod-protocol/lib/encryption/encryption-service";
48
import { AuditLogDB } from "./audit-log-db";
49
import { AuditLogDBImpl } from "./typeorm/audit-log-db-impl";
50
51
// THE DB container module that contains all DB implementations
52
export const dbContainerModule = (cacheClass = DataCacheNoop) =>
53
new ContainerModule((bind, unbind, isBound, rebind, unbindAsync, onActivation, onDeactivation) => {
54
bind(Config).toSelf().inSingletonScope();
55
bind(TypeORM)
56
.toSelf()
57
.inSingletonScope()
58
.onActivation((ctx, orm) => {
59
// HACK we need to initialize the global encryption service.
60
GlobalEncryptionService.encryptionService = ctx.container.get(EncryptionService);
61
return orm;
62
});
63
bind(DBWithTracing).toSelf().inSingletonScope();
64
bind(TracingManager).toSelf().inSingletonScope();
65
bind(DataCache).to(cacheClass).inSingletonScope();
66
67
bind(TypeORMBlockedRepositoryDBImpl).toSelf().inSingletonScope();
68
bind(BlockedRepositoryDB).toService(TypeORMBlockedRepositoryDBImpl);
69
70
bind(TypeORMUserDBImpl).toSelf().inSingletonScope();
71
bind(UserDB).toService(TypeORMUserDBImpl);
72
bindDbWithTracing(TracedUserDB, bind, UserDB).inSingletonScope();
73
74
bind(AuthProviderEntryDB).to(AuthProviderEntryDBImpl).inSingletonScope();
75
76
bind(TypeORMWorkspaceDBImpl).toSelf().inSingletonScope();
77
bind(WorkspaceDB).toService(TypeORMWorkspaceDBImpl);
78
bindDbWithTracing(TracedWorkspaceDB, bind, WorkspaceDB).inSingletonScope();
79
80
bind(TypeORMAppInstallationDBImpl).toSelf().inSingletonScope();
81
bind(AppInstallationDB).toService(TypeORMAppInstallationDBImpl);
82
83
bind(TypeORMOneTimeSecretDBImpl).toSelf().inSingletonScope();
84
bind(OneTimeSecretDB).toService(TypeORMOneTimeSecretDBImpl);
85
bindDbWithTracing(TracedOneTimeSecretDB, bind, OneTimeSecretDB).inSingletonScope();
86
87
encryptionModule(bind, unbind, isBound, rebind, unbindAsync, onActivation, onDeactivation);
88
bind(KeyProviderConfig)
89
.toDynamicValue((ctx) => {
90
const config = ctx.container.get<Config>(Config);
91
return {
92
keys: KeyProviderImpl.loadKeyConfigFromJsonString(config.dbEncryptionKeys),
93
};
94
})
95
.inSingletonScope();
96
97
bind(GitpodTableDescriptionProvider).toSelf().inSingletonScope();
98
bind(TableDescriptionProvider).toService(GitpodTableDescriptionProvider);
99
bind(PeriodicDbDeleter).toSelf().inSingletonScope();
100
101
bind(CodeSyncResourceDB).toSelf().inSingletonScope();
102
103
bind(WorkspaceClusterDB).to(WorkspaceClusterDBImpl).inSingletonScope();
104
105
bind(AuthCodeRepositoryDB).toSelf().inSingletonScope();
106
107
bind(TeamDBImpl).toSelf().inSingletonScope();
108
bind(TeamDB).toService(TeamDBImpl);
109
bind(ProjectDBImpl).toSelf().inSingletonScope();
110
bind(ProjectDB).toService(ProjectDBImpl);
111
bind(WebhookEventDBImpl).toSelf().inSingletonScope();
112
bind(WebhookEventDB).toService(WebhookEventDBImpl);
113
114
bind(PersonalAccessTokenDBImpl).toSelf().inSingletonScope();
115
bind(PersonalAccessTokenDB).toService(PersonalAccessTokenDBImpl);
116
117
bind(AuditLogDBImpl).toSelf().inSingletonScope();
118
bind(AuditLogDB).toService(AuditLogDBImpl);
119
120
// com concerns
121
bind(EmailDomainFilterDB).to(EmailDomainFilterDBImpl).inSingletonScope();
122
bind(LinkedInProfileDBImpl).toSelf().inSingletonScope();
123
bind(LinkedInProfileDB).toService(LinkedInProfileDBImpl);
124
});
125
126