gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: /admin/add/subscriber for Sandbox.


From: gnunet
Subject: [libeufin] branch master updated: /admin/add/subscriber for Sandbox.
Date: Fri, 24 Jan 2020 23:08:36 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 9eaee8c  /admin/add/subscriber for Sandbox.
9eaee8c is described below

commit 9eaee8c372609ae962a6e2c8e44c9b4faae65443
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri Jan 24 23:08:17 2020 +0100

    /admin/add/subscriber for Sandbox.
---
 nexus/src/main/kotlin/Main.kt                      |  2 -
 .../src/main/kotlin/tech/libeufin/sandbox/DB.kt    |  2 +
 .../src/main/kotlin/tech/libeufin/sandbox/JSON.kt  | 21 +++++++++-
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  | 36 ++++++++++++++++-
 sandbox/src/main/python/libeufin-cli               | 47 ++++++++++++++++++++++
 5 files changed, 104 insertions(+), 4 deletions(-)

diff --git a/nexus/src/main/kotlin/Main.kt b/nexus/src/main/kotlin/Main.kt
index e5cc336..65af692 100644
--- a/nexus/src/main/kotlin/Main.kt
+++ b/nexus/src/main/kotlin/Main.kt
@@ -108,10 +108,8 @@ fun main() {
         }
 
         install(ContentNegotiation) {
-
             moshi {
             }
-
             gson {
                 setDateFormat(DateFormat.LONG)
                 setPrettyPrinting()
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
index c6a580d..e8853d5 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -244,6 +244,7 @@ object EbicsSubscribersTable : IntIdTable() {
     val userId = text("userID")
     val partnerId = text("partnerID")
     val systemId = text("systemID").nullable()
+    val hostId = text("hostID")
 
     val signatureKey = reference("signatureKey", 
EbicsSubscriberPublicKeysTable).nullable()
     val encryptionKey = reference("encryptionKey", 
EbicsSubscriberPublicKeysTable).nullable()
@@ -262,6 +263,7 @@ class EbicsSubscriberEntity(id: EntityID<Int>) : 
IntEntity(id) {
     var userId by EbicsSubscribersTable.userId
     var partnerId by EbicsSubscribersTable.partnerId
     var systemId by EbicsSubscribersTable.systemId
+    var hostId by EbicsSubscribersTable.hostId
 
     var signatureKey by EbicsSubscriberPublicKeyEntity optionalReferencedOn 
EbicsSubscribersTable.signatureKey
     var encryptionKey by EbicsSubscriberPublicKeyEntity optionalReferencedOn 
EbicsSubscribersTable.encryptionKey
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt
index 3b45960..8d8eafe 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt
@@ -143,4 +143,23 @@ data class EbicsHostResponse(
 data class EbicsHostCreateRequest(
     val hostID: String,
     val ebicsVersion: String
-)
\ No newline at end of file
+)
+
+data class AdminAddSubscriberRequest(
+    val name: String, // person's name
+    val hostID: String,
+    val partnerID: String,
+    val userID: String,
+    val systemID: String? = null
+)
+
+data class AdminSubscriberElement(
+    var name: String,
+    var userId: String,
+    var partnerID: String,
+    var hostID: String
+)
+
+data class AdminGetSubscribers(
+    var subscribers: MutableList<AdminSubscriberElement> = mutableListOf()
+)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index f9a8b67..858d2a7 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -153,6 +153,7 @@ fun sampleData() {
             partnerId = "PARTNER1"
             userId = "USER1"
             systemId = null
+            hostId = "HOST1"
             state = SubscriberState.NEW
             nextOrderID = 1
             bankCustomer = customerEntity
@@ -274,17 +275,50 @@ fun main() {
 
                 val customer = findCustomer(call.parameters["id"])
                 val balance = calculateBalance(customer.id.value, null, null)
-
                 call.respond(
                     CustomerBalance(
                     name = customer.customerName,
                     balance = "${balance} EUR"
                     )
                 )
+                return@get
+            }
 
+            get("/admin/get/subscribers") {
+                var ret = AdminGetSubscribers()
+                transaction {
+                    EbicsSubscriberEntity.all().forEach {
+                        ret.subscribers.add(
+                            AdminSubscriberElement(
+                            userId = it.userId, partnerID = it.partnerId, 
hostID = it.hostId, name = it.bankCustomer.customerName))
+                    }
+                }
+                call.respond(ret)
                 return@get
             }
 
+            post("/admin/add/subscriber") {
+                val body = call.receive<AdminAddSubscriberRequest>()
+
+                transaction {
+                    val customerEntity = BankCustomerEntity.new {
+                        addLogger(StdOutSqlLogger)
+                        customerName = body.name
+                    }
+                    EbicsSubscriberEntity.new {
+                        partnerId = body.partnerID
+                        userId = body.userID
+                        systemId = null
+                        state = SubscriberState.NEW
+                        nextOrderID = 1
+                        bankCustomer = customerEntity
+                    }
+                }
+
+                call.respondText("Subscriber created.", 
ContentType.Text.Plain, HttpStatusCode.OK)
+                return@post
+            }
+
             get("/") {
                 call.respondText("Hello LibEuFin!\n", ContentType.Text.Plain)
             }
diff --git a/sandbox/src/main/python/libeufin-cli 
b/sandbox/src/main/python/libeufin-cli
index ab15069..a5b5b9b 100755
--- a/sandbox/src/main/python/libeufin-cli
+++ b/sandbox/src/main/python/libeufin-cli
@@ -19,6 +19,53 @@ from getpass import getpass
 def cli(ctx, nexus_base_url):
     ctx.obj = dict(nexus_base_url=nexus_base_url)
 
+@cli.group()
+def admin():
+    pass
+
+@admin.command(help="Instruct the Sandbox to create a new EBICS Subscriber")
+@click.option(
+    "--sandbox-url",
+    help="URL (with path) of the Sandbox that will activate the new 
Subscriber",
+    required=True
+)
+@click.option(
+    "--user-id",
+    help="EBICS user ID",
+    required=True
+)
+@click.option(
+    "--partner-id",
+    help="EBICS partner ID",
+    required=True
+)
+@click.option(
+    "--host-id",
+    help="EBICS host ID",
+    required=True
+)
+@click.option(
+    "--name",
+    help="Name of the person associated with the user ID",
+    required=True
+)
+def add_subscriber(sandbox_url, user_id, partner_id, host_id, name):
+    body = dict(
+            userID=user_id,
+            partnerID=partner_id,
+            hostID=host_id,
+            name=name
+    )
+
+    try:
+        resp = post(sandbox_url, json=body)
+    except Exception:
+        print("Could not reach the Sandbox")
+        return
+
+    print(resp.content.decode("utf-8"))
+
+
 @cli.group()
 def ebics():
     pass

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]