gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: change config loading logic


From: gnunet
Subject: [libeufin] branch master updated: change config loading logic
Date: Mon, 27 Nov 2023 19:23:44 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 90b179e4 change config loading logic
90b179e4 is described below

commit 90b179e41749f54b41d24653c7250abb04b974e9
Author: Florian Dold <florian@dold.me>
AuthorDate: Mon Nov 27 19:23:36 2023 +0100

    change config loading logic
    
    we now have one root per project
---
 .../tech/libeufin/bank/BankIntegrationApi.kt       |  4 ++-
 bank/src/main/kotlin/tech/libeufin/bank/Config.kt  |  2 +-
 .../kotlin/tech/libeufin/bank/db/WithdrawalDAO.kt  | 10 +++----
 nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt  |  2 +-
 util/src/main/kotlin/TalerConfig.kt                | 31 +++++++++++++++++-----
 util/src/test/kotlin/TalerConfigTest.kt            |  4 +--
 6 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/bank/src/main/kotlin/tech/libeufin/bank/BankIntegrationApi.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/BankIntegrationApi.kt
index 062700ba..620c9ba9 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/BankIntegrationApi.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/BankIntegrationApi.kt
@@ -25,9 +25,9 @@ import io.ktor.server.application.*
 import io.ktor.server.request.*
 import io.ktor.server.response.*
 import io.ktor.server.routing.*
-import java.util.*
 import net.taler.common.errorcodes.TalerErrorCode
 import tech.libeufin.bank.WithdrawalDAO.*
+import java.lang.AssertionError
 
 fun Routing.bankIntegrationApi(db: Database, ctx: BankConfig) {
     get("/taler-integration/config") {
@@ -96,6 +96,8 @@ fun Routing.bankIntegrationApi(db: Database, ctx: BankConfig) 
{
                     confirm_transfer_url = confirmUrl
                 ))
             }
+            // Make IntelliJ happy.
+            else -> throw AssertionError("not reached")
         }
     }
 }
\ No newline at end of file
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Config.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/Config.kt
index 08bd4a84..ce0afb23 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/Config.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/Config.kt
@@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory
 import tech.libeufin.util.DatabaseConfig
 
 private val logger: Logger = 
LoggerFactory.getLogger("tech.libeufin.bank.Config")
-private val BANK_CONFIG_SOURCE = ConfigSource("libeufin-bank", "libeufin-bank")
+private val BANK_CONFIG_SOURCE = ConfigSource("libeufin", "libeufin-bank", 
"libeufin-bank")
 
 /**
  * Application the parsed configuration.
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/db/WithdrawalDAO.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/db/WithdrawalDAO.kt
index df277f24..3ea593dd 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/db/WithdrawalDAO.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/db/WithdrawalDAO.kt
@@ -90,11 +90,11 @@ class WithdrawalDAO(private val db: Database) {
     /** Result withdrawal operation selection */
     sealed class WithdrawalSelectionResult {
         data class Success(val status: WithdrawalStatus): 
WithdrawalSelectionResult()
-        object UnknownOperation: WithdrawalSelectionResult()
-        object AlreadySelected: WithdrawalSelectionResult()
-        object RequestPubReuse: WithdrawalSelectionResult()
-        object UnknownAccount: WithdrawalSelectionResult()
-        object AccountIsNotExchange: WithdrawalSelectionResult()
+        data object UnknownOperation: WithdrawalSelectionResult()
+        data object AlreadySelected: WithdrawalSelectionResult()
+        data object RequestPubReuse: WithdrawalSelectionResult()
+        data object UnknownAccount: WithdrawalSelectionResult()
+        data object AccountIsNotExchange: WithdrawalSelectionResult()
     }
 
     /** Set details ([exchangePayto] & [reservePub]) for withdrawal operation 
[uuid] */
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index 64f94902..63a79102 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -50,7 +50,7 @@ import tech.libeufin.util.*
 import java.security.interfaces.RSAPrivateCrtKey
 import java.security.interfaces.RSAPublicKey
 
