commit 49ba85dc3eb4001dadeb4a4945e07735ff832ff8
parent 96b7112457ade76188b6010c93f5fa927c2871ee
Author: Antoine A <>
Date: Thu, 8 Jan 2026 17:06:13 +0100
common: more env substitution in config
Diffstat:
4 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/libeufin-bank/src/main/kotlin/tech/libeufin/bank/Config.kt b/libeufin-bank/src/main/kotlin/tech/libeufin/bank/Config.kt
@@ -1,6 +1,6 @@
/*
* This file is part of LibEuFin.
- * Copyright (C) 2023-2025 Taler Systems S.A.
+ * Copyright (C) 2023, 2024, 2025, 2026 Taler Systems S.A.
* LibEuFin is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -60,7 +60,7 @@ data class BankConfig(
val dbCfg: DatabaseConfig by lazy {
val sect = cfg.section("libeufin-bankdb-postgres")
DatabaseConfig(
- dbConnStr = sect.string("config").require(),
+ dbConnStr = sect.stringsub("config").require(),
sqlDir = sect.path("sql_dir").require()
)
}
diff --git a/libeufin-common/src/main/kotlin/TalerConfig.kt b/libeufin-common/src/main/kotlin/TalerConfig.kt
@@ -1,6 +1,6 @@
/*
* This file is part of LibEuFin.
- * Copyright (C) 2023-2025 Taler Systems S.A.
+ * Copyright (C) 2023, 2024, 2025, 2026 Taler Systems S.A.
*
* LibEuFin is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -309,24 +309,20 @@ class TalerConfig internal constructor(
*
* This substitution is typically only done for paths.
*/
- internal fun pathsub(str: String, recursionDepth: Int = 0): Path {
+ internal fun pathsub(str: String, recursionDepth: Int = 0): String {
/** Lookup for variable value from PATHS section in the configuration and environment variables */
- fun lookup(name: String, recursionDepth: Int = 0): Path? {
+ fun lookup(name: String, recursionDepth: Int = 0): String? {
val pathRes = section("PATHS").string(name).orNull()
if (pathRes != null) {
return pathsub(pathRes, recursionDepth + 1)
}
- val envVal = System.getenv(name)
- if (envVal != null) {
- return Path(envVal)
- }
- return null
+ return System.getenv(name)
}
if (recursionDepth > 128) {
throw ValueError("recursion limit in path substitution exceeded for '$str'")
} else if (!str.contains('$')) { // Fast path without variables
- return Path(str)
+ return str
}
var cursor = 0
@@ -392,7 +388,7 @@ class TalerConfig internal constructor(
?: throw ValueError("unbound variable '$name'")
result.append(resolved)
}
- return Path(result.toString())
+ return result.toString()
}
/** Access [section] */
@@ -459,6 +455,11 @@ class TalerConfigSection internal constructor(
/** Access [option] as String */
fun string(option: String) = option(option, "string") { it }
+ /** Access [option] as String with variable substitution */
+ fun stringsub(option: String) = option(option, "string") {
+ cfg.pathsub(it)
+ }
+
/** Access [option] as Regex */
fun regex(option: String) = option(option, "regex") { Regex(it) }
@@ -486,7 +487,7 @@ class TalerConfigSection internal constructor(
/** Access [option] as Path */
fun path(option: String) = option(option, "path") {
- cfg.pathsub(it)
+ Path(cfg.pathsub(it))
}
/** Access [option] as Duration */
diff --git a/libeufin-common/src/main/kotlin/api/server.kt b/libeufin-common/src/main/kotlin/api/server.kt
@@ -1,6 +1,6 @@
/*
* This file is part of LibEuFin.
- * Copyright (C) 2024-2025 Taler Systems S.A.
+ * Copyright (C) 2024, 2025, 2026 Taler Systems S.A.
* LibEuFin is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -303,7 +303,7 @@ fun serve(cfg: tech.libeufin.common.ServerConfig, logger: Logger, api: Applicati
}
is ServerConfig.Unix -> {
logger.info("Listening on ${cfg.path}")
- unixConnector(cfg.path)
+ unixConnector(cfg.path.toString())
}
}
},
diff --git a/libeufin-common/src/main/kotlin/config.kt b/libeufin-common/src/main/kotlin/config.kt
@@ -1,6 +1,6 @@
/*
* This file is part of LibEuFin.
- * Copyright (C) 2024-2025 Taler Systems S.A.
+ * Copyright (C) 2024, 2025, 2026 Taler Systems S.A.
* LibEuFin is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -21,11 +21,12 @@ package tech.libeufin.common
import org.slf4j.Logger
import org.slf4j.LoggerFactory
+import java.nio.file.Path
private val logger: Logger = LoggerFactory.getLogger("libeufin-config")
sealed interface ServerConfig {
- data class Unix(val path: String): ServerConfig
+ data class Unix(val path: Path): ServerConfig
data class Tcp(val addr: String, val port: Int): ServerConfig
}
@@ -33,7 +34,7 @@ fun TalerConfig.loadServerConfig(section: String): ServerConfig {
val sect = section(section)
return sect.mapLambda("serve", "server method", mapOf(
"tcp" to { ServerConfig.Tcp(sect.string("address").orNull() ?: sect.string("bind_to").require(), sect.number("port").require()) },
- "unix" to { ServerConfig.Unix(sect.string("unixpath").require()) }
+ "unix" to { ServerConfig.Unix(sect.path("unixpath").require()) }
)).require()
}