commit 9eaee8c372609ae962a6e2c8e44c9b4faae65443
parent 384190428a0907cb8c046d85de603a3c4ef0240e
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Fri, 24 Jan 2020 23:08:17 +0100
/admin/add/subscriber for Sandbox.
Diffstat:
5 files changed, 104 insertions(+), 5 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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
@@ -20,6 +20,53 @@ 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