TLS to PostGres Sequalize function error
What happened?
The fix provided through https://github.com/hyperledger-labs/blockchain-explorer/pull/30 is incomplete. The Sequelize function requires enabling TLS.
In the file https://github.com/hyperledger-labs/blockchain-explorer/blob/main/app/persistence/postgreSQL/PgService.ts
Please change the code for the below:
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 } );
to
`const isPostgresSslEnabled = process.env.DATABASE_SSL_ENABLED || false; if (isPostgresSslEnabled) {
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{
const sequelize = new Sequelize(
postgres://${this.pgconfig.user}:${this.pgconfig.password}@${this.pgconfig.host}:${this.pgconfig.port}/${this.pgconfig.database},
{ logging: false }
);
}`
What did you expect to happen?
TLS connection should work to PostGreSQL
How can we reproduce it (as minimally and precisely as possible)?
the current as is code will not work - will get a SequelizeConnectionError
Anything else we need to know?
I have tested with the above changes to code and it worked for me
OS version
# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here
# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here
Hi @zicaden , Thanks for the issue. Can you please create a PR for the same.
Created PR as requested