diff options
author | Antoine A <> | 2024-02-05 12:14:49 +0100 |
---|---|---|
committer | Antoine A <> | 2024-02-05 12:14:49 +0100 |
commit | 54ff928887a5b5a96a262f35bf9e45e646184e07 (patch) | |
tree | 2bf437f0e816e5061f75cbc397c88e7f8b0c7db6 /bank | |
parent | 836956edb700e953ceb03fbb862822c4f31fe722 (diff) | |
download | libeufin-54ff928887a5b5a96a262f35bf9e45e646184e07.tar.gz libeufin-54ff928887a5b5a96a262f35bf9e45e646184e07.tar.bz2 libeufin-54ff928887a5b5a96a262f35bf9e45e646184e07.zip |
Fix admin account create with x-taler-bank and improve config error msg
Diffstat (limited to 'bank')
-rw-r--r-- | bank/conf/test_x_taler_bank.conf | 2 | ||||
-rw-r--r-- | bank/src/main/kotlin/tech/libeufin/bank/Config.kt | 22 | ||||
-rw-r--r-- | bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt | 2 | ||||
-rw-r--r-- | bank/src/main/kotlin/tech/libeufin/bank/Main.kt | 2 | ||||
-rw-r--r-- | bank/src/main/kotlin/tech/libeufin/bank/helpers.kt | 13 | ||||
-rw-r--r-- | bank/src/test/kotlin/DatabaseTest.kt | 4 | ||||
-rw-r--r-- | bank/src/test/kotlin/helpers.kt | 2 |
7 files changed, 23 insertions, 24 deletions
diff --git a/bank/conf/test_x_taler_bank.conf b/bank/conf/test_x_taler_bank.conf index 294aa371..a2ef2f85 100644 --- a/bank/conf/test_x_taler_bank.conf +++ b/bank/conf/test_x_taler_bank.conf @@ -5,7 +5,7 @@ ALLOW_REGISTRATION = yes ALLOW_ACCOUNT_DELETION = yes ALLOW_EDIT_NAME = yes ALLOW_EDIT_CASHOUT_PAYTO_URI = yes -PAYMENT_METHOD = x-taler-bank +WIRE_TYPE = x-taler-bank X_TALER_BANK_PAYTO_HOSTNAME = bank.hostname.test [libeufin-bankdb-postgres] diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Config.kt b/bank/src/main/kotlin/tech/libeufin/bank/Config.kt index 7539da69..5d881461 100644 --- a/bank/src/main/kotlin/tech/libeufin/bank/Config.kt +++ b/bank/src/main/kotlin/tech/libeufin/bank/Config.kt @@ -86,7 +86,7 @@ fun TalerConfig.loadServerConfig(): ServerConfig { return when (val method = requireString("libeufin-bank", "serve")) { "tcp" -> ServerConfig.Tcp(requireNumber("libeufin-bank", "port")) "unix" -> ServerConfig.Unix(requireString("libeufin-bank", "unixpath"), requireNumber("libeufin-bank", "unixpath_mode")) - else -> throw Exception("Unknown server method '$method' expected 'tcp' or 'unix'") + else -> throw Exception(" Unknown server method '$method' expected 'tcp' or 'unix' got '$method'") } } @@ -106,10 +106,10 @@ fun TalerConfig.loadBankConfig(): BankConfig { } } } - val method = when (val raw = lookupString("libeufin-bank", "payment_method")) { + val method = when (val raw = lookupString("libeufin-bank", "wire_type")) { "iban" -> WireMethod.IBAN "x-taler-bank" -> WireMethod.X_TALER_BANK - else -> throw TalerConfigError("expected wire method for section libeufin-bank, option payment_method, but $raw is unknown") + else -> throw TalerConfigError("expected a payment target type for section libeufin-bank, option wire_type, but $raw is unknown") } val payto = when (method) { WireMethod.IBAN -> BankPaytoCtx(bic = lookupString("libeufin-bank", "iban_payto_bic")) @@ -158,39 +158,35 @@ private fun TalerConfig.amount(section: String, option: String, currency: String val amount = try { TalerAmount(amountStr) } catch (e: Exception) { - throw TalerConfigError("expected amount for section $section, option $option, but amount is malformed") + throw TalerConfigError("amount", section, option, "but amount is malformed") } if (amount.currency != currency) { - throw TalerConfigError( - "expected amount for section $section, option $option, but currency is wrong (got ${amount.currency} expected $currency" - ) + throw TalerConfigError("amount", section, option, "but currency is wrong : got ${amount.currency} expected $currency") } return amount } private fun TalerConfig.requireAmount(section: String, option: String, currency: String): TalerAmount = - amount(section, option, currency) ?: - throw TalerConfigError("expected amount for section $section, option $option, but config value is empty") + amount(section, option, currency) ?: throw TalerConfigError("amount", section, option, "but config value is empty") private fun TalerConfig.decimalNumber(section: String, option: String): DecimalNumber? { val numberStr = lookupString(section, option) ?: return null try { return DecimalNumber(numberStr) } catch (e: Exception) { - throw TalerConfigError("expected decimal number for section $section, option $option, but number is malformed") + throw TalerConfigError("decimal number", section, option, "but number is malformed") } } private fun TalerConfig.requireDecimalNumber(section: String, option: String): DecimalNumber - = decimalNumber(section, option) ?: - throw TalerConfigError("expected decimal number for section $section, option $option, but config value is empty") + = decimalNumber(section, option) ?: throw TalerConfigError("decimal number", section, option, "but config value is empty") private fun TalerConfig.RoundingMode(section: String, option: String): RoundingMode? { val str = lookupString(section, option) ?: return null; try { return RoundingMode.valueOf(str) } catch (e: Exception) { - throw TalerConfigError("expected rouding mode for section $section, option $option, but $str is unknown") + throw TalerConfigError("rouding mode", section, option, "but $str is unknown") } }
\ No newline at end of file diff --git a/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt b/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt index e6b8ae20..a08b7c50 100644 --- a/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt +++ b/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt @@ -236,8 +236,6 @@ suspend fun createAccount( return Pair(res, internalPayto.bank(req.name, cfg.payto)) } } - - } suspend fun patchAccount( diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt index a85cff41..d9591183 100644 --- a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt +++ b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt @@ -238,7 +238,7 @@ class BankDbInit : CliktCommand("Initialize the libeufin-bank database", name = initializeDatabaseTables(conn, cfg, sqlFilePrefix = "libeufin-bank") } // Create admin account if missing - val res = maybeCreateAdminAccount(db, ctx) // logs provided by the helper + val res = createAdminAccount(db, ctx) // logs provided by the helper when (res) { AccountCreationResult.BonusBalanceInsufficient -> {} AccountCreationResult.LoginReuse -> {} diff --git a/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt b/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt index 5f52fda0..24dc4168 100644 --- a/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt +++ b/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt @@ -110,7 +110,7 @@ fun ApplicationCall.longParameter(name: String): Long { * * It returns false in case of problems, true otherwise. */ -suspend fun maybeCreateAdminAccount(db: Database, ctx: BankConfig, pw: String? = null): AccountCreationResult { +suspend fun createAdminAccount(db: Database, cfg: BankConfig, pw: String? = null): AccountCreationResult { var pwStr = pw; if (pwStr == null) { val pwBuf = ByteArray(32) @@ -118,15 +118,20 @@ suspend fun maybeCreateAdminAccount(db: Database, ctx: BankConfig, pw: String? = pwStr = String(pwBuf, Charsets.UTF_8) } + val payto = when (cfg.wireMethod) { + WireMethod.IBAN -> IbanPayto.rand() + WireMethod.X_TALER_BANK -> XTalerBankPayto.forUsername("admin") + } + return db.account.create( login = "admin", password = pwStr, name = "Bank administrator", - internalPayto = IbanPayto.rand(), + internalPayto = payto, isPublic = false, isTalerExchange = false, - maxDebt = ctx.defaultDebtLimit, - bonus = TalerAmount(0, 0, ctx.regionalCurrency), + maxDebt = cfg.defaultDebtLimit, + bonus = TalerAmount(0, 0, cfg.regionalCurrency), checkPaytoIdempotent = false, email = null, phone = null, diff --git a/bank/src/test/kotlin/DatabaseTest.kt b/bank/src/test/kotlin/DatabaseTest.kt index 877e6042..97a1b4f5 100644 --- a/bank/src/test/kotlin/DatabaseTest.kt +++ b/bank/src/test/kotlin/DatabaseTest.kt @@ -38,9 +38,9 @@ class DatabaseTest { @Test fun createAdmin() = setup { db, ctx -> // Create admin account - assertEquals(AccountCreationResult.Success, maybeCreateAdminAccount(db, ctx)) + assertEquals(AccountCreationResult.Success, createAdminAccount(db, ctx)) // Checking idempotency - assertEquals(AccountCreationResult.LoginReuse, maybeCreateAdminAccount(db, ctx)) + assertEquals(AccountCreationResult.LoginReuse, createAdminAccount(db, ctx)) } @Test diff --git a/bank/src/test/kotlin/helpers.kt b/bank/src/test/kotlin/helpers.kt index 3175c74c..e6c53565 100644 --- a/bank/src/test/kotlin/helpers.kt +++ b/bank/src/test/kotlin/helpers.kt @@ -128,7 +128,7 @@ fun bankSetup( tanChannel = null )) // Create admin account - assertEquals(AccountCreationResult.Success, maybeCreateAdminAccount(db, ctx, "admin-password")) + assertEquals(AccountCreationResult.Success, createAdminAccount(db, ctx, "admin-password")) testApplication { application { corebankWebApp(db, ctx) |