commit bfeebd4f3f3cb3ad388f150c7da11d902f0c8b22
parent 426952bfd788c0cbe89287f8ae721cdf626cb2da
Author: Antoine A <>
Date: Wed, 29 Nov 2023 12:10:50 +0000
Provide minimal config in contrib
Diffstat:
2 files changed, 81 insertions(+), 78 deletions(-)
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
@@ -142,72 +142,66 @@ fun Application.corebankWebApp(db: Database, ctx: BankConfig) {
})
}
install(StatusPages) {
- /**
- * This branch triggers when the Ktor layers detect one
- * invalid request. It _might_ be thrown by the bank's
- * actual logic, but that should be avoided because this
- * (Ktor native) type doesn't easily map to the Taler error
- * format.
- */
- exception<BadRequestException> { call, cause ->
- /**
- * NOTE: extracting the root cause helps with JSON error messages,
- * because they mention the particular way they are invalid, but OTOH
- * it loses (by getting null) other error messages, like for example
- * the one from MissingRequestParameterException. Therefore, in order
- * to get the most detailed message, we must consider BOTH sides:
- * the 'cause' AND its root cause!
- */
- logger.error(cause.message)
- var rootCause: Throwable? = cause.cause
- while (rootCause?.cause != null)
- rootCause = rootCause.cause
- /* Here getting _some_ error message, by giving precedence
- * to the root cause, as otherwise JSON details would be lost. */
- logger.error(rootCause?.message)
- // Telling apart invalid JSON vs missing parameter vs invalid parameter.
- val talerErrorCode = when (cause) {
- is MissingRequestParameterException ->
- TalerErrorCode.GENERIC_PARAMETER_MISSING
+ exception<Exception> { call, cause ->
+ when (cause) {
+ is LibeufinBankException -> call.err(cause)
+ is SQLException -> {
+ when (cause.sqlState) {
+ PSQLState.SERIALIZATION_FAILURE.state -> call.err(
+ HttpStatusCode.InternalServerError,
+ "Transaction serialization failure",
+ TalerErrorCode.BANK_SOFT_EXCEPTION
+ )
+ else -> call.err(
+ HttpStatusCode.InternalServerError,
+ "Unexpected sql error with state ${cause.sqlState}",
+ TalerErrorCode.BANK_UNMANAGED_EXCEPTION
+ )
+ }
+ }
+ is BadRequestException -> {
+ /**
+ * NOTE: extracting the root cause helps with JSON error messages,
+ * because they mention the particular way they are invalid, but OTOH
+ * it loses (by getting null) other error messages, like for example
+ * the one from MissingRequestParameterException. Therefore, in order
+ * to get the most detailed message, we must consider BOTH sides:
+ * the 'cause' AND its root cause!
+ */
+ logger.error(cause.message)
+ var rootCause: Throwable? = cause.cause
+ while (rootCause?.cause != null)
+ rootCause = rootCause.cause
+ /* Here getting _some_ error message, by giving precedence
+ * to the root cause, as otherwise JSON details would be lost. */
+ logger.error(rootCause?.message)
+ // Telling apart invalid JSON vs missing parameter vs invalid parameter.
+ val talerErrorCode = when (cause) {
+ is MissingRequestParameterException ->
+ TalerErrorCode.GENERIC_PARAMETER_MISSING
- is ParameterConversionException ->
- TalerErrorCode.GENERIC_PARAMETER_MALFORMED
+ is ParameterConversionException ->
+ TalerErrorCode.GENERIC_PARAMETER_MALFORMED
- else -> TalerErrorCode.GENERIC_JSON_INVALID
- }
- call.err(
- badRequest(
- cause.message,
- talerErrorCode,
- rootCause?.message
- )
- )
- }
- exception<LibeufinBankException> { call, cause ->
- call.err(cause)
- }
- exception<SQLException> { call, cause ->
- when (cause.sqlState) {
- PSQLState.SERIALIZATION_FAILURE.state -> call.err(
- HttpStatusCode.InternalServerError,
- "Transaction serialization failure",
- TalerErrorCode.BANK_SOFT_EXCEPTION
- )
- else -> call.err(
- HttpStatusCode.InternalServerError,
- "Unexpected sql error with state ${cause.sqlState}",
- TalerErrorCode.BANK_UNMANAGED_EXCEPTION
- )
+ else -> TalerErrorCode.GENERIC_JSON_INVALID
+ }
+ call.err(
+ badRequest(
+ cause.message,
+ talerErrorCode,
+ rootCause?.message
+ )
+ )
+ }
+ else -> {
+ call.err(
+ HttpStatusCode.InternalServerError,
+ cause.message,
+ TalerErrorCode.BANK_UNMANAGED_EXCEPTION
+ )
+ }
}
}
- // Catch-all branch to mean that the bank wasn't able to manage one error.
- exception<Exception> { call, cause ->
- call.err(
- HttpStatusCode.InternalServerError,
- cause.message,
- TalerErrorCode.BANK_UNMANAGED_EXCEPTION
- )
- }
}
routing {
coreBankApi(db, ctx)
diff --git a/contrib/bank.conf b/contrib/bank.conf
@@ -1,35 +1,44 @@
[libeufin-bank]
# Internal currency of the libeufin-bank
-CURRENCY = KUDOS
+#CURRENCY = KUDOS
# Default debt limit for newly created customer accounts
-DEFAULT_CUSTOMER_DEBT_LIMIT = KUDOS:200
+#DEFAULT_CUSTOMER_DEBT_LIMIT = KUDOS:200
# Default debt limit of the admin. Typically higher, since sign-up bonuses and cashin are deducted from the admin account.
-DEFAULT_ADMIN_DEBT_LIMIT = KUDOS:20000000
+#DEFAULT_ADMIN_DEBT_LIMIT = KUDOS:20000000
# Value of the registration bonus for new users. Default is "CURRENCY:0"
-REGISTRATION_BONUS = KUDOS:100
+#REGISTRATION_BONUS = KUDOS:100
# Allow account registration by anyone.
-ALLOW_REGISTRATION = yes
+#ALLOW_REGISTRATION = yes
# Allow an account to delete itself
-ALLOW_ACCOUNT_DELETION = yes
+#ALLOW_ACCOUNT_DELETION = yes
# Enable regional currency conversion
-ALLOW_CONVERSION = no
+#ALLOW_CONVERSION = no
# Path to TAN challenge transmission script via sms. If not specified, this TAN channel wil be unuspported.
-TAN_SMS =
+#TAN_SMS =
# Path to TAN challenge transmission script via email. If not specified, this TAN channel wil be unuspported.
-TAN_EMAIL =
+#TAN_EMAIL =
+
+# How "libeufin-bank serve" serves its API, this can either be tcp or unix
+#SERVE = tcp
+
+# Port on which the HTTP server listens, e.g. 9967. Only used if SERVE is tcp.
+#PORT = 8080
+
+# Which unix domain path should we bind to? Only used if SERVE is unix.
+#UNIXPATH = libeufin-bank.sock
+
+# What should be the file access permissions for UNIXPATH? Only used if SERVE is unix.
+#UNIXPATH_MODE = 660
-# Where "libeufin-bank serve" serves its API
-SERVE = tcp
-PORT = 8080
# Path to spa files
SPA = $DATADIR/spa/
@@ -39,14 +48,14 @@ SPA = $DATADIR/spa/
# The string {woid} is replaced with the withdrawal operation ID.
# FIXME: The name is not great. Maybe call it WITHDRAWAL_CONFIRMATION_REDIRECT
# or something similar?
-SPA_CAPTCHA_URL = https://bank.demo.taler.net/webui/#/operation/{woid}
+#SPA_CAPTCHA_URL = https://bank.demo.taler.net/webui/#/operation/{woid}
# Exchange that is suggested to wallets when withdrawing.
-SUGGESTED_WITHDRAWAL_EXCHANGE = https://exchange.demo.taler.net/
+#SUGGESTED_WITHDRAWAL_EXCHANGE = https://exchange.demo.taler.net/
[libeufin-bankdb-postgres]
# Where are the SQL files to setup our tables?
SQL_DIR = $DATADIR/sql/
# DB connection string
-CONFIG = postgresql:///libeufinbank
-\ No newline at end of file
+#CONFIG = postgresql:///libeufinbank
+\ No newline at end of file