summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine A <>2024-02-15 15:24:15 +0100
committerAntoine A <>2024-02-15 15:24:15 +0100
commit6a5cb8787cd341566af49c6514ccc90dce186691 (patch)
treed7e2c5de61a571d2a2edaf2b5d8d3531bfc2f5b6
parent5a5da42eb8bed68e1aa1ca00a9484bb6717edcfd (diff)
downloadlibeufin-6a5cb8787cd341566af49c6514ccc90dce186691.tar.gz
libeufin-6a5cb8787cd341566af49c6514ccc90dce186691.tar.bz2
libeufin-6a5cb8787cd341566af49c6514ccc90dce186691.zip
Reduce db logging and serve on localhost by default
-rw-r--r--bank/src/main/kotlin/tech/libeufin/bank/Config.kt4
-rw-r--r--bank/src/main/kotlin/tech/libeufin/bank/Main.kt8
-rw-r--r--common/src/main/kotlin/DB.kt9
-rw-r--r--contrib/bank.conf3
4 files changed, 10 insertions, 14 deletions
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Config.kt b/bank/src/main/kotlin/tech/libeufin/bank/Config.kt
index 42df06b4..5c67f292 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/Config.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/Config.kt
@@ -65,7 +65,7 @@ data class ConversionRate (
sealed interface ServerConfig {
data class Unix(val path: String, val mode: Int): ServerConfig
- data class Tcp(val port: Int): ServerConfig
+ data class Tcp(val addr: String, val port: Int): ServerConfig
}
fun talerConfig(configPath: Path?): TalerConfig = BANK_CONFIG_SOURCE.fromFile(configPath)
@@ -79,7 +79,7 @@ fun TalerConfig.loadDbConfig(): DatabaseConfig {
fun TalerConfig.loadServerConfig(): ServerConfig {
return when (val method = requireString("libeufin-bank", "serve")) {
- "tcp" -> ServerConfig.Tcp(requireNumber("libeufin-bank", "port"))
+ "tcp" -> ServerConfig.Tcp(requireString("libeufin-bank", "address"), requireNumber("libeufin-bank", "port"))
"unix" -> ServerConfig.Unix(requireString("libeufin-bank", "unixpath"), requireNumber("libeufin-bank", "unixpath_mode"))
else -> throw TalerConfigError.invalid("server method", "libeufin-bank", "serve", "expected 'tcp' or 'unix' got '$method'")
}
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
index e6245238..60b61f8b 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
@@ -308,6 +308,7 @@ class ServeBank : CliktCommand("Run libeufin-bank HTTP server", name = "serve")
when (serverCfg) {
is ServerConfig.Tcp -> {
port = serverCfg.port
+ host = serverCfg.addr
}
is ServerConfig.Unix ->
throw Exception("Can only serve libeufin-bank via TCP")
@@ -317,13 +318,6 @@ class ServeBank : CliktCommand("Run libeufin-bank HTTP server", name = "serve")
}
val local = embeddedServer(Netty, env)
engine = local
- when (serverCfg) {
- is ServerConfig.Tcp -> {
- logger.info("Server listening on http://localhost:${serverCfg.port}")
- }
- is ServerConfig.Unix ->
- throw Exception("Can only serve libeufin-bank via TCP")
- }
local.start(wait = true)
}
}
diff --git a/common/src/main/kotlin/DB.kt b/common/src/main/kotlin/DB.kt
index a7561d85..2fa25ebc 100644
--- a/common/src/main/kotlin/DB.kt
+++ b/common/src/main/kotlin/DB.kt
@@ -58,7 +58,6 @@ fun getJdbcConnectionFromPg(pgConn: String): String {
return pgConn
}
if (!pgConn.startsWith("postgresql://") && !pgConn.startsWith("postgres://")) {
- logger.info("Not a Postgres connection string: $pgConn")
throw Exception("Not a Postgres connection string: $pgConn")
}
var maybeUnixSocket = false
@@ -110,7 +109,7 @@ data class DatabaseConfig(
fun pgDataSource(dbConfig: String): PGSimpleDataSource {
val jdbcConnStr = getJdbcConnectionFromPg(dbConfig)
- logger.info("connecting to database via JDBC string '$jdbcConnStr'")
+ logger.debug("connecting to database via JDBC string '$jdbcConnStr'")
val pgSource = PGSimpleDataSource()
pgSource.setUrl(jdbcConnStr)
pgSource.prepareThreshold = 1
@@ -244,13 +243,13 @@ fun initializeDatabaseTables(conn: PgConnection, cfg: DatabaseConfig, sqlFilePre
checkStmt.setString(1, patchName)
val patchCount = checkStmt.oneOrNull { it.getInt(1) } ?: throw Exception("unable to query patches")
if (patchCount >= 1) {
- logger.info("patch $patchName already applied")
+ logger.debug("patch $patchName already applied")
continue
}
val path = Path("${cfg.sqlDir}/$sqlFilePrefix-$numStr.sql")
if (!path.exists()) {
- logger.info("path $path doesn't exist anymore, stopping")
+ logger.debug("path $path doesn't exist anymore, stopping")
break
}
logger.info("applying patch $path")
@@ -259,7 +258,7 @@ fun initializeDatabaseTables(conn: PgConnection, cfg: DatabaseConfig, sqlFilePre
}
val sqlProcedures = Path("${cfg.sqlDir}/$sqlFilePrefix-procedures.sql")
if (!sqlProcedures.exists()) {
- logger.info("no procedures.sql for the SQL collection: $sqlFilePrefix")
+ logger.warn("no procedures.sql for the SQL collection: $sqlFilePrefix")
return@transaction
}
logger.info("run procedure.sql")
diff --git a/contrib/bank.conf b/contrib/bank.conf
index 5457a7f2..ef492139 100644
--- a/contrib/bank.conf
+++ b/contrib/bank.conf
@@ -48,6 +48,9 @@ SERVE = tcp
# Port on which the HTTP server listens, e.g. 9967. Only used if SERVE is tcp.
PORT = 8080
+# Address on which the HTTP server listens, e.g. localhost. Only used if SERVE is tcp.
+ADDRESS = localhost
+
# Which unix domain path should we bind to? Only used if SERVE is unix.
# UNIXPATH = libeufin-bank.sock