gnunet-svn
[Top][All Lists]
Advanced

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

[taler-deployment] branch master updated: taler-local: logging. Sandbox


From: gnunet
Subject: [taler-deployment] branch master updated: taler-local: logging. Sandbox auth env
Date: Fri, 15 Oct 2021 09:48:46 +0200

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

ms pushed a commit to branch master
in repository deployment.

The following commit(s) were added to refs/heads/master by this push:
     new 0bffb79  taler-local: logging. Sandbox auth env
0bffb79 is described below

commit 0bffb79fb28f52a36e19496b1e341d1ec8032396
Author: ms <ms@taler.net>
AuthorDate: Fri Oct 15 09:48:38 2021 +0200

    taler-local: logging. Sandbox auth env
---
 bin/WIP/taler-local | 87 ++++++++++++++++++++++++++++++++---------------------
 1 file changed, 52 insertions(+), 35 deletions(-)

diff --git a/bin/WIP/taler-local b/bin/WIP/taler-local
index 9ed5a53..752e726 100755
--- a/bin/WIP/taler-local
+++ b/bin/WIP/taler-local
@@ -55,6 +55,7 @@ TALER_ROOT_DIR = Path.home() / ".taler"
 # Print No Newline.
 def print_nn(msg):
     print(msg, end="")
+    sys.stdout.flush()
 
 @dataclass
 class Repo:
@@ -459,7 +460,7 @@ class TalerReverseProxy(Flask):
         self.proc.join()
 
     def get_log_filename(self):
-        return self.logger.handlers[0].baseFilename
+        return self.logger.root.handlers[0].baseFilename
 
     def start(self):
         if not self.log_dir.is_dir():
@@ -491,12 +492,6 @@ class TalerReverseProxy(Flask):
 
     def proxy(self, component, path=""):
         s = Session()
-        sockets_dir_urlenc = quote(str(self.unix_sockets_dir), safe="")
-        uri = f"http+unix://%2F{sockets_dir_urlenc}%2F{component}.sock/{path}"
-        raw_data = request.get_data()
-        if len(request.args) > 0:
-            uri += f"?{request.query_string.decode()}"
-        self.logger.debug("Proxying to: " + uri)
         try:
             if request.method == "GET":
                 method = s.get
@@ -513,16 +508,22 @@ class TalerReverseProxy(Flask):
             }
             for k, v in request.headers.items():
                 proxied_headers[k] = v
+
+            socket_path = f"{self.unix_sockets_dir}/{component}.sock"
+            self.logger.debug("Proxying to: " + socket_path + "/" + path)
+            uri = f"http+unix://{quote(socket_path, safe='')}/{path}"
+            if len(request.args) > 0:
+                uri += f"?{request.query_string.decode()}"
             resp = method(
                 uri,
                 headers=proxied_headers,
-                data=raw_data,
+                data=request.get_data(),
             )
         except Exception as error:
             self.logger.error(error)
             return "Could not connect to upstream", 500
-        self.logger.debug(f"Upstream responds: {resp.text}")
 
+        self.logger.debug(f"Upstream responds: {resp.text}")
         headers = Headers()
         for k in resp.headers.keys():
             # This version does not send chunked responses, so
@@ -549,9 +550,11 @@ def prepare():
 
     """Generate configuration, run-time blobs, instances, euFin accounts."""
 
-    def fail(reason=None):
+    def fail(reason=None, proxy_proc=None):
         if reason:
             print("ERROR: " + reason)
+        if proxy_proc:
+            print(f"Proxy logs in: {proxy_proc.get_log_filename()}")
         exit(1)
     
     def kill(proc):
@@ -570,23 +573,22 @@ def prepare():
         return env
     
     def get_sandbox_cli_env(
-        username, password, admin_token
+        username, password
     ):
        env = os.environ.copy()
        env["LIBEUFIN_SANDBOX_USERNAME"] = username
        env["LIBEUFIN_SANDBOX_PASSWORD"] = password
