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
Signed-off-by: zicaden <[email protected]>

fix sequelize variable scope

Signed-off-by: zicaden <[email protected]>
  • Loading branch information
zicaden committed Sep 29, 2023
1 parent c21628b commit 672af94
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions app/persistence/postgreSQL/PgService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,27 @@ 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;
let sequelize;

if (isPostgresSslEnabled) {
logger.info('SSL to Postgresql enabled: set dialect SSL option');
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');
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 672af94

Please sign in to comment.