gnunet-svn
[Top][All Lists]
Advanced

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

[taler-deployment] branch master updated (d654196 -> a6af8c8)


From: gnunet
Subject: [taler-deployment] branch master updated (d654196 -> a6af8c8)
Date: Wed, 14 Apr 2021 12:08:10 +0200

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

dold pushed a change to branch master
in repository deployment.

    from d654196  remove obsolete script
     new e121628  gitignore
     new a6af8c8  instances script

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:
 .gitignore                            |   1 +
 bin/taler-deployment-config-instances | 209 +++++++++++-----------------------
 2 files changed, 65 insertions(+), 145 deletions(-)

diff --git a/.gitignore b/.gitignore
index bbca547..1ca700b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 *~
 .mypy_cache
+.vscode
diff --git a/bin/taler-deployment-config-instances 
b/bin/taler-deployment-config-instances
index 924a9ba..f434822 100755
--- a/bin/taler-deployment-config-instances
+++ b/bin/taler-deployment-config-instances
@@ -1,56 +1,40 @@
 #!/usr/bin/env python3
 
+"""
+This script makes sure that the merchant backend instances used by the
+test/demo environment are created.
+
+We assume that the merchant backend is running, and that the "~/activate"
+file has been sourced to provide the right environment variables.
+"""
+
 import requests
 from os import environ
 from sys import exit
 from urllib.parse import urljoin
 
