taler-deployment

Deployment scripts and configuration files
Log | Files | Refs | README

commit 0add7c44dc9f24b2b05f80706d331fdff085b8af
parent 63ca16886ea5ffe9d0630dc35bcf228b5d4ab468
Author: MS <ms@taler.net>
Date:   Fri, 28 May 2021 22:07:22 +0200

change instance PATCH logic

Diffstat:
Mbin/taler-deployment-config-instances | 39++++++++++++++++++++++-----------------
1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/bin/taler-deployment-config-instances b/bin/taler-deployment-config-instances @@ -61,6 +61,25 @@ TALER_ENV_FRONTENDS_APITOKEN = expect_env("TALER_ENV_FRONTENDS_APITOKEN") authorization_header = {"Authorization": f"Bearer {TALER_ENV_FRONTENDS_APITOKEN}"} def ensure_instance(instance_id, name, payto_uris, auth): + + resp = requests.get(urljoin(MERCHANT_BACKEND_BASE_URL, f"private/instances/{instance_id}")) + + # Instance exists, we PATCH the auth just in case it changed. + if resp.status_code == 200: + if instance_id != "Tutorial": + print(f"Patching (auth of) instance '{instance_id}'") + patch_resp = requests.post( + urljoin(MERCHANT_BACKEND_BASE_URL, + f"private/instances/{instance_id}/auth"), + json=auth, + headers = authorization_header + ) + if patch_resp.status_code < 200 or patch_resp.status_code >= 300: + print(f"Failed to update auth of '{instance_id}', backend responds: {patch_resp.status_code}/{patch_resp.text}") + exit(1) + return + + print(f"Instance '{instance_id}' not found, trying to create it.") req = dict( id=instance_id, name=name, @@ -72,31 +91,17 @@ def ensure_instance(instance_id, name, payto_uris, auth): default_max_deposit_fee=f"{TALER_CONFIG_CURRENCY}:1", default_wire_transfer_delay=dict(d_ms="forever"), default_pay_delay=dict(d_ms="forever"), - # FIXME: Eventually, this should be an actual secret token auth=auth, ) - # Here authenticates as 'default' (with same credentials of other instances.) create_resp = requests.post( urljoin(MERCHANT_BACKEND_BASE_URL, "private/instances"), json=req, headers = authorization_header ) - print(f"POSTing to /private/instances for '{instance_id}', responded with: {create_resp.status_code}") if create_resp.status_code < 200 or create_resp.status_code >= 300: - print(f"Instance '{instance_id}' could not be (re)created, backend says: {create_resp.text}. Updating its auth now") - if instance_id != "Tutorial": - patch_resp = requests.post( - urljoin(MERCHANT_BACKEND_BASE_URL, - f"private/instances/{instance_id}/auth"), - json=auth, - headers = authorization_header - ) - if patch_resp.status_code < 200 or patch_resp.status_code >= 300: - print(f"Failed to update auth of '{instance_id}'") - print(patch_resp.text) - exit(1) - else: - exit(1) + print(f"Could not create instance '{instance_id}', backend responds: {create_resp.status_code}/{create_resp.text}") + exit(1) + def is_merchant_running(): for proc in psutil.process_iter():