gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: separate DATADIR for libeufin-bank


From: gnunet
Subject: [libeufin] branch master updated: separate DATADIR for libeufin-bank
Date: Fri, 06 Oct 2023 02:11:30 +0200

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 80a51874 separate DATADIR for libeufin-bank
80a51874 is described below

commit 80a518748cc74cabe52d96b59022ab5792aa815a
Author: Florian Dold <florian@dold.me>
AuthorDate: Fri Oct 6 02:11:36 2023 +0200

    separate DATADIR for libeufin-bank
---
 Makefile                                        |  71 ++++--------
 bank/src/main/kotlin/tech/libeufin/bank/Main.kt |  32 +++++-
 bank/src/test/kotlin/Common.kt                  |   4 +-
 util/src/main/kotlin/TalerConfig.kt             | 144 +++++++++++++-----------
 util/src/test/kotlin/TalerConfigTest.kt         |   9 +-
 5 files changed, 137 insertions(+), 123 deletions(-)

diff --git a/Makefile b/Makefile
index fe69215e..50458c6f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,81 +1,60 @@
-include build-system/config.mk
+# This Makefile has been placed under the public domain
 
-escaped_pwd = $(shell pwd | sed 's/\//\\\//g')
+include build-system/config.mk
 
 all: assemble
-install: install-bank install-cli install-db-versioning # install-nexus 
 git-archive-all = 
./build-system/taler-build-scripts/archive-with-submodules/git_archive_all.py
 git_tag=$(shell git describe --tags)
 gradle_version=$(shell ./gradlew -q libeufinVersion)
+
 define versions_check =
   if test $(git_tag) != "v$(gradle_version)"; \
     then echo WARNING: Project version from Gradle: $(gradle_version) differs 
from current Git tag: $(git_tag); fi
 endef
 
-sql_dir=$(prefix)/share/taler/sql/libeufin-bank
-config_dir=$(prefix)/share/taler/config.d
+# Absolute DESTDIR or empty string if DESTDIR unset/empty
+abs_destdir=$(abspath $(DESTDIR))
+
+sql_dir=$(abs_destdir)$(prefix)/share/libeufin-bank/sql
+config_dir=$(abs_destdir)$(prefix)/share/libeufin-bank/config.d
 
 .PHONY: dist
 dist:
-       @$(call versions_check)
-       @mkdir -p build/distributions
-       @$(git-archive-all) --include ./configure 
build/distributions/libeufin-$(shell ./gradlew -q 
libeufinVersion)-sources.tar.gz
+       $(call versions_check)
+       mkdir -p build/distributions
+       $(git-archive-all) --include ./configure 
build/distributions/libeufin-$(shell ./gradlew -q 
libeufinVersion)-sources.tar.gz
 
 .PHONY: exec-arch
 exec-arch:
-       @$(call versions_check)
-       @./gradlew -q execArch
+       $(call versions_check)
+       ./gradlew -q execArch
 
 .PHONY: clean-spa
 clean-spa:
