tegola icon indicating copy to clipboard operation
tegola copied to clipboard

Do not required hardcoded postgres connection uri in config file

Open apjoseph opened this issue 1 year ago • 4 comments

Tegola is using PGX to connect to Postgis enabled postgres database. By default, PGX handles standard libpq env variables like PGHOST, PGDATABASE, PGPORT, PGUSER, PGPASSWORD. However Tegola forces either hardcoding the connection url into the config file or manually setting interpolated env vars. This is clunky and unintuitive (especially if you have a password that contains a character that needs escaping) and could be solved by making the connection uri in the config file optional and allowing pgx to handle validating the connection. directly.

If multiple postgis providers are needed, postgres has a built in convention for this using the pgservicefile which is also supported by default by PGX without any additional configuration needed

an optional service parameter could be added to allow switching between multiple providers. This way Tegola does not need to reinvent the wheel and manually handle what PGX can already do.

apjoseph avatar Dec 17 '24 17:12 apjoseph

actually you don't even need the extra service parameter. if tegola just feeds the url directly to pgx you can specify the service in the uri like postgres:///?service=pg-db all that needs to be done is not pre-validate the connection uri

apjoseph avatar Dec 17 '24 17:12 apjoseph

@apjoseph I'm all for supporting more ways to load in the connection string. I just want to make sure we prove the connection is valid at start up. I think this change could be fairly easy to implement by just doing a check if a connection string is present, and if not then let pgx run through it's load routine. If that fails, return an error.

Do you want to tackle implementing this?

ARolek avatar Dec 19 '24 16:12 ARolek

happy to look into it otherwise.

iwpnd avatar Dec 19 '24 17:12 iwpnd

@iwpnd if you want to tackle this feel free to pick it up as well. I think it is a good enhancement and you're pretty familiar with that part of the codebase ;-)

ARolek avatar Dec 19 '24 19:12 ARolek