summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorms <ms@taler.net>2022-05-04 11:50:41 +0200
committerms <ms@taler.net>2022-05-04 11:50:41 +0200
commita4055896afb9672b1b5505877f255b8c0380aa99 (patch)
tree790489494e74e0c15d500c98973c28c4a18314dc
parentbcc56867dbecb7f41d52e09753256e1c604b1a8f (diff)
downloadlibeufin-a4055896afb9672b1b5505877f255b8c0380aa99.tar.gz
libeufin-a4055896afb9672b1b5505877f255b8c0380aa99.tar.bz2
libeufin-a4055896afb9672b1b5505877f255b8c0380aa99.zip
Currency option.
Do not transparently create the default demobank. The Sandbox needs one to be created manually _before_ being launched.
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt2
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt27
2 files changed, 17 insertions, 12 deletions
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
index b02307f9..53df73fd 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
@@ -373,7 +373,7 @@ private fun ensureDemobank(name: String): DemobankConfigEntity {
}
}
-fun getSandboxConfig(name: String?): DemobankConfigEntity? {
+fun getDemobank(name: String?): DemobankConfigEntity? {
return transaction {
if (name == null) {
DemobankConfigEntity.all().firstOrNull()
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 2cae0f34..a06e8c51 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -131,7 +131,7 @@ class Config : CliktCommand("Insert one configuration into the database") {
}
}
- private val nameOption by argument(
+ private val nameArgument by argument(
"NAME", help = "Name of this configuration"
)
private val currencyOption by option("--currency").default("EUR")
@@ -141,6 +141,10 @@ class Config : CliktCommand("Insert one configuration into the database") {
"--allow-registrations",
help = "(default: true)" /* mentioning here as help message did not. */
).flag(default = true)
+ private val withSignupBonusOption by option(
+ "--with-signup-bonus",
+ help = "Award new customers with 100 units of currency!"
+ ).flag("--without-signup-bonus", default = false)
override fun run() {
val dbConnString = getDbConnFromEnv(SANDBOX_DB_ENV_VAR_NAME)
@@ -148,10 +152,10 @@ class Config : CliktCommand("Insert one configuration into the database") {
dbCreateTables(dbConnString)
transaction {
val checkExist = DemobankConfigEntity.find {
- DemobankConfigsTable.name eq nameOption
+ DemobankConfigsTable.name eq nameArgument
}.firstOrNull()
if (checkExist != null) {
- println("Error, demobank ${nameOption} exists already, not overriding it.")
+ println("Error, demobank ${nameArgument} exists already, not overriding it.")
exitProcess(1)
}
val demoBank = DemobankConfigEntity.new {
@@ -159,7 +163,8 @@ class Config : CliktCommand("Insert one configuration into the database") {
bankDebtLimit = bankDebtLimitOption
usersDebtLimit = usersDebtLimitOption
allowRegistrations = allowRegistrationsOption
- name = nameOption
+ name = nameArgument
+ this.withSignupBonus = withSignupBonusOption
}
BankAccountEntity.new {
iban = getIban()
@@ -284,7 +289,6 @@ class Serve : CliktCommand("Run sandbox HTTP server") {
helpFormatter = CliktHelpFormatter(showDefaultValues = true)
}
}
-
private val auth by option(
"--auth",
help = "Disable authentication."
@@ -295,11 +299,6 @@ class Serve : CliktCommand("Run sandbox HTTP server") {
help = "Bind the Sandbox to the Unix domain socket at PATH. Overrides" +
" --port, when both are given", metavar = "PATH"
)
- private val withSignupBonus by option(
- "--with-signup-bonus",
- help = "Award new customers with 100 units of currency!"
- ).flag("--without-signup-bonus", default = false)
-
override fun run() {
WITH_AUTH = auth
setLogLevel(logLevel)
@@ -309,7 +308,13 @@ class Serve : CliktCommand("Run sandbox HTTP server") {
exitProcess(1)
}
execThrowableOrTerminate { dbCreateTables(getDbConnFromEnv(SANDBOX_DB_ENV_VAR_NAME)) }
- maybeCreateDefaultDemobank(withSignupBonus)
+ // Refuse to operate without a 'default' demobank.
+ val demobank = getDemobank("default")
+ if (demobank == null) {
+ println("Sandbox cannot operate without a 'default' demobank.")
+ println("Please make one with the 'libeufin-cli config' command.")
+ exitProcess(1)
+ }
if (withUnixSocket != null) {
startServer(
withUnixSocket ?: throw Exception("Could not use the Unix domain socket path value!"),