-MERCHANT_BACKEND_BASE_URL = environ.get("TALER_ENV_MERCHANT_BACKEND")
-if not MERCHANT_BACKEND_BASE_URL:
-    print("TALER_ENV_MERCHANT_BACKEND not defined.  Please source the 
~/activate file.")
-    exit(1)
-
-TALER_ENV_NAME = environ.get("TALER_ENV_NAME")
-if not TALER_ENV_NAME:
-    print("TALER_ENV_NAME not defined.  Please source the ~/activate file.")
-    exit(1)
-
-TALER_PATCH_INSTANCES = environ.get("TALER_PATCH_INSTANCES")
-TALER_CONFIG_CURRENCY = environ.get("TALER_CONFIG_CURRENCY", "EUR")
-
-def expectResponse(response, expected_status_codes):
-    if response.status_code not in expected_status_codes:
-        print("Configuration failed on URL: {}".format(response.url))
-        print(response.text)
+def expect_env(name):
+    val = environ.get(name)
+    if not val:
+        print(f"{name} not defined.  Please source the ~/activate file.")
         exit(1)
-    # Allows for finer grained checks.
-    return response
+    return val
 
-class Instance:
-    def __init__(self, instance_id, config_data, backend_url, is_patch=False):
-        self.instance_id = instance_id
-        self.config_data = config_data
-        self.backend_url = backend_url
-        if not is_patch: # First time instance configuration.
-            self.config_data.update(id=instance_id)
-        self.is_patch = is_patch
 
-    def get_config_data(self):
-        return self.config_data
-    def get_config_url(self):
-        if not self.is_patch:
-            return urljoin(self.backend_url, "/private/instances")
-        return urljoin(self.backend_url, 
"/private/instances/{}".format(self.instance_id))
-    def get_http_method(self):
-        if not self.is_patch:
-            return requests.post
-        return requests.patch
+MERCHANT_BACKEND_BASE_URL = expect_env("TALER_ENV_MERCHANT_BACKEND")
+TALER_ENV_NAME = expect_env("TALER_ENV_NAME")
+TALER_CONFIG_CURRENCY = expect_env("TALER_CONFIG_CURRENCY")
 
-blog = Instance(
-    "blog",
-    dict(
-        
payto_uris=[f"payto://x-taler-bank/bank.{TALER_ENV_NAME}.taler.net/blog"],
-        name="Blog",
+def ensure_instance(instance_id, name, payto_uris, auth):
+    # FIXME: Use auth once the default instance also uses token auth
+    instance_response = requests.get(
+        urljoin(MERCHANT_BACKEND_BASE_URL, f"private/instances/${instance_id}")
+    )
+    if instance_response.status_code == 200:
+        return
+    req = dict(
+        name=name,
+        payto_uris=payto_uris,
         address=dict(),
         jurisdiction=dict(),
         default_max_wire_fee=f"{TALER_CONFIG_CURRENCY}:1",
@@ -58,125 +42,60 @@ blog = Instance(
         default_max_deposit_fee=f"{TALER_CONFIG_CURRENCY}:1",
         default_wire_transfer_delay=dict(d_ms="forever"),
         default_pay_delay=dict(d_ms="forever"),
-        auth=dict(method="token", token="secret-token:sandbox")
-    ),
-    MERCHANT_BACKEND_BASE_URL,
-    TALER_PATCH_INSTANCES
+    )
+    create_resp = requests.post(
+        urljoin(MERCHANT_BACKEND_BASE_URL, "private/instances"), data=req
+    )
+    if create_resp.status_code < 200 or create_resp.status_code >= 300:
+        print(f"failed to create instance {instance_id}")
+        print(create_resp.text)
+        exit(1)
+
+ensure_instance(
+    "blog",
+    name="Blog",
+    payto_uris=[f"payto://x-taler-bank/bank.{TALER_ENV_NAME}.taler.net/blog"],
+    auth=dict(method="token", token="secret-token:sandbox"),
 )
 
-donations = Instance(
+ensure_instance(
     "donations",
-    dict(
-        
payto_uris=[f"payto://x-taler-bank/bank.{TALER_ENV_NAME}.taler.net/donations"],
-        name="Donations",
-        address=dict(),
-        jurisdiction=dict(),
-        default_max_wire_fee=f"{TALER_CONFIG_CURRENCY}:1",
-        default_wire_fee_amortization=3,
-        default_max_deposit_fee=f"{TALER_CONFIG_CURRENCY}:1",
-        default_wire_transfer_delay=dict(d_ms="forever"),
-        default_pay_delay=dict(d_ms="forever"),
-        auth=dict(method="token", token="secret-token:sandbox")
-    ),
-    MERCHANT_BACKEND_BASE_URL,
-    TALER_PATCH_INSTANCES
+    name="Donations",
+    
payto_uris=[f"payto://x-taler-bank/bank.{TALER_ENV_NAME}.taler.net/donations"],
+    auth=dict(method="token", token="secret-token:sandbox"),
 )
 
-survey = Instance(
+ensure_instance(
     "survey",
-    dict(
-        
payto_uris=[f"payto://x-taler-bank/bank.{TALER_ENV_NAME}.taler.net/survey"],
-        name="Survey",
-        address=dict(),
-        jurisdiction=dict(),
-        default_max_wire_fee=f"{TALER_CONFIG_CURRENCY}:1",
-        default_wire_fee_amortization=3,
-        default_max_deposit_fee=f"{TALER_CONFIG_CURRENCY}:1",
-        default_wire_transfer_delay=dict(d_ms="forever"),
-        default_pay_delay=dict(d_ms="forever"),
-        auth=dict(method="token", token="secret-token:sandbox")
-    ),
-    MERCHANT_BACKEND_BASE_URL,
-    TALER_PATCH_INSTANCES
+    name="Survey",
+    
payto_uris=[f"payto://x-taler-bank/bank.{TALER_ENV_NAME}.taler.net/survey"],
+    auth=dict(method="token", token="secret-token:sandbox"),
 )
 
-pos = Instance(
+ensure_instance(
     "pos",
-    dict(
-        
payto_uris=[f"payto://x-taler-bank/bank.{TALER_ENV_NAME}.taler.net/pos"],
-        name="PoS",
-        address=dict(),
-        jurisdiction=dict(),
-        default_max_wire_fee=f"{TALER_CONFIG_CURRENCY}:1",
-        default_wire_fee_amortization=3,
-        default_max_deposit_fee=f"{TALER_CONFIG_CURRENCY}:1",
-        default_wire_transfer_delay=dict(d_ms="forever"),
-        default_pay_delay=dict(d_ms="forever"),
-        auth=dict(method="token", token="secret-token:sandbox")
-    ),
-    MERCHANT_BACKEND_BASE_URL,
-    TALER_PATCH_INSTANCES
+    name="PoS",
+    payto_uris=[f"payto://x-taler-bank/bank.{TALER_ENV_NAME}.taler.net/pos"],
+    auth=dict(method="token", token="secret-token:sandbox"),
 )
 
-gnunet = Instance(
+ensure_instance(
     "GNUnet",
-    dict(
-        
payto_uris=[f"payto://x-taler-bank/bank.{TALER_ENV_NAME}.taler.net/GNUnet"],
-        name="GNUnet",
-        address=dict(),
-        jurisdiction=dict(),
-        default_max_wire_fee=f"{TALER_CONFIG_CURRENCY}:1",
-        default_wire_fee_amortization=3,
-        default_max_deposit_fee=f"{TALER_CONFIG_CURRENCY}:1",
-        default_wire_transfer_delay=dict(d_ms="forever"),
-        default_pay_delay=dict(d_ms="forever"),
-        auth=dict(method="token", token="secret-token:sandbox")
-    ),
-    MERCHANT_BACKEND_BASE_URL,
-    TALER_PATCH_INSTANCES
+    name="GNUnet",
+    
payto_uris=[f"payto://x-taler-bank/bank.{TALER_ENV_NAME}.taler.net/GNUnet"],
+    auth=dict(method="token", token="secret-token:sandbox"),
 )
 
-taler = Instance(
+ensure_instance(
     "Taler",
-    dict(
-        
payto_uris=[f"payto://x-taler-bank/bank.{TALER_ENV_NAME}.taler.net/Taler"],
-        name="Taler",
-        address=dict(),
-        jurisdiction=dict(),
-        default_max_wire_fee=f"{TALER_CONFIG_CURRENCY}:1",
-        default_wire_fee_amortization=3,
-        default_max_deposit_fee=f"{TALER_CONFIG_CURRENCY}:1",
-        default_wire_transfer_delay=dict(d_ms="forever"),
-        default_pay_delay=dict(d_ms="forever"),
-        auth=dict(method="token", token="secret-token:sandbox")
-    ),
-    MERCHANT_BACKEND_BASE_URL,
-    TALER_PATCH_INSTANCES
+    name="Taler",
+    payto_uris=[f"payto://x-taler-bank/bank.{TALER_ENV_NAME}.taler.net/Taler"],
+    auth=dict(method="token", token="secret-token:sandbox"),
 )
 
-tor = Instance(
+ensure_instance(
     "Tor",
-    dict(
-        
payto_uris=[f"payto://x-taler-bank/bank.{TALER_ENV_NAME}.taler.net/Tor"],
-        name="Tor",
-        address=dict(),
-        jurisdiction=dict(),
-        default_max_wire_fee=f"{TALER_CONFIG_CURRENCY}:1",
-        default_wire_fee_amortization=3,
-        default_max_deposit_fee=f"{TALER_CONFIG_CURRENCY}:1",
-        default_wire_transfer_delay=dict(d_ms="forever"),
-        default_pay_delay=dict(d_ms="forever"),
-        auth=dict(method="token", token="secret-token:sandbox")
-    ),
-    MERCHANT_BACKEND_BASE_URL,
-    TALER_PATCH_INSTANCES
+    name="Tor",
+    payto_uris=[f"payto://x-taler-bank/bank.{TALER_ENV_NAME}.taler.net/Tor"],
+    auth=dict(method="token", token="secret-token:sandbox"),
 )
-
-for instance in [blog, donations, pos, tor, taler, gnunet, survey]:
-    expectResponse(
-        instance.get_http_method()(
-            instance.get_config_url(),
-            json=instance.get_config_data()
-        ),
-        [204, 409]
-    )

-- 
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]