blockchain-explorer icon indicating copy to clipboard operation
blockchain-explorer copied to clipboard

TLS to PostGres Sequalize function error

Open zicaden opened this issue 2 years ago • 2 comments

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

zicaden avatar Jun 26 '23 07:06 zicaden

Hi @zicaden , Thanks for the issue. Can you please create a PR for the same.

ArchanaArige avatar Jun 28 '23 05:06 ArchanaArige

Created PR as requested

zicaden avatar Jun 30 '23 10:06 zicaden