-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathconfig.ts
66 lines (58 loc) · 1.86 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Copyright (c) 2020 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 { log } from "@gitpod/gitpod-protocol/lib/util/logging";
import { getEnvVarParsed, getEnvVar } from "@gitpod/gitpod-protocol/lib/env";
import { ConnectionConfig } from "mysql";
@injectable()
export class Config {
get dbConfig(): DatabaseConfig {
// defaults to be used only in tests
const dbSetup: DatabaseConfig = {
host: process.env.DB_HOST || "localhost",
port: getEnvVarParsed("DB_PORT", Number.parseInt, "3306"),
username: process.env.DB_USERNAME || "gitpod",
password: process.env.DB_PASSWORD || "test",
database: process.env.DB_NAME || "gitpod",
};
if (process.env.DB_CA_CERT) {
dbSetup.ssl = {
ca: process.env.DB_CA_CERT,
};
}
log.info(`Using DB: ${dbSetup.host}:${dbSetup.port}/${dbSetup.database}`);
return dbSetup;
}
get mysqlConfig(): ConnectionConfig {
const dbConfig = this.dbConfig;
const mysqlConfig: ConnectionConfig = {
host: dbConfig.host,
port: dbConfig.port,
user: dbConfig.username,
password: dbConfig.password,
database: dbConfig.database,
};
if (dbConfig.ssl?.ca) {
mysqlConfig.ssl = {
ca: dbConfig.ssl.ca,
};
}
return mysqlConfig;
}
get dbEncryptionKeys(): string {
return getEnvVar("DB_ENCRYPTION_KEYS");
}
}
export interface DatabaseConfig {
host?: string;
port?: number;
database?: string;
username?: string;
password?: string;
ssl?: {
ca?: string;
};
}