-       @rm -fr debian/usr/share/libeufin/demobank-ui/index.* 
debian/usr/share/libeufin/demobank-ui/*.svg
+       rm -fr debian/usr/share/libeufin/demobank-ui/index.* 
debian/usr/share/libeufin/demobank-ui/*.svg
 
 .PHONY: copy-spa
 get-spa:
-       @./contrib/copy_spa.sh
+       ./contrib/copy_spa.sh
 
 .PHONY: deb
 deb: exec-arch copy-spa
-       @dpkg-buildpackage -rfakeroot -b -uc -us
-
+       dpkg-buildpackage -rfakeroot -b -uc -us
 
-# Absolute DESTDIR or empty string if DESTDIR unset/empty
-abs_destdir=$(abspath $(DESTDIR))
 
-.PHONY: install-bank
-install-bank:
-       install -d $(abs_destdir)$(config_dir)
-       install contrib/libeufin-bank.conf $(abs_destdir)$(config_dir)/
+.PHONY: install
+install:
+       install -d $(config_dir)
+       install contrib/libeufin-bank.conf $(config_dir)/
+       install -D database-versioning/libeufin-bank*.sql -t $(sql_dir)
+       install -D database-versioning/versioning.sql -t $(sql_dir)
+       install -D database-versioning/procedures.sql -t $(sql_dir)
        ./gradlew -q -Pprefix=$(abs_destdir)$(prefix) bank:installToPrefix
 
-# To reactivate after the refactoring.
-# .PHONY: install-nexus
-# install-nexus:
-#      @./gradlew -q -Pprefix=$(prefix) nexus:installToPrefix; cd ..
-
-.PHONY: install-cli
-install-cli:
-       @./gradlew -q replaceVersionCli
-       @install -D cli/bin/libeufin-cli $(prefix)/bin
-
-.PHONY: install-db-versioning
-install-db-versioning:
-       @install -D database-versioning/libeufin-bank*.sql -t $(sql_dir)
-       @install -D database-versioning/versioning.sql -t $(sql_dir)
-       @install -D database-versioning/procedures.sql -t $(sql_dir)
-
 .PHONY: assemble
 assemble:
-       @./gradlew assemble
+       ./gradlew assemble
 
 .PHONY: check
 check:
-       @./gradlew check
-
-.PHONY: pofi-get
-pofi-get:
-       @./gradlew -q :nexus:pofi --args="download" # --args="arg1 arg2 .."
-
-.PHONY: pofi-post
-pofi-post:
-       @./gradlew -q :nexus:pofi --args="upload"
+       ./gradlew check
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
index 7d329399..b0e6d174 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
@@ -20,6 +20,7 @@
 
 package tech.libeufin.bank
 
+import ConfigSource
 import TalerConfig
 import TalerConfigError
 import com.github.ajalt.clikt.core.CliktCommand
@@ -69,6 +70,7 @@ private val logger: Logger = 
LoggerFactory.getLogger("tech.libeufin.bank.Main")
 const val GENERIC_UNDEFINED = -1 // Filler for ECs that don't exist yet.
 val TOKEN_DEFAULT_DURATION: java.time.Duration = Duration.ofDays(1L)
 
+val BANK_CONFIG_SOURCE = ConfigSource("libeufin-bank", "libeufin-bank")
 
 /**
  * Application context with the parsed configuration.
@@ -410,7 +412,7 @@ fun Application.corebankWebApp(db: Database, ctx: 
BankApplicationContext) {
 class LibeufinBankCommand : CliktCommand() {
     init {
         versionOption(getVersion())
-        subcommands(ServeBank(), BankDbInit(), ChangePw())
+        subcommands(ServeBank(), BankDbInit(), ChangePw(), BankConfig())
     }
 
     override fun run() = Unit
@@ -507,7 +509,8 @@ class BankDbInit : CliktCommand("Initialize the 
libeufin-bank database", name =
     }
 
     override fun run() {
-        val config = TalerConfig.load(this.configFile)
+        val config = TalerConfig(BANK_CONFIG_SOURCE)
+        config.load(this.configFile)
         val dbConnStr = config.requireValueString("libeufin-bankdb-postgres", 
"config")
         val sqlDir = config.requireValuePath("libeufin-bankdb-postgres", 
"sql_dir")
         if (requestReset) {
@@ -529,7 +532,8 @@ class ServeBank : CliktCommand("Run libeufin-bank HTTP 
server", name = "serve")
     }
 
     override fun run() {
-        val config = TalerConfig.load(this.configFile)
+        val config = TalerConfig(BANK_CONFIG_SOURCE)
+        config.load(this.configFile)
         val ctx = readBankApplicationContextFromConfig(config)
         val dbConnStr = config.requireValueString("libeufin-bankdb-postgres", 
"config")
         logger.info("using database '$dbConnStr'")
@@ -568,7 +572,8 @@ class ChangePw : CliktCommand("Change account password", 
name = "passwd") {
     }
 
     override fun run() {
-        val config = TalerConfig.load(this.configFile)
+        val config = TalerConfig(BANK_CONFIG_SOURCE)
+        config.load(this.configFile)
         val ctx = readBankApplicationContextFromConfig(config)
         val dbConnStr = config.requireValueString("libeufin-bankdb-postgres", 
"config")
         config.requireValueNumber("libeufin-bank", "port")
@@ -585,6 +590,25 @@ class ChangePw : CliktCommand("Change account password", 
name = "passwd") {
     }
 }
 
+class BankConfig : CliktCommand("Dump the configuration", name = 
"debug-config-dump") {
+    private val configFile by option(
+        "--config", "-c",
+        help = "set the configuration file"
+    )
+    init {
+        context {
+            helpFormatter = CliktHelpFormatter(showDefaultValues = true)
+        }
+    }
+
+    override fun run() {
+        val config = TalerConfig(BANK_CONFIG_SOURCE)
+        println("# install path: ${config.getInstallPath()}")
+        config.load(this.configFile)
+        println(config.stringify())
+    }
+}
+
 fun main(args: Array<String>) {
     LibeufinBankCommand().main(args)
 }
diff --git a/bank/src/test/kotlin/Common.kt b/bank/src/test/kotlin/Common.kt
index 8d9721ab..ffacaa7a 100644
--- a/bank/src/test/kotlin/Common.kt
+++ b/bank/src/test/kotlin/Common.kt
@@ -25,7 +25,9 @@ import java.util.zip.DeflaterOutputStream
  * Init the database and sets the currency to KUDOS.
  */
 fun initDb(): Database {
-    val config = TalerConfig.load()
+    // We assume that libeufin-bank is installed. We could also try to locate 
the source tree here.
+    val config = TalerConfig(ConfigSource("libeufin-bank", "libeufin-bank"))
+    config.load()
     val sqlPath = config.requireValuePath("libeufin-bankdb-postgres", 
"SQL_DIR")
     val dbConnStr = "postgresql:///libeufincheck"
     resetDatabaseTables(dbConnStr, sqlPath)
diff --git a/util/src/main/kotlin/TalerConfig.kt 
b/util/src/main/kotlin/TalerConfig.kt
index 2a8644a5..a3f8e22a 100644
--- a/util/src/main/kotlin/TalerConfig.kt
+++ b/util/src/main/kotlin/TalerConfig.kt
@@ -25,7 +25,7 @@ import kotlin.io.path.listDirectoryEntries
 private data class Entry(val value: String)
 
 private data class Section(
-    val entries: MutableMap<String, Entry>
+    val entries: MutableMap<String, Entry>,
 )
 
 private val reEmptyLine = Regex("^\\s*$")
@@ -36,15 +36,27 @@ private val reDirective = 
Regex("^\\s*@([a-zA-Z-_]+)@\\s*(.*?)\\s*$")
 
 class TalerConfigError(m: String) : Exception(m)
 
+data class ConfigSource(
+    val componentName: String = "taler",
+    val installPathBinary: String = "taler-config",
+)
+
 /**
  * Reader and writer for Taler-style configuration files.
  *
  * The configuration file format is similar to INI files
  * and fully described in the taler.conf man page.
+ *
+ * @param configSource information about where to load configuration defaults 
from
  */
-class TalerConfig {
+class TalerConfig(
+    private val configSource: ConfigSource
+) {
     private val sectionMap: MutableMap<String, Section> = mutableMapOf()
 
+    private val componentName = configSource.componentName
+    private val installPathBinary = configSource.installPathBinary
+
     private fun internalLoadFromString(s: String) {
         val lines = s.lines()
         var lineNum = 0
@@ -212,16 +224,16 @@ class TalerConfig {
     }
 
     fun loadDefaults() {
-        val installDir = getTalerInstallPath()
-        val baseConfigDir = Paths.get(installDir, 
"share/taler/config.d").toString()
+        val installDir = getInstallPath()
+        val baseConfigDir = Paths.get(installDir, 
"share/$componentName/config.d").toString()
         setSystemDefault("PATHS", "PREFIX", "${installDir}/")
         setSystemDefault("PATHS", "BINDIR", "${installDir}/bin/")
-        setSystemDefault("PATHS", "LIBEXECDIR", "${installDir}/taler/libexec/")
-        setSystemDefault("PATHS", "DOCDIR", "${installDir}/share/doc/taler/")
+        setSystemDefault("PATHS", "LIBEXECDIR", 
"${installDir}/$componentName/libexec/")
+        setSystemDefault("PATHS", "DOCDIR", 
"${installDir}/share/doc/$componentName/")
         setSystemDefault("PATHS", "ICONDIR", "${installDir}/share/icons/")
         setSystemDefault("PATHS", "LOCALEDIR", "${installDir}/share/locale/")
-        setSystemDefault("PATHS", "LIBDIR", "${installDir}/lib/taler/")
-        setSystemDefault("PATHS", "DATADIR", "${installDir}/share/taler/")
+        setSystemDefault("PATHS", "LIBDIR", 
"${installDir}/lib/$componentName/")
+        setSystemDefault("PATHS", "DATADIR", 
"${installDir}/share/$componentName/")
         loadDefaultsFromDir(baseConfigDir)
     }
 
@@ -271,74 +283,70 @@ class TalerConfig {
         return result.toString()
     }
 
-    companion object {
-        /**
-         * Load configuration values from the file system.
-         * If no entrypoint is specified, the default entrypoint
-         * is used.
-         */
-        fun load(entrypoint: String? = null): TalerConfig {
-            val cfg = TalerConfig()
-            cfg.loadDefaults()
-            if (entrypoint != null) {
-                cfg.loadFromFilename(entrypoint)
-            } else {
-                val defaultFilename = findDefaultConfigFilename()
-                if (defaultFilename != null) {
-                    cfg.loadFromFilename(defaultFilename)
-                }
+    /**
+     * Load configuration values from the file system.
+     * If no entrypoint is specified, the default entrypoint
+     * is used.
+     */
+    fun load(entrypoint: String? = null) {
+        loadDefaults()
+        if (entrypoint != null) {
+            loadFromFilename(entrypoint)
+        } else {
+            val defaultFilename = findDefaultConfigFilename()
+            if (defaultFilename != null) {
+                loadFromFilename(defaultFilename)
             }
-            return cfg
         }
+    }
 
 
-        /**
-         * Determine the filename of the default configuration file.
-         *
-         * If no such file can be found, return null.
-         */
-        private fun findDefaultConfigFilename(): String? {
-            val xdg = System.getenv("XDG_CONFIG_HOME")
-            val home = System.getenv("HOME")
-
-            var filename: String? = null
-            if (xdg != null) {
-                filename = Paths.get(xdg, "taler.conf").toString()
-            } else if (home != null) {
-                filename = Paths.get(home, ".config/taler.conf").toString()
-            }
-            if (filename != null && File(filename).exists()) {
-                return filename
-            }
-            val etc1 = "/etc/taler.conf"
-            if (File(etc1).exists()) {
-                return etc1
-            }
-            val etc2 = "/etc/taler/taler.conf"
-            if (File(etc2).exists()) {
-                return etc2
-            }
-            return null
+    /**
+     * Determine the filename of the default configuration file.
+     *
+     * If no such file can be found, return null.
+     */
+    private fun findDefaultConfigFilename(): String? {
+        val xdg = System.getenv("XDG_CONFIG_HOME")
+        val home = System.getenv("HOME")
+
+        var filename: String? = null
+        if (xdg != null) {
+            filename = Paths.get(xdg, "$componentName.conf").toString()
+        } else if (home != null) {
+            filename = Paths.get(home, 
".config/$componentName.conf").toString()
         }
-
-        fun getTalerInstallPath(): String {
-            // We use the location of the libeufin-bank
-            // binary to determine the install prefix.
-            // If for some weird reason it's now found, we
-            // fall back to "/usr" as install prefix.
-            return getInstallPathFromBinary("libeufin-bank")
+        if (filename != null && File(filename).exists()) {
+            return filename
+        }
+        val etc1 = "/etc/$componentName.conf"
+        if (File(etc1).exists()) {
+            return etc1
         }
+        val etc2 = "/etc/$componentName/$componentName.conf"
+        if (File(etc2).exists()) {
+            return etc2
+        }
+        return null
+    }
 
-        fun getInstallPathFromBinary(name: String): String {
-            val pathEnv = System.getenv("PATH")
-            val paths = pathEnv.split(":")
-            for (p in paths) {
-                val possiblePath = Paths.get(p, name).toString()
-                if (File(possiblePath).exists()) {
-                    return Paths.get(p, "..").toRealPath().toString()
-                }
+    fun getInstallPath(): String {
+        // We use the location of the libeufin-bank
+        // binary to determine the installation prefix.
+        // If for some weird reason it's now found, we
+        // fall back to "/usr" as install prefix.
+        return getInstallPathFromBinary(installPathBinary)
+    }
+
+    private fun getInstallPathFromBinary(name: String): String {
+        val pathEnv = System.getenv("PATH")
+        val paths = pathEnv.split(":")
+        for (p in paths) {
+            val possiblePath = Paths.get(p, name).toString()
+            if (File(possiblePath).exists()) {
+                return Paths.get(p, "..").toRealPath().toString()
             }
-            return "/usr"
         }
+        return "/usr"
     }
 }
diff --git a/util/src/test/kotlin/TalerConfigTest.kt 
b/util/src/test/kotlin/TalerConfigTest.kt
index 4587c535..f07edede 100644
--- a/util/src/test/kotlin/TalerConfigTest.kt
+++ b/util/src/test/kotlin/TalerConfigTest.kt
@@ -18,14 +18,14 @@
  */
 
 import org.junit.Test
-import java.nio.file.FileSystems
 import kotlin.test.assertEquals
 
 class TalerConfigTest {
 
     @Test
     fun parsing() {
-        val conf = TalerConfig()
+        // 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"))
         conf.loadDefaults()
         conf.loadFromString(
             """
@@ -41,12 +41,13 @@ class TalerConfigTest {
 
         assertEquals("baz", conf.lookupValueString("foo", "bar"))
 
-        println(TalerConfig.getTalerInstallPath())
+        println(conf.getInstallPath())
     }
 
     @Test
     fun substitution() {
-        val conf = TalerConfig()
+        // 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"))
         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]