gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated (d08bb39e -> 322e5217)


From: gnunet
Subject: [libeufin] branch master updated (d08bb39e -> 322e5217)
Date: Mon, 22 Nov 2021 20:39:02 +0100

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

ms pushed a change to branch master
in repository libeufin.

    from d08bb39e fix proxied URL construction
     new 6a1dc505 CLI, register accounts via Access API
     new 322e5217 default demobank

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 cli/bin/libeufin-cli                               | 88 +++++++++++++++++++++-
 .../main/kotlin/tech/libeufin/sandbox/Helpers.kt   |  9 +++
 .../src/main/kotlin/tech/libeufin/sandbox/JSON.kt  | 16 +---
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  | 21 +-----
 4 files changed, 100 insertions(+), 34 deletions(-)

diff --git a/cli/bin/libeufin-cli b/cli/bin/libeufin-cli
index 52fca212..d264b5ac 100755
--- a/cli/bin/libeufin-cli
+++ b/cli/bin/libeufin-cli
@@ -20,9 +20,9 @@ from getpass import getpass
 def check_response_status(resp, expected_status_code=200):
     if resp.status_code != expected_status_code:
         print("Unexpected response status: {}".format(resp.status_code), 
file=sys.stderr)
+        print("Response: {}".format(resp.text))
         sys.exit(1)
 
-
 def tell_user(resp, expected_status_code=200, withsuccess=False):
     if resp.status_code != expected_status_code:
         print(resp.content.decode("utf-8"), file=sys.stderr)
@@ -284,9 +284,8 @@ class SandboxContext:
         sandbox_username = os.environ.get("LIBEUFIN_SANDBOX_USERNAME")
         sandbox_password = os.environ.get("LIBEUFIN_SANDBOX_PASSWORD")
         if not sandbox_username or not sandbox_password:
