libeufin

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

commit eb13868f603dc2701bd31561f7c2f82b4385d4d7
parent a602577777f2345dd60ef499defde7c08e786d24
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Fri,  8 Nov 2019 14:01:27 +0100

implement nexus admin /subscribers call

Diffstat:
Mnexus/src/main/kotlin/JSON.kt | 7+++++++
Mnexus/src/main/kotlin/Main.kt | 19+++++++++++++++++++
Msandbox/src/main/python/libeufin-cli | 33+++++++++++++++++++++++++++------
3 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/nexus/src/main/kotlin/JSON.kt b/nexus/src/main/kotlin/JSON.kt @@ -25,6 +25,13 @@ data class EbicsSubscriberInfoResponse( ) /** + * Admin call that tells all the subscribers managed by Nexus. + */ +data class EbicsSubscribersResponse( + val ebicsSubscribers: List<EbicsSubscriberInfoResponse> +) + +/** * Error message. */ data class NexusError( diff --git a/nexus/src/main/kotlin/Main.kt b/nexus/src/main/kotlin/Main.kt @@ -217,6 +217,23 @@ fun main() { return@get } + get("/ebics/subscribers") { + + val ebicsSubscribers = transaction { + EbicsSubscriberEntity.all().map { + EbicsSubscriberInfoResponse( + accountID = it.id.value, + hostID = it.hostID, + partnerID = it.partnerID, + systemID = it.systemID, + ebicsURL = it.ebicsURL, + userID = it.userID + ) + } + } + call.respond(EbicsSubscribersResponse(ebicsSubscribers)) + } + get("/ebics/subscribers/{id}") { val id = expectId(call.parameters["id"]) val response = transaction { @@ -235,6 +252,8 @@ fun main() { } post("/ebics/subscribers") { + + // FIXME: parsed object is not enforced! val body = try { call.receive<EbicsSubscriberInfoRequest>() } catch (e: Exception) { diff --git a/sandbox/src/main/python/libeufin-cli b/sandbox/src/main/python/libeufin-cli @@ -77,23 +77,35 @@ def sync(obj, customer_id): print(resp.content.decode("utf-8")) +@ebics.command(help="retrieve all subscribers in the system") +@click.pass_obj +def subscribers(obj): + + url = urljoin(obj["base_url"], "/ebics/subscribers") + try: + resp = get(url) + except Exception: + print("Could not reach the bank") + return + + print(resp.content.decode("utf-8")) + @ebics.command(help="insert new subscriber into Nexus") @click.pass_obj @click.option( "--ebics-url", help="URL of the EBICS server (defaults to http://localhost:5001/)", - required=False, - default="http://localhost:5001" + required=False ) @click.option( "--user-id", help="ID of the user to add in the system" , - required=True + required=False ) @click.option( "--partner-id", help="ID of the partner associated with the user" , - required=True + required=False ) @click.option( "--system-id", @@ -103,13 +115,22 @@ def sync(obj, customer_id): @click.option( "--host-id", help="ID of the EBICS server" , - required=True + required=False, + default="host01" ) def new(obj, user_id, partner_id, system_id, host_id, ebics_url): + import random + salt = random.randrange(0, 1000000000) + if not user_id: + user_id = "USER{}".format(salt) + + if not partner_id: + partner_id = "PARTNER{}".format(salt) + url = urljoin(obj["base_url"], "/ebics/subscribers") body = json=dict( - ebicsURL=ebics_url, + ebicsURL=obj["base_url"], userID=user_id, partnerID=partner_id, hostID=host_id