mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
/**
|
|
* 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 = {
|
|
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",
|
|
};
|
|
|
|
log.info(`Using DB: ${dbSetup.host}:${dbSetup.port}/${dbSetup.database}`);
|
|
|
|
return dbSetup;
|
|
}
|
|
|
|
get mysqlConfig(): ConnectionConfig {
|
|
const dbConfig = this.dbConfig;
|
|
return {
|
|
host: dbConfig.host,
|
|
port: dbConfig.port,
|
|
user: dbConfig.username,
|
|
password: dbConfig.password,
|
|
database: dbConfig.database,
|
|
};
|
|
}
|
|
|
|
get dbEncryptionKeys(): string {
|
|
return getEnvVar("DB_ENCRYPTION_KEYS");
|
|
}
|
|
}
|
|
|
|
export interface DatabaseConfig {
|
|
host?: string;
|
|
port?: number;
|
|
database?: string;
|
|
username?: string;
|
|
password?: string;
|
|
}
|