Page 1 of 1

Postgres connection with SSL

Posted: Sun May 03, 2020 9:46 am
by rafael_at
Hi,

I’m currently evaluating Stimulsoft Reports.JS and .WEB, as we are considering to make a switch from SSRS and Tableau.

First problem I encounter is how to connect to our Postgres database with SSL. In the connection string in the macOS Designer I try “sslmode=require” “=true”, “ssl=true” etc. but nothing seems to work as the connection gets rejected with message that SSL is off. As far as I understand the macOS designer is based on the JS engine, i.e. it should be the same as Reports.JS. Does it use node-postgres package for Postgres connections?

Also where do I find a documentation about the connection string syntax used in Reports.JS and Reports.WEB?

Thanks
Rafael

Re: Postgres connection with SSL

Posted: Tue May 05, 2020 2:35 pm
by HighAley
Hello, Rafael.

In Reports.JS there are 4 types of data adapters are available.
- node.js
- PHP
- ASP.NET
- Java

All of them are open source. You could select any of them and make necessary changes if you need.

On the side of JS report engine you should add just one line of code
https://www.stimulsoft.com/en/documenta ... _bases.htm

Code: Select all

StiOptions.WebServer.url = "http://example.com/data/handler.php";
Thank you.

Re: Postgres connection with SSL

Posted: Wed May 06, 2020 10:31 am
by rafael_at
Thanks for the info!
However, it doesn't really help, as I want to be able to use the macOS Designer.app. Only way I could solve this, was to actually hack your reports.js source code, which is embedded in the app bundle. I would suggest you add the option for SSL into the Posgres data adapter, as it would benefit reports.js in general AND the mac Designer.app. Another approach would be to allow defining the connection sring using the "postgres://..." notation, that's the hack I used, one line of code ;) I am sure, we are not the only (not yet) customers which need SSL to connect!

Re: Postgres connection with SSL

Posted: Thu May 07, 2020 8:20 am
by HighAley
Hello.

Could you sned us the change that you did in our code?
We will add them to the next build.

Thank you.

Re: Postgres connection with SSL

Posted: Thu May 07, 2020 11:06 am
by rafael_at
The change in:
https://github.com/stimulsoft/Samples-J ... er.js#L114
is more or less:

Code: Select all

var pg = require('pg');
if (command.connectionString.startsWith("postgres://")) command.postgreConnectionString = command.connectionString
else {
	//same as before:
	command.connectionStringInfo = getConnectionStringInfo(command.connectionString);

	command.postgreConnectionString = "postgres://" + command.connectionStringInfo.userId + ":" + command.connectionStringInfo.password + "@" + command.connectionStringInfo.host;
        if (command.connectionStringInfo.port != null) command.postgreConnectionString += ":" + command.connectionStringInfo.port;
        command.postgreConnectionString += "/" + command.connectionStringInfo.database;
}
var client = new pg.Client(command.postgreConnectionString);

connect();
This allows to use a connections string with parameters like: "postgres://user:pw@host:port/database?ssl=1". Alternatively you could add the property "SSL" to getConnectionStringInfo/command.connectionStringInfo.ssl and construct the connection string with the "?ssl=1" parameter.

cheers

Re: Postgres connection with SSL

Posted: Mon May 11, 2020 6:47 am
by Lech Kulikowski
Hello,

Thank you for the information. We have added these changes.