-       env["LIBEUFIN_SANDBOX_TOKEN"] = admin_token
        return env
 
     # Will be extended to include a SANDBOX_ADMIN_TOKEN
     # that will obsolete the 'superuser' flag of ordinary
     # user accounts.  Likewise, the client side will be
     # modified to use such token.
-    def get_sandbox_server_env(db_file, base_url, admin_token):
+    def get_sandbox_server_env(db_file, base_url, admin_password):
         env = os.environ.copy()
         env["LIBEUFIN_SANDBOX_DB_CONNECTION"] = f"jdbc:sqlite:{db_file}"
         env["LIBEUFIN_SANDBOX_BASE_URL"] = base_url
-        env["LIBEUFIN_SANDBOX_TOKEN"] = admin_token
+        env["LIBEUFIN_SANDBOX_ADMIN_PASSWORD"] = admin_password
         return env
 
     def get_nexus_server_env(db_file, base_url):
@@ -743,7 +745,6 @@ def prepare():
     EXCHANGE_NEXUS_PASSWORD = "exchange-nexus-password"
     FRONTENDS_API_TOKEN = "secret-token:secret"
     TALER_MERCHANT_TOKEN = "secret-token:secret"
-    LIBEUFIN_SANDBOX_TOKEN = "secret-token:secret"
 
     # Network locations
     REV_PROXY_NETLOC = "localhost:8080"
@@ -782,18 +783,23 @@ def prepare():
             self.log_dir = log_dir
 
         @staticmethod
-        def is_serving(check_url):
-            for i in range(10):
-                print_nn(".")
+        def is_serving(check_url, tries=10):
+            for i in range(tries):
                 try:
+                    print_nn(".")
                     # Raises if the service is not reachable.
-                    response = requests.get(check_url)
-                    # Raises if the request gets a non 200 OK.
+                    response = requests.get(
+                        check_url,
+                        timeout=1
+                    )
+                    # The reverse proxy may return 500 if the
+                    # end service is not ready, therefore this
+                    # case should be tolerated.
                     response.raise_for_status()
                 except:
-                    if i == 9:
-                        return False
                     time.sleep(0.5)
+                    if i == tries - 1:
+                        return False
                     continue
                 break
             return True
@@ -1085,7 +1091,7 @@ def prepare():
         obj.cfg_write(outdir)
         
     print_nn("Ensure no service is running...")
-    if Command.is_serving(REV_PROXY_URL + "/"):
+    if Command.is_serving(REV_PROXY_URL + "/", tries=3):
         fail("Reverse proxy is unexpectedly running!")
     if UNIX_SOCKETS_DIR.is_dir():
         for left_socket in os.listdir(UNIX_SOCKETS_DIR):
@@ -1196,7 +1202,10 @@ Logs: {rev_proxy.get_log_filename()}"
         "-c", CFG_OUTDIR / "taler.conf"
     ]).launch()
     if not Command.is_serving(REV_PROXY_URL + "/exchange/"):