-val NEXUS_CONFIG_SOURCE = ConfigSource("libeufin-nexus", "libeufin-nexus")
+val NEXUS_CONFIG_SOURCE = ConfigSource("libeufin", "libeufin-nexus", 
"libeufin-nexus")
 val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus")
 val myJson = Json {
     this.serializersModule = SerializersModule {
diff --git a/util/src/main/kotlin/TalerConfig.kt 
b/util/src/main/kotlin/TalerConfig.kt
index 5e29e3a1..d468eaa0 100644
--- a/util/src/main/kotlin/TalerConfig.kt
+++ b/util/src/main/kotlin/TalerConfig.kt
@@ -36,8 +36,26 @@ private val reDirective = 
Regex("^\\s*@([a-zA-Z-_]+)@\\s*(.*?)\\s*$")
 
 class TalerConfigError(m: String) : Exception(m)
 
+/**
+ * Information about how the configuration is loaded.
+ *
+ * The entry point for the configuration will be the first file from this list:
+ * - /etc/$projectName/$componentName.conf
+ * - /etc/$componentName.conf
+ */
 data class ConfigSource(
+    /**
+     * Name of the high-level project.
+     */
+    val projectName: String = "taler",
+    /**
+     * Name of the component within the package.
+     */
     val componentName: String = "taler",
+    /**
+     * Name of the binary that will be located on $PATH to
+     * find the installation path of the package.
+     */
     val installPathBinary: String = "taler-config",
 )
 
@@ -55,6 +73,7 @@ class TalerConfig(
     private val sectionMap: MutableMap<String, Section> = mutableMapOf()
 
     private val componentName = configSource.componentName
+    private val projectName = configSource.projectName
     private val installPathBinary = configSource.installPathBinary
     val sections: Set<String> get() = sectionMap.keys
 
@@ -239,15 +258,15 @@ class TalerConfig(
      */
     fun loadDefaults() {
         val installDir = getInstallPath()
-        val baseConfigDir = Paths.get(installDir, 
"share/$componentName/config.d").toString()
+        val baseConfigDir = Paths.get(installDir, 
"share/$projectName/config.d").toString()
         setSystemDefault("PATHS", "PREFIX", "${installDir}/")
         setSystemDefault("PATHS", "BINDIR", "${installDir}/bin/")
-        setSystemDefault("PATHS", "LIBEXECDIR", 
"${installDir}/$componentName/libexec/")
-        setSystemDefault("PATHS", "DOCDIR", 
"${installDir}/share/doc/$componentName/")
+        setSystemDefault("PATHS", "LIBEXECDIR", 
"${installDir}/$projectName/libexec/")
+        setSystemDefault("PATHS", "DOCDIR", 
"${installDir}/share/doc/$projectName/")
         setSystemDefault("PATHS", "ICONDIR", "${installDir}/share/icons/")
         setSystemDefault("PATHS", "LOCALEDIR", "${installDir}/share/locale/")
-        setSystemDefault("PATHS", "LIBDIR", 
"${installDir}/lib/$componentName/")
-        setSystemDefault("PATHS", "DATADIR", 
"${installDir}/share/$componentName/")
+        setSystemDefault("PATHS", "LIBDIR", "${installDir}/lib/$projectName/")
+        setSystemDefault("PATHS", "DATADIR", 
"${installDir}/share/$projectName/")
         loadDefaultsFromDir(baseConfigDir)
     }
 
@@ -390,7 +409,7 @@ class TalerConfig(
         if (File(etc1).exists()) {
             return etc1
         }
-        val etc2 = "/etc/$componentName/$componentName.conf"
+        val etc2 = "/etc/$projectName/$componentName.conf"
         if (File(etc2).exists()) {
             return etc2
         }
diff --git a/util/src/test/kotlin/TalerConfigTest.kt 
b/util/src/test/kotlin/TalerConfigTest.kt
index 4be47948..7e51076d 100644
--- a/util/src/test/kotlin/TalerConfigTest.kt
+++ b/util/src/test/kotlin/TalerConfigTest.kt
@@ -25,7 +25,7 @@ class TalerConfigTest {
     @Test
     fun parsing() {
         // We assume that libeufin-bank is installed. We could also try to 
locate the source tree here.
-        val conf = TalerConfig(ConfigSource("libeufin-bank", "libeufin-bank"))
+        val conf = TalerConfig(ConfigSource("libeufin", "libeufin-bank", 
"libeufin-bank"))
         conf.loadDefaults()
         conf.loadFromString(
             """
@@ -47,7 +47,7 @@ class TalerConfigTest {
     @Test
     fun substitution() {
         // We assume that libeufin-bank is installed. We could also try to 
locate the source tree here.
-        val conf = TalerConfig(ConfigSource("libeufin-bank", "libeufin-bank"))
+        val conf = TalerConfig(ConfigSource("libeufin", "libeufin-bank", 
"libeufin-bank"))
         conf.putValueString("PATHS", "DATADIR", "mydir")
         conf.putValueString("foo", "bar", "baz")
         conf.putValueString("foo", "bar2", "baz")

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]