Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TLS to PostGres Sequalize function error #404

Open
zicaden opened this issue Jun 26, 2023 · 2 comments
Open

TLS to PostGres Sequalize function error #404

zicaden opened this issue Jun 26, 2023 · 2 comments
Assignees
Labels

Comments

@zicaden
Copy link

zicaden commented Jun 26, 2023

What happened?

The fix provided through #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
@ArchanaArige
Copy link
Contributor

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

@zicaden
Copy link
Author

zicaden commented Jun 30, 2023

Created PR as requested

zicaden added a commit to zicaden/blockchain-explorer that referenced this issue Jul 7, 2023
zicaden added a commit to zicaden/blockchain-explorer that referenced this issue Sep 21, 2023
zicaden added a commit to zicaden/blockchain-explorer that referenced this issue Sep 29, 2023
Signed-off-by: zicaden <[email protected]>

fix sequelize variable scope

Signed-off-by: zicaden <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Progress
Development

No branches or pull requests

2 participants