-        fail(f"Exchange did not start correctly.  Logs: 
{exchange_handle.get_log_filename()}")
+        fail(
+            f"Exchange did not start correctly.  Logs: 
{exchange_handle.get_log_filename()}",
+            rev_proxy
+        )
     print(" OK")
     print_nn("exchange-offline: signing key material...")
     Command([
@@ -1266,11 +1275,14 @@ Logs: {rev_proxy.get_log_filename()}"
         env=get_sandbox_server_env(
             SANDBOX_DB_FILE,
             SANDBOX_URL,
-            LIBEUFIN_SANDBOX_TOKEN
+            SANDBOX_ADMIN_PASSWORD
         )
     ).launch()
     if not Command.is_serving(SANDBOX_URL):
-        fail(f"Sandbox did not start correctly.  Logs: 
{sandbox_handle.get_log_filename()}")
+        fail(
+            f"Sandbox did not start correctly.  Logs: 
{sandbox_handle.get_log_filename()}",
+            rev_proxy
+        )
     print(" OK")
     print_nn("Make Sandbox EBICS host...")
     Command(
@@ -1283,7 +1295,6 @@ Logs: {rev_proxy.get_log_filename()}"
         env=get_sandbox_cli_env(
             SANDBOX_ADMIN_USERNAME,
             SANDBOX_ADMIN_PASSWORD,
-            LIBEUFIN_SANDBOX_TOKEN
         ),
         custom_name="sandbox-create-ebicshost",
     ).run()
@@ -1302,7 +1313,6 @@ Logs: {rev_proxy.get_log_filename()}"
         env=get_sandbox_cli_env(
             SANDBOX_ADMIN_USERNAME,
             SANDBOX_ADMIN_PASSWORD,
-            LIBEUFIN_SANDBOX_TOKEN
         )
     )
     print(" OK")
@@ -1324,7 +1334,6 @@ Logs: {rev_proxy.get_log_filename()}"
             env=get_sandbox_cli_env(
                 SANDBOX_ADMIN_USERNAME,
                 SANDBOX_ADMIN_PASSWORD,
-                LIBEUFIN_SANDBOX_TOKEN
             )
         )
         print(" OK")
@@ -1341,7 +1350,6 @@ Logs: {rev_proxy.get_log_filename()}"
         env=get_sandbox_cli_env(
             SANDBOX_ADMIN_USERNAME,
             SANDBOX_ADMIN_PASSWORD,
-            LIBEUFIN_SANDBOX_TOKEN
         )
     )
     print(" OK")
@@ -1369,7 +1377,10 @@ Logs: {rev_proxy.get_log_filename()}"
         env=get_nexus_server_env(NEXUS_DB_FILE, NEXUS_URL)
     ).launch()
     if not Command.is_serving(NEXUS_URL):
-        fail(f"Nexus did not start correctly.  Logs: 
{nexus_handle.get_log_filename()}")
+        fail(
+            f"Nexus did not start correctly.  Logs: 
{nexus_handle.get_log_filename()}",
+            rev_proxy
+        )
     print(" OK")
 
     print_nn("Create Exchange account at Nexus...")
@@ -1417,7 +1428,7 @@ Logs: {rev_proxy.get_log_filename()}"
         )
         response.raise_for_status()
     except Exception as error:
-        fail(error)
+        fail(error, rev_proxy)
     FACADE_URL=response.json().get("facades")[0].get("baseUrl")
     
     print_nn("Terminating Nexus...")
@@ -1510,7 +1521,7 @@ Logs: {rev_proxy.get_log_filename()}"
         if resp.status_code < 200 or resp.status_code >= 300:
             print(f"Could not create (or patch) instance '{instance_id}'")
             print(f"Backend responds: {resp.status_code}/{resp.text}")
-            fail()
+            fail(proxy_proc=rev_proxy)
 
     print_nn(f"Start merchant (with TALER_MERCHANT_TOKEN into the env)...")
     auth_env = os.environ.copy()
@@ -1520,7 +1531,10 @@ Logs: {rev_proxy.get_log_filename()}"
         env=auth_env
     ).launch()
     if not Command.is_serving(REV_PROXY_URL + "/merchant-backend/config"):
-        fail(f"Merchant backend did not start correctly.  Logs: 
{merchant_handle.get_log_filename()}")
+        fail(
+            f"Merchant backend did not start correctly.  Logs: 
{merchant_handle.get_log_filename()}",
+            rev_proxy
+        )
     print(" OK")
 
     ensure_instance(
@@ -1540,7 +1554,10 @@ Logs: {rev_proxy.get_log_filename()}"
     merchant_handle.launch()
     if not Command.is_serving(REV_PROXY_URL + "/merchant-backend/config"):
         # check_running logs errors already.
-        fail(f"Merchant backend did not re start correctly.  Logs: 
{merchant_handle.get_log_filename()}")
+        fail(
+            f"Merchant backend did not re start correctly.  Logs: 
{merchant_handle.get_log_filename()}",
+            rev_proxy
+        )
     print(" OK")
 
     for instance_id, iban in INSTANCES.items():

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