Skip to content

Commit 672af94

Browse files
committed
Code changes for Issue #404 SSL enable Sequelize
Signed-off-by: zicaden <[email protected]> fix sequelize variable scope Signed-off-by: zicaden <[email protected]>
1 parent c21628b commit 672af94

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

app/persistence/postgreSQL/PgService.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,27 @@ 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+
let sequelize;
104+
105+
if (isPostgresSslEnabled) {
106+
logger.info('SSL to Postgresql enabled: set dialect SSL option');
107+
sequelize = new Sequelize(
108+
`postgres://${this.pgconfig.user}:${this.pgconfig.password}@${this.pgconfig.host}:${this.pgconfig.port}/${this.pgconfig.database}`,
109+
{ logging: false, dialectOptions: { ssl: true, }, }
110+
);
111+
}else{
112+
logger.info('SSL to Postgresql disabled: dialect options not set');
113+
sequelize = new Sequelize(
114+
`postgres://${this.pgconfig.user}:${this.pgconfig.password}@${this.pgconfig.host}:${this.pgconfig.port}/${this.pgconfig.database}`,
115+
{ logging: false }
116+
);
117+
118+
}
119+
120+
104121
this.userModel = sequelize.define('users', attributes, options);
105122
return this.userModel;
106123
}

0 commit comments

Comments
 (0)