libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit ab1fa55a44a9ad802ef84e658e757b6fc4c776d0
parent 5b1d376ec4e8a50859acf07788e81349e9fdc4ba
Author: Antoine A <>
Date:   Sat, 13 Jul 2024 00:56:14 +0200

nexus: fix dbinit breaking change

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/Config.kt | 22++++++++++++++--------
Mnexus/src/main/kotlin/tech/libeufin/nexus/DbInit.kt | 2+-
2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Config.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Config.kt @@ -48,14 +48,7 @@ class ApiConfig(section: TalerConfigSection) { class NexusConfig internal constructor (private val cfg: TalerConfig) { private val sect = cfg.section("nexus-ebics") - val dbCfg: DatabaseConfig by lazy { - val sect = cfg.section("libeufin-nexusdb-postgres") - val configOption = sect.string("config") - DatabaseConfig( - dbConnStr = configOption.orNull() ?: cfg.section("nexus-postgres").string("config").orNull() ?: configOption.require(), - sqlDir = sect.path("sql_dir").require() - ) - } + val dbCfg: DatabaseConfig by lazy { cfg.dbConfig() } val serverCfg: ServerConfig by lazy { cfg.loadServerConfig("nexus-httpd") } @@ -134,12 +127,25 @@ enum class AccountType { exchange } +private fun TalerConfig.dbConfig(): DatabaseConfig { + val sect = section("libeufin-nexusdb-postgres") + val configOption = sect.string("config") + return DatabaseConfig( + dbConnStr = configOption.orNull() ?: section("nexus-postgres").string("config").orNull() ?: configOption.require(), + sqlDir = sect.path("sql_dir").require() + ) +} + /** Load nexus config at [configPath] */ fun nexusConfig(configPath: Path?): NexusConfig { val config = NEXUS_CONFIG_SOURCE.fromFile(configPath) return NexusConfig(config) } +/** Load nexus db config at [configPath] */ +fun dbConfig(configPath: Path?): DatabaseConfig = + NEXUS_CONFIG_SOURCE.fromFile(configPath).dbConfig() + /** Run [lambda] with access to a database conn pool */ suspend fun NexusConfig.withDb(lambda: suspend (Database, NexusConfig) -> Unit) { Database(dbCfg, currency).use { lambda(it, this) } diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DbInit.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DbInit.kt @@ -40,7 +40,7 @@ class DbInit : CliktCommand("Initialize the libeufin-nexus database", name = "db ).flag() override fun run() = cliCmd(logger, common.log) { - val cfg = nexusConfig(common.config).dbCfg + val cfg = dbConfig(common.config) pgDataSource(cfg.dbConnStr).dbInit(cfg, "libeufin-nexus", reset) } } \ No newline at end of file