Skip to content

Commit 335c919

Browse files
committed
Code changes for Issue #404 SSL enable Sequelize
1 parent c21628b commit 335c919

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

app/persistence/postgreSQL/PgService.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,26 @@ export class PgService {
9797
* @memberof PgService
9898
*/
9999
getUserModel(attributes, options) {
100-
const sequelize = new Sequelize(
101-
`postgres://${this.pgconfig.user}:${this.pgconfig.password}@${this.pgconfig.host}:${this.pgconfig.port}/${this.pgconfig.database}`,
102-
{ logging: false }
103-
);
100+
101+
// Add SSL option for PostGresql- Issue #404
102+
const isPostgresSslEnabled = process.env.DATABASE_SSL_ENABLED || false;
103+
104+
if (isPostgresSslEnabled) {
105+
logger.info('SSL to Postgresql enabled: set dialect SSL option');
106+
const sequelize = new Sequelize(
107+
`postgres://${this.pgconfig.user}:${this.pgconfig.password}@${this.pgconfig.host}:${this.pgconfig.port}/${this.pgconfig.database}`,
108+
{ logging: false, dialectOptions: { ssl: true, }, }
109+
);
110+
}else{
111+
logger.info('SSL to Postgresql disabled: dialect options not set');
112+
const sequelize = new Sequelize(
113+
`postgres://${this.pgconfig.user}:${this.pgconfig.password}@${this.pgconfig.host}:${this.pgconfig.port}/${this.pgconfig.database}`,
114+
{ logging: false }
115+
);
116+
117+
}
118+
119+
104120
this.userModel = sequelize.define('users', attributes, options);
105121
return this.userModel;
106122
}

0 commit comments

Comments
 (0)