summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine A <>2023-12-04 16:19:33 +0000
committerAntoine A <>2023-12-04 16:19:46 +0000
commit52f77dda8785453d443d9fb96c47a91dc2892f92 (patch)
treeab0179bb8323ec160e646b1535cc4c51dbcd157e
parent078d2401cc1146c0687347608f184fbbd7bf6240 (diff)
downloadlibeufin-52f77dda8785453d443d9fb96c47a91dc2892f92.tar.gz
libeufin-52f77dda8785453d443d9fb96c47a91dc2892f92.tar.bz2
libeufin-52f77dda8785453d443d9fb96c47a91dc2892f92.zip
New create account command
-rw-r--r--bank/src/main/kotlin/tech/libeufin/bank/Main.kt64
-rw-r--r--integration/test/IntegrationTest.kt8
2 files changed, 62 insertions, 10 deletions
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
index ad566840..8d3196e7 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
@@ -24,6 +24,7 @@ import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.subcommands
import com.github.ajalt.clikt.parameters.arguments.*
import com.github.ajalt.clikt.parameters.options.*
+import com.github.ajalt.clikt.parameters.groups.*
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.http.content.*
@@ -328,14 +329,71 @@ class ChangePw : CliktCommand("Change account password", name = "passwd") {
class CreateAccount : CliktCommand(
"Create an account, returning the payto://-URI associated with it",
- name = "create-account"
+ name = "create"
) {
private val configFile by option(
"--config", "-c",
help = "set the configuration file"
)
- private val json: RegisterAccountRequest by argument().convert { Json.decodeFromString<RegisterAccountRequest>(it) }
+ private val username: String by option("--username", "-u").required()
+ private val password: String by option("--password", "-p").prompt(requireConfirmation = true, hideInput = true)
+ private val name: String by option("--name").required()
+ private val is_public: Boolean by option("--is_public", "--public").flag()
+ private val is_taler_exchange: Boolean by option("--is_taler_exchange", "--exchange").flag()
+ private val email: String? by option()
+ private val phone: String? by option()
+ private val cashout_payto_uri: IbanPayTo? by option().convert { IbanPayTo(it) }
+ private val internal_payto_uri: IbanPayTo? by option().convert { IbanPayTo(it) }
+ private val debit_threshold: TalerAmount? by option().convert { TalerAmount(it) }
+
+ override fun run() = cliCmd(logger) {
+ val cfg = talerConfig(configFile)
+ val ctx = cfg.loadBankConfig()
+ val dbCfg = cfg.loadDbConfig()
+ val db = Database(dbCfg.dbConnStr, ctx.regionalCurrency, ctx.fiatCurrency)
+ runBlocking {
+ val (result, internalPayto) = createAccount(db, ctx, RegisterAccountRequest(
+ username = username,
+ password = password,
+ name = name,
+ is_public = is_public,
+ is_taler_exchange = is_taler_exchange,
+ challenge_contact_data = ChallengeContactData(
+ email = email,
+ phone = phone,
+ ),
+ cashout_payto_uri = cashout_payto_uri,
+ internal_payto_uri = internal_payto_uri,
+ debit_threshold = debit_threshold
+ ), true);
+ when (result) {
+ AccountCreationResult.BonusBalanceInsufficient ->
+ throw Exception("Insufficient admin funds to grant bonus")
+ AccountCreationResult.LoginReuse ->
+ throw Exception("Account username reuse '$username'")
+ AccountCreationResult.PayToReuse ->
+ throw Exception("Bank internalPayToUri reuse '${internalPayto.canonical}'")
+ AccountCreationResult.Success ->
+ logger.info("Account '$username' created")
+ }
+ println(internalPayto)
+ }
+ }
+}
+// TODO remove
+class CreateAccountJson : CliktCommand(
+ "Create an account, returning the payto://-URI associated with it",
+ name = "create-account",
+ hidden = true
+) {
+ private val configFile by option(
+ "--config", "-c",
+ help = "set the configuration file"
+ )
+
+ private val json: RegisterAccountRequest by argument().convert { Json.decodeFromString<RegisterAccountRequest>(it) }
+
override fun run() = cliCmd(logger) {
val cfg = talerConfig(configFile)
val ctx = cfg.loadBankConfig()
@@ -361,7 +419,7 @@ class CreateAccount : CliktCommand(
class LibeufinBankCommand : CliktCommand() {
init {
versionOption(getVersion())
- subcommands(ServeBank(), BankDbInit(), CreateAccount(), ChangePw(), CliConfigCmd(BANK_CONFIG_SOURCE))
+ subcommands(ServeBank(), BankDbInit(), CreateAccountJson(), CreateAccount(), ChangePw(), CliConfigCmd(BANK_CONFIG_SOURCE))
}
override fun run() = Unit
diff --git a/integration/test/IntegrationTest.kt b/integration/test/IntegrationTest.kt
index e0bc237a..c1f04086 100644
--- a/integration/test/IntegrationTest.kt
+++ b/integration/test/IntegrationTest.kt
@@ -85,13 +85,7 @@ class IntegrationTest {
nexusCmd.run("dbinit -c conf/integration.conf -r")
bankCmd.run("dbinit -c conf/integration.conf -r")
bankCmd.run("passwd admin password -c conf/integration.conf")
- val json = obj {
- "username" to "exchange"
- "password" to "password"
- "name" to "Mr Money"
- "is_taler_exchange" to true
- }
- bankCmd.run("create-account '$json' -c conf/integration.conf")
+ bankCmd.run("create -c conf/integration.conf -u exchange -p password --name 'Mr Money' --exchange")
kotlin.concurrent.thread(isDaemon = true) {
bankCmd.run("serve -c conf/integration.conf")
}