libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit aabfb5224e1d1298281241296121a27700a1acf0
parent c61a5543d6dcee2b9c36bdbd68da183311499a01
Author: Antoine A <>
Date:   Tue,  5 Dec 2023 15:21:41 +0000

Add supported_tan_channels in config

Diffstat:
MAPI_CHANGES.md | 7++++---
Mbank/src/main/kotlin/tech/libeufin/bank/Config.kt | 15++++++++++-----
Mbank/src/main/kotlin/tech/libeufin/bank/Constants.kt | 10++++++++--
Mbank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt | 8+++-----
Mbank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt | 11++++++-----
Mdatabase-versioning/libeufin-bank-0001.sql | 2+-
6 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/API_CHANGES.md b/API_CHANGES.md @@ -4,9 +4,10 @@ This files contains all the API changes for the current release: ## bank serve - - POST /accounts: now returns RegisterAccountResponse with IBAN on http code 200 instead of 201 - - CREATE /accounts: new debit_threshold field similar to the one of PATH /accounts - - GET /config: new default_debit_threshold field for the default debt limit for newly created accounts +- POST /accounts: now returns RegisterAccountResponse with IBAN on http code 200 instead of 201 +- CREATE /accounts: new debit_threshold field similar to the one of PATH /accounts +- GET /config: new default_debit_threshold field for the default debt limit for newly created accounts +- GET /config: new supported_tan_channels field which lists all the TAN channels supported by the server ## bank cli diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Config.kt b/bank/src/main/kotlin/tech/libeufin/bank/Config.kt @@ -50,9 +50,8 @@ data class BankConfig( val allowConversion: Boolean, val fiatCurrency: String?, val fiatCurrencySpec: CurrencySpecification?, - val tanSms: String?, - val tanEmail: String?, - val spaPath: String? + val spaPath: String?, + val tanChannels: Map<TanChannel, String> ) @Serializable @@ -104,6 +103,13 @@ fun TalerConfig.loadBankConfig(): BankConfig { fiatCurrency = requireString("libeufin-bank", "fiat_currency"); fiatCurrencySpec = currencySpecificationFor(fiatCurrency) } + val tanChannels = buildMap { + for (channel in TanChannel.entries) { + lookupPath("libeufin-bank", "tan_$channel")?.notEmptyOrNull()?.let { + put(channel, it) + } + } + } return BankConfig( regionalCurrency = regionalCurrency, regionalCurrencySpec = currencySpecificationFor(regionalCurrency), @@ -117,8 +123,7 @@ fun TalerConfig.loadBankConfig(): BankConfig { allowConversion = allowConversion, fiatCurrency = fiatCurrency, fiatCurrencySpec = fiatCurrencySpec, - tanSms = lookupPath("libeufin-bank", "tan_sms")?.notEmptyOrNull(), - tanEmail = lookupPath("libeufin-bank", "tan_email")?.notEmptyOrNull(), + tanChannels = tanChannels ) } diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Constants.kt b/bank/src/main/kotlin/tech/libeufin/bank/Constants.kt @@ -36,4 +36,10 @@ val TOKEN_DEFAULT_DURATION: java.time.Duration = Duration.ofDays(1L) val RESERVED_ACCOUNTS = setOf("admin", "bank") // Security -const val MAX_BODY_LENGTH: Long = 4 * 1024 // 4kB -\ No newline at end of file +const val MAX_BODY_LENGTH: Long = 4 * 1024 // 4kB + +// API version +const val COREBANK_API_VERSION: String = "0:0:1" +const val CONVERSION_API_VERSION: String = "0:0:0" +const val INTEGRATION_API_VERSION: String = "1:0:1" +const val WIRE_GATEWAY_API_VERSION: String = "0:0:0" +\ 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 @@ -53,7 +53,8 @@ fun Routing.coreBankApi(db: Database, ctx: BankConfig) { allow_conversion = ctx.allowConversion, allow_registrations = ctx.allowRegistration, allow_deletions = ctx.allowAccountDeletion, - default_debit_threshold = ctx.defaultDebtLimit + default_debit_threshold = ctx.defaultDebtLimit, + supported_tan_channels = ctx.tanChannels.keys ) ) } @@ -508,10 +509,7 @@ private fun Routing.coreBankCashoutApi(db: Database, ctx: BankConfig) = conditio ctx.checkFiatCurrency(req.amount_credit) val tanChannel = req.tan_channel ?: TanChannel.sms - val tanScript = when (tanChannel) { - TanChannel.sms -> ctx.tanSms - TanChannel.email -> ctx.tanEmail - } ?: throw libeufinError( + val tanScript = ctx.tanChannels.get(tanChannel) ?: throw libeufinError( HttpStatusCode.NotImplemented, "Unsupported tan channel $tanChannel", TalerErrorCode.BANK_TAN_CHANNEL_NOT_SUPPORTED diff --git a/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt b/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt @@ -231,10 +231,11 @@ data class Config( val allow_conversion: Boolean, val allow_registrations: Boolean, val allow_deletions: Boolean, - val default_debit_threshold: TalerAmount + val default_debit_threshold: TalerAmount, + val supported_tan_channels: Set<TanChannel> ) { val name: String = "libeufin-bank" - val version: String = "0:0:0" + val version: String = COREBANK_API_VERSION } @Serializable @@ -246,7 +247,7 @@ data class ConversionConfig( val conversion_rate: ConversionRate ) { val name: String = "taler-conversion-info" - val version: String = "0:0:0" + val version: String = CONVERSION_API_VERSION } @Serializable @@ -255,7 +256,7 @@ data class TalerIntegrationConfigResponse( val currency_specification: CurrencySpecification ) { val name: String = "taler-bank-integration"; - val version: String = "1:0:1"; + val version: String = INTEGRATION_API_VERSION; } enum class CreditDebitInfo { @@ -487,7 +488,7 @@ data class AddIncomingResponse( @Serializable data class TWGConfigResponse( val name: String = "taler-wire-gateway", - val version: String = "0:0:0", + val version: String = WIRE_GATEWAY_API_VERSION, val currency: String ) diff --git a/database-versioning/libeufin-bank-0001.sql b/database-versioning/libeufin-bank-0001.sql @@ -198,7 +198,7 @@ CREATE TABLE IF NOT EXISTS cashout_operations REFERENCES challenges(challenge_id) ON DELETE CASCADE ON UPDATE RESTRICT - ,tan_channel TEXT NULL DEFAULT NULL + ,tan_channel TEXT NULL DEFAULT NULL -- TODO should be tan_enum but might be removed in the future ,tan_info TEXT NULL DEFAULT NULL ,aborted BOOLEAN NOT NULL DEFAULT FALSE ,local_transaction BIGINT UNIQUE DEFAULT NULL-- FIXME: Comment that the transaction only gets created after the TAN confirmation