[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: make libeufin respect PGHOST and PGPOR
From: |
gnunet |
Subject: |
[libeufin] branch master updated: make libeufin respect PGHOST and PGPORT environment variables |
Date: |
Sun, 24 Mar 2024 13:01:34 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository libeufin.
The following commit(s) were added to refs/heads/master by this push:
new 2460b772 make libeufin respect PGHOST and PGPORT environment variables
2460b772 is described below
commit 2460b772ac4e870aa307512cce1a8aa454d2d625
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Mar 24 13:01:32 2024 +0100
make libeufin respect PGHOST and PGPORT environment variables
---
common/src/main/kotlin/DB.kt | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/common/src/main/kotlin/DB.kt b/common/src/main/kotlin/DB.kt
index e36182b7..d2cb0a01 100644
--- a/common/src/main/kotlin/DB.kt
+++ b/common/src/main/kotlin/DB.kt
@@ -62,22 +62,38 @@ fun getJdbcConnectionFromPg(pgConn: String): String {
}
var maybeUnixSocket = false
val parsed = URI(pgConn)
- val hostAsParam: String? = if (parsed.query != null) {
+ var hostAsParam: String? = if (parsed.query != null) {
getQueryParam(parsed.query, "host")
} else {
null
}
+ var pgHost = System.getenv("PGHOST")
+ if (null == pgHost)
+ pgHost = parsed.host
+ var pgPort = System.getenv("PGPORT")
+ if (null == pgPort) {
+ if (-1 == parsed.port)
+ pgPort = "5432"
+ else
+ pgPort = parsed.port.toString()
+ }
+
/**
* In some cases, it is possible to leave the hostname empty
* and specify it via a query param, therefore a "postgresql:///"-starting
* connection string does NOT always mean Unix domain socket.
*
https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
*/
- if (parsed.host == null &&
+ if (pgHost == null &&
(hostAsParam == null || hostAsParam.startsWith('/'))
) {
maybeUnixSocket = true
}
+ if (pgHost != null &&
+ (pgHost.startsWith('/'))
+ ) {
+ maybeUnixSocket = true
+ }
if (maybeUnixSocket) {
// Check whether the database user should differ from the process user.
var pgUser = getCurrentUser()
@@ -86,7 +102,9 @@ fun getJdbcConnectionFromPg(pgConn: String): String {
if (maybeUserParam != null) pgUser = maybeUserParam
}
// Check whether the Unix domain socket location was given
non-standard.
- val socketLocation = hostAsParam ?: "/var/run/postgresql/.s.PGSQL.5432"
+ if ( (null == hostAsParam) && (null != pgHost) )
+ hostAsParam = pgHost + "/.s.PGSQL." + pgPort
+ val socketLocation = hostAsParam ?: "/var/run/postgresql/.s.PGSQL." +
pgPort
if (!socketLocation.startsWith('/')) {
throw Exception("PG connection wants Unix domain socket, but
non-null host doesn't start with slash")
}
@@ -99,6 +117,7 @@ fun getJdbcConnectionFromPg(pgConn: String): String {
// into one that the JDBC driver likes.
return "jdbc:postgresql://" + pgConn.removePrefix("postgres://")
}
+ logger.info("connecting to database via JDBC string '$pgConn'")
return "jdbc:$pgConn"
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: make libeufin respect PGHOST and PGPORT environment variables,
gnunet <=