Skip to content

Commit

Permalink
Code changes for Issue hyperledger-labs#404 SSL enable Sequelize
Browse files Browse the repository at this point in the history
  • Loading branch information
zicaden committed Jun 30, 2023
1 parent c21628b commit 335c919
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions app/persistence/postgreSQL/PgService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,26 @@ export class PgService {
* @memberof PgService
*/
getUserModel(attributes, options) {
const sequelize = new Sequelize(
`postgres://${this.pgconfig.user}:${this.pgconfig.password}@${this.pgconfig.host}:${this.pgconfig.port}/${this.pgconfig.database}`,
{ logging: false }
);

// Add SSL option for PostGresql- Issue #404
const isPostgresSslEnabled = process.env.DATABASE_SSL_ENABLED || false;

if (isPostgresSslEnabled) {
logger.info('SSL to Postgresql enabled: set dialect SSL option');
const sequelize = new Sequelize(
`postgres://${this.pgconfig.user}:${this.pgconfig.password}@${this.pgconfig.host}:${this.pgconfig.port}/${this.pgconfig.database}`,
{ logging: false, dialectOptions: { ssl: true, }, }
);
}else{
logger.info('SSL to Postgresql disabled: dialect options not set');
const sequelize = new Sequelize(
`postgres://${this.pgconfig.user}:${this.pgconfig.password}@${this.pgconfig.host}:${this.pgconfig.port}/${this.pgconfig.database}`,
{ logging: false }
);

}


this.userModel = sequelize.define('users', attributes, options);
return this.userModel;
}
Expand Down

0 comments on commit 335c919

Please sign in to comment.