-            print(
-                "LIBEUFIN_SANDBOX_USERNAME and LIBEUFIN_SANDBOX_PASSWORD\n" \
-                "not found in the environment, assuming tests are being run..."
+            print("""INFO: LIBEUFIN_SANDBOX_USERNAME and 
LIBEUFIN_SANDBOX_PASSWORD
+not found in the environment, assuming tests are being run..."""
             )
         return sandbox_username, sandbox_password
 
@@ -1186,6 +1185,87 @@ def sandbox_bankaccount(ctx):
     pass
 
 
+# This group deals with the new Access API
+# and the 'demobank' model.
+@sandbox.group("demobank", help="manage customers")
+@click.pass_context
+def sandbox_demobank(ctx):
+    pass
+
+@sandbox_demobank.command("info", help="Return basic information of a bank 
account")
+@click.option(
+    "--bank-account",
+    help="Label of the bank account whose information should be returned.",
+    required=True
+)
+@click.pass_obj
+def sandbox_demobank_info(obj, bank_account):
+    sandbox_base_url = obj.require_sandbox_base_url()
+    url = urljoin_nodrop(sandbox_base_url, 
f"/access-api/accounts/{bank_account}")
+    try:
+        resp = get(
+            url,
+            auth=auth.HTTPBasicAuth(obj.username, obj.password)
+        )
+    except Exception as e:
+        print(e)
+        print("Could not reach sandbox")
+        exit(1)
+    tell_user(resp, withsuccess=True)
+
+@sandbox_demobank.command("register",
+    help="""register a new bank account.  Note that the username
+will be both the username to login at the bank and the bank account
+label"""
+)
+@click.pass_obj
+def sandbox_demobank_register(obj):
+    sandbox_base_url = obj.require_sandbox_base_url()
+    url = urljoin_nodrop(sandbox_base_url, f"/access-api/testing/register")
+    try:
+        resp = post(url,
+            json=dict(username=obj.username, password=obj.password),
+        )
+    except Exception as e:
+        print(e)
+        print("Could not reach nexus at " + url)
+        exit(1)
+    check_response_status(resp)
+
+@sandbox_demobank.command("new-ebicssubscriber",
+    help="Associate a new Ebics subscriber to a existing bank account."
+)
+@click.option("--host-id", help="Ebics host ID", required=True)
+@click.option("--partner-id", help="Ebics partner ID", required=True)
+@click.option("--user-id", help="Ebics user ID", required=True)
+@click.option(
+    "--bank-account",
+    help="Label of the bank account to associate with this Ebics subscriber",
+    required=True
+)
+@click.pass_obj
+def sandbox_demobank_ebicssubscriber(obj, host_id, partner_id, user_id, 
bank_account):
+    sandbox_base_url = obj.require_sandbox_base_url()
+    url = urljoin_nodrop(sandbox_base_url, "/ebics/subscribers")
+    try:
+        resp = post(url,
+            json=dict(
+                hostID=host_id,
+                partnerID=partner_id,
+                userID=user_id,
+                demobankAccountLabel=bank_account
+            ),
+            auth=auth.HTTPBasicAuth(
+                obj.username,
+                obj.password
+            ),
+        )
+    except Exception as e:
+        print(e)
+        print("Could not reach sandbox")
+        exit(1)
+    check_response_status(resp)
+
 @sandbox_bankaccount.command("list", help="List accounts")
 @click.pass_obj
 def bankaccount_list(obj):
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
index 5451ca25..29d93e4f 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
@@ -175,6 +175,15 @@ fun maybeCreateDefaultDemobank() {
                 allowRegistrations = true
                 name = "default"
             }
+            // Give one demobank a own bank account, mainly to award
+            // customer upon registration.
+            BankAccountEntity.new {
+                iban = getIban()
+                label = "bank" // used by the wire helper
+                owner = "bank" // used by the person name finder
+                // For now, the model assumes always one demobank
+                demoBank = getFirstDemobank()
+            }
         }
     }
 }
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt
index e85e3fbb..a25503b8 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt
@@ -57,7 +57,7 @@ data class AccountTransactions(
 )
 
 /**
- * Used to create AND show one Ebics subscriber in the system.
+ * Used to create AND show one Ebics subscriber.
  */
 data class EbicsSubscriberInfo(
     val hostID: String,
@@ -72,17 +72,9 @@ data class AdminGetSubscribers(
 )
 
 /**
- * Some obsolete code creates a bank account and after the
- * Ebics subscriber.  This doesn't allow to have bank accounts
- * without a subscriber associated to it.  Demobank should allow
- * this instead, because only one user - the exchange - will
- * ever need a Ebics subscription at the Sandbox.
- *
- * The code is obsoleted by a new endpoint that's defined within
- * the /demobanks/${demobankId} trunk.  This one allows to first create
- * a bank account, and only optionally later give a Ebics account to
- * it.
- */
+ * The following definition is obsolete because it
+ * doesn't allow to specify a demobank that will host
+ * the Ebics subscriber.  */
 data class EbicsSubscriberObsoleteApi(
     val hostID: String,
     val partnerID: String,
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 04c99eba..5cdd8cd5 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -310,18 +310,6 @@ class Serve : CliktCommand("Run sandbox HTTP server") {
             )
             exitProcess(0)
         }
-        /**
-         * Create the bank's bank account, to award the 100 Kudos
-         * when new customers open bank account.  */
-        transaction {
-            BankAccountEntity.new {
-                iban = getIban()
-                label = "bank" // used by the wire helper
-                owner = "bank" // used by the person name finder
-                // For now, the model assumes always one demobank
-                demoBank = getFirstDemobank()
-            }
-        }
         serverMain(port)
     }
 }
@@ -1340,11 +1328,11 @@ val sandboxApp: Application.() -> Unit = {
             }
             route("/ebics") {
                 post("/subscribers") {
+                    // Only the admin can create Ebics subscribers.
                     val user = call.request.basicAuth()
+                    if (user != "admin") throw forbidden("Only the Admin can 
create Ebics subscribers.")
                     val body = call.receiveJson<EbicsSubscriberInfo>()
-                    /**
-                     * Create or get the Ebics subscriber that is found.
-                     */
+                    // Create or get the Ebics subscriber that is found.
                     transaction {
                         val subscriber: EbicsSubscriberEntity = 
EbicsSubscriberEntity.find {
                             (EbicsSubscribersTable.partnerId eq 
body.partnerID).and(
@@ -1362,9 +1350,6 @@ val sandboxApp: Application.() -> Unit = {
                             body.demobankAccountLabel,
                             ensureDemobank(call)
                         )
-                        if ((user != "admin") && (bankAccount.owner != user)) 
throw forbidden(
-                            "User ${bankAccount.owner} cannot access bank 
account '${bankAccount.label}'"
-                        )
                         subscriber.bankAccount = bankAccount
                     }
                     call.respond(object {})

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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