Skip to content

Commit

Permalink
Added ssl-param for db connection (#39)
Browse files Browse the repository at this point in the history
* Added ssl-param for db connection

* Adjusted config-tests
  • Loading branch information
kristoff-kiefer authored Oct 11, 2023
1 parent b515ead commit 4785f52
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
6 changes: 4 additions & 2 deletions config/config.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
},
"DB": {
"CLIENT_URL": "postgres://admin:[email protected]:5432",
"DB_NAME": "dbildungs-iam"
"DB_NAME": "dbildungs-iam",
"USE_SSL": false
},
"KEYCLOAK": {
"BASE_URL": "http://127.0.0.1:8080",
"REALM_NAME": "master",
"CLIENT_ID": "admin-cli"
"CLIENT_ID": "admin-cli",
"SECRET": "topsecret"
}
}
3 changes: 2 additions & 1 deletion config/config.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
},
"DB": {
"CLIENT_URL": "<here goes your connection string>",
"DB_NAME": "<here goes your db name>"
"DB_NAME": "<here goes your db name>",
"USE_SSL": true
},
"KEYCLOAK": {
"BASE_URL": "<URL to keycloak>",
Expand Down
3 changes: 2 additions & 1 deletion config/config.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
},
"DB": {
"CLIENT_URL": "postgres://127.0.0.1:5432",
"DB_NAME": "dbildungs-iam"
"DB_NAME": "dbildungs-iam",
"USE_SSL": true
},
"KEYCLOAK": {
"BASE_URL": "http://127.0.0.1:8080",
Expand Down
3 changes: 2 additions & 1 deletion src/console/console.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DbInitConsole } from './db-init.console.js';
@Module({
imports: [
LoggingModule,

ConfigModule.forRoot({
isGlobal: true,
validate: loadEnvConfig,
Expand All @@ -33,7 +34,7 @@ import { DbInitConsole } from './db-init.console.js';
entitiesTs: ['./src/**/*.entity.ts'],
driverOptions: {
connection: {
ssl: true,
ssl: config.getOrThrow<DbConfig>('DB').USE_SSL,
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/server/server.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { OrganisationApiModule } from '../modules/organisation/organisation-api.
type: 'postgresql',
driverOptions: {
connection: {
ssl: true,
ssl: dbConfig.USE_SSL,
},
},
});
Expand Down
3 changes: 2 additions & 1 deletion src/shared/config/config.loader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'reflect-metadata'; // some decorators use reflect-metadata in the background
import fs from 'fs';
import { EnvConfig, JsonConfig, DeployStage, loadConfigFiles, loadEnvConfig } from './index.js';
import { DeployStage, EnvConfig, JsonConfig, loadConfigFiles, loadEnvConfig } from './index.js';
import { DeepPartial } from '../../../test/utils/index.js';

describe('configloader', () => {
Expand Down Expand Up @@ -35,6 +35,7 @@ describe('configloader', () => {
DB: {
CLIENT_URL: 'postgres://localhost:5432',
DB_NAME: 'test-db',
USE_SSL: false,
},
KEYCLOAK: {
BASE_URL: 'localhost:8080',
Expand Down
6 changes: 5 additions & 1 deletion src/shared/config/db.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsNotEmpty, IsString } from 'class-validator';
import { IsBoolean, IsNotEmpty, IsString } from 'class-validator';

export class DbConfig {
@IsString()
Expand All @@ -12,4 +12,8 @@ export class DbConfig {
@IsString()
@IsNotEmpty()
public readonly SECRET!: string;

@IsBoolean()
@IsNotEmpty()
public readonly USE_SSL!: boolean;
}

0 comments on commit 4785f52

Please sign in to comment.