[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: db connection string only from env
From: |
gnunet |
Subject: |
[libeufin] branch master updated: db connection string only from env |
Date: |
Wed, 27 Jan 2021 13:36:24 +0100 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
The following commit(s) were added to refs/heads/master by this push:
new c8d3cde db connection string only from env
c8d3cde is described below
commit c8d3cdeeb92ed054e77c3c549f17e99fa5f288aa
Author: MS <ms@taler.net>
AuthorDate: Wed Jan 27 13:36:15 2021 +0100
db connection string only from env
---
nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 16 +++++-----------
sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 16 +++-------------
util/src/main/kotlin/Config.kt | 10 ++++++++++
util/src/main/kotlin/Errors.kt | 2 +-
4 files changed, 19 insertions(+), 25 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index 27638c9..81ed787 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -35,15 +35,11 @@ import execThrowableOrTerminate
import com.github.ajalt.clikt.core.*
import com.github.ajalt.clikt.parameters.options.versionOption
import tech.libeufin.nexus.iso20022.parseCamtMessage
-import tech.libeufin.util.XMLUtil
-import tech.libeufin.util.getVersion
-import tech.libeufin.util.setLogLevel
+import tech.libeufin.util.*
import java.io.File
val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus")
-
-val LIBEUFIN_NEXUS_DB_CONNECTION = System.getenv(
- "LIBEUFIN_NEXUS_DB_CONNECTION") ?:
"jdbc:sqlite:/tmp/libeufin-nexus.sqlite3"
+val NEXUS_DB_ENV_VAR_NAME = "LIBEUFIN_NEXUS_DB_CONNECTION"
class NexusCommand : CliktCommand() {
init {
@@ -58,13 +54,12 @@ class Serve : CliktCommand("Run nexus HTTP server") {
helpFormatter = CliktHelpFormatter(showDefaultValues = true)
}
}
- private val dbConnString by option().default(LIBEUFIN_NEXUS_DB_CONNECTION)
private val host by option().default("127.0.0.1")
private val port by option().int().default(5001)
private val logLevel by option()
override fun run() {
setLogLevel(logLevel)
- serverMain(dbConnString, host, port)
+ serverMain(getDbConnFromEnv(NEXUS_DB_ENV_VAR_NAME), host, port)
}
}
@@ -85,8 +80,8 @@ class ResetTables : CliktCommand("Drop all the tables from
the database") {
helpFormatter = CliktHelpFormatter(showDefaultValues = true)
}
}
- private val dbConnString by option().default(LIBEUFIN_NEXUS_DB_CONNECTION)
override fun run() {
+ val dbConnString = getDbConnFromEnv(NEXUS_DB_ENV_VAR_NAME)
execThrowableOrTerminate {
dbDropTables(dbConnString)
dbCreateTables(dbConnString)
@@ -95,12 +90,11 @@ class ResetTables : CliktCommand("Drop all the tables from
the database") {
}
class Superuser : CliktCommand("Add superuser or change pw") {
- private val dbConnString by option().default(LIBEUFIN_NEXUS_DB_CONNECTION)
private val username by argument()
private val password by option().prompt(requireConfirmation = true,
hideInput = true)
override fun run() {
execThrowableOrTerminate {
- dbCreateTables(dbConnString)
+ dbCreateTables(getDbConnFromEnv(NEXUS_DB_ENV_VAR_NAME))
}
transaction {
val hashedPw = hashpw(password)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index b0406aa..399a47a 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -82,15 +82,7 @@ import tech.libeufin.util.ebics_h004.EbicsTypes
import java.util.*
import kotlin.random.Random
-val LIBEUFIN_SANDBOX_DB_CONNECTION = System.getenv(
- "LIBEUFIN_SANDBOX_DB_CONNECTION") ?:
"jdbc:sqlite:/tmp/libeufin-sandbox.sqlite3"
-
-class CustomerNotFound(id: String?) : Exception("Customer ${id} not found")
-class BadInputData(inputData: String?) : Exception("Customer provided invalid
input data: ${inputData}")
-class UnacceptableFractional(badNumber: BigDecimal) : Exception(
- "Unacceptable fractional part ${badNumber}"
-)
-
+val SANDBOX_DB_ENV_VAR_NAME = "LIBEUFIN_SANDBOX_DB_CONNECTION"
private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.sandbox")
data class SandboxError(val statusCode: HttpStatusCode, val reason: String) :
Exception()
@@ -103,9 +95,8 @@ class ResetTables : CliktCommand("Drop all the tables from
the database") {
helpFormatter = CliktHelpFormatter(showDefaultValues = true)
}
}
-
- private val dbConnString by
option().default(LIBEUFIN_SANDBOX_DB_CONNECTION)
override fun run() {
+ val dbConnString = getDbConnFromEnv(SANDBOX_DB_ENV_VAR_NAME)
execThrowableOrTerminate {
dbDropTables(dbConnString)
dbCreateTables(dbConnString)
@@ -120,12 +111,11 @@ class Serve : CliktCommand("Run sandbox HTTP server") {
}
}
- private val dbConnString by
option().default(LIBEUFIN_SANDBOX_DB_CONNECTION)
private val logLevel by option()
private val port by option().int().default(5000)
override fun run() {
setLogLevel(logLevel)
- serverMain(dbConnString, port)
+ serverMain(getDbConnFromEnv(SANDBOX_DB_ENV_VAR_NAME), port)
}
}
diff --git a/util/src/main/kotlin/Config.kt b/util/src/main/kotlin/Config.kt
index 2788cdf..f376b63 100644
--- a/util/src/main/kotlin/Config.kt
+++ b/util/src/main/kotlin/Config.kt
@@ -5,6 +5,7 @@ import ch.qos.logback.classic.LoggerContext
import ch.qos.logback.classic.util.ContextInitializer
import ch.qos.logback.core.util.Loader
import org.slf4j.LoggerFactory
+import kotlin.system.exitProcess
fun getVersion(): String {
return Loader.getResource(
@@ -46,4 +47,13 @@ fun setLogLevel(logLevel: String?) {
}
}
}
+}
+
+fun getDbConnFromEnv(varName: String): String {
+ val dbConnStr = System.getenv(varName)
+ if (dbConnStr.isNullOrBlank() or dbConnStr.isNullOrEmpty()) {
+ println("DB connection string not found/valid in the env variable
$varName.")
+ exitProcess(1)
+ }
+ return dbConnStr
}
\ No newline at end of file
diff --git a/util/src/main/kotlin/Errors.kt b/util/src/main/kotlin/Errors.kt
index d63d232..e99e8be 100644
--- a/util/src/main/kotlin/Errors.kt
+++ b/util/src/main/kotlin/Errors.kt
@@ -32,7 +32,7 @@ fun execThrowableOrTerminate(func: () -> Unit) {
try {
func()
} catch (e: Exception) {
- e.printStackTrace()
+ println(e.message)
exitProcess(1)
}
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: db connection string only from env,
gnunet <=