libeufin

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

commit 15ae0483272dfcdb6245443631c37b91223bb795
parent 757c39c6c7686d45cfa9c7764d27a5792658a613
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Thu,  3 Oct 2019 18:44:17 +0200

Transparently create (EBICS) user/partner/system IDs columns.

Diffstat:
Msrc/main/kotlin/tech/libeufin/DB.kt | 46++++++++++++++++++++++++++++++++++++----------
Msrc/main/kotlin/tech/libeufin/JSON.kt | 2+-
Msrc/main/kotlin/tech/libeufin/Main.kt | 6++----
Msrc/main/python/libeufin-cli | 7++++++-
4 files changed, 45 insertions(+), 16 deletions(-)

diff --git a/src/main/kotlin/tech/libeufin/DB.kt b/src/main/kotlin/tech/libeufin/DB.kt @@ -5,7 +5,9 @@ import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.transactions.transaction const val CUSTOMER_NAME_MAX_LENGTH = 20 -const val SUBSCRIBER_ID_MAX_LENGTH = 10 +const val EBICS_USER_ID_MAX_LENGTH = 10 +const val EBICS_PARTNER_ID_MAX_LENGTH = 10 +const val EBICS_SYSTEM_ID_MAX_LENGTH = 10 const val PUBLIC_KEY_MAX_LENGTH = 256 // FIXME review this value! const val PRIV_KEY_MAX_LENGTH = 512 // FIXME review this value! const val SQL_ENUM_SUBSCRIBER_STATES = "ENUM('NEW', 'PARTIALLI_INITIALIZED_INI', 'PARTIALLY_INITIALIZED_HIA', 'INITIALIZED', 'READY')" @@ -89,16 +91,23 @@ class BankCustomer(id: EntityID<Int>) : IntEntity(id) { * - SystemID, (optional) the machine that is handling the EBICS task on behalf of the UserID. */ -/** - * Table for UserID. - */ object EbicsUsers: IntIdTable() { - // For simplicity, this entity is implemented by the - // 'id' field provided by the table constructor by default. + /* EBICS user ID in the string form. */ + val userId = varchar("userId", EBICS_USER_ID_MAX_LENGTH).nullable() + } -class EbicsUser(id: EntityID<Int>) : IntEntity(id) { - companion object : IntEntityClass<EbicsUser>(EbicsUsers) +class EbicsUser(id: EntityID<Int>) : IntEntity(id){ + companion object : IntEntityClass<EbicsUser>(EbicsUsers) { + fun newUser() : EbicsUser { + var row = Companion.new { + } + row.userId = "u${row.id}" + return row + } + } + + var userId by EbicsUsers.userId } /** @@ -107,11 +116,19 @@ class EbicsUser(id: EntityID<Int>) : IntEntity(id) { object EbicsPartners: IntIdTable() { // For simplicity, this entity is implemented by the // 'id' field provided by the table constructor by default. + val partnerId = varchar("partnerId", EBICS_PARTNER_ID_MAX_LENGTH).nullable() } class EbicsPartner(id: EntityID<Int>) : IntEntity(id) { - companion object : IntEntityClass<EbicsPartner>(EbicsPartners) + companion object : IntEntityClass<EbicsPartner>(EbicsPartners) { + fun newUser(): EbicsPartner { + var row = EbicsPartner.new { } + row.partnerId = "p${row.id}" + return row + } + } + var partnerId by EbicsPartners.partnerId } @@ -121,10 +138,19 @@ class EbicsPartner(id: EntityID<Int>) : IntEntity(id) { object EbicsSystems: IntIdTable() { // For simplicity, this entity is implemented by the // 'id' field provided by the table constructor by default. + val systemId = EbicsPartners.varchar("systemId", EBICS_SYSTEM_ID_MAX_LENGTH).nullable() } class EbicsSystem(id: EntityID<Int>) : IntEntity(id) { - companion object : IntEntityClass<EbicsSystem>(EbicsSystems) + companion object : IntEntityClass<EbicsSystem>(EbicsSystems) { + fun newUser(): EbicsSystem { + var row = EbicsSystem.new { } + row.systemId = "s${row.id}" + return row + } + } + + var systemId by EbicsSystems.systemId } /** diff --git a/src/main/kotlin/tech/libeufin/JSON.kt b/src/main/kotlin/tech/libeufin/JSON.kt @@ -28,7 +28,7 @@ data class CustomerInfo( ) data class CustomerEbicsInfo( - val userId: Int + val userId: String ) /** diff --git a/src/main/kotlin/tech/libeufin/Main.kt b/src/main/kotlin/tech/libeufin/Main.kt @@ -77,7 +77,7 @@ fun main() { logger.info(body.toString()) val returnId = transaction { - val myUserId = EbicsUser.new { } + var myUserId = EbicsUser.newUser() val myPartnerId = EbicsPartner.new { } val mySystemId = EbicsSystem.new { } val subscriber = EbicsSubscriber.new { @@ -115,14 +115,12 @@ fun main() { return@get } - logger.info("Querying ID: $id") - val customerInfo = transaction { val customer = BankCustomer.findById(id) ?: return@transaction null CustomerInfo( customer.name, ebicsInfo = CustomerEbicsInfo( - customer.ebicsSubscriber.userId.id.value + customer.ebicsSubscriber.userId.userId!! ) ) } diff --git a/src/main/python/libeufin-cli b/src/main/python/libeufin-cli @@ -3,6 +3,7 @@ import os import click import hashlib +import errno from datetime import datetime from requests import post, get from Crypto.PublicKey import RSA @@ -63,7 +64,11 @@ def customers(obj): keyfile.write(pem) keyfile.write("\n") keyfile.close() - print("Customer and private keys ({}) correctly generated.".format(customer_path)) + print( + "Customer (id == {}) and private keys ({}) correctly generated.".format( + customer_id, customer_path + ) + ) @admin.command(help="Ask details about a customer") @click.option(