From 53577d64abca7b769fa64bc00de41571cfd1d8e5 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Tue, 28 Feb 2023 12:27:27 +0100 Subject: [PATCH] improvements --- app/util.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/util.py b/app/util.py index 1b66999..90bd9ad 100644 --- a/app/util.py +++ b/app/util.py @@ -28,10 +28,14 @@ def generate_key() -> "RsaKey": return RSA.generate(bits=2048) -def ha_replicate(logger: "logging.Logger", ha_replicate: str, ha_role: str, version: str, dls_url: str, dls_port: int, site_key_xid: str, instance_ref: str, origins: list["Origin"], leases: list["Lease"]): +def ha_replicate(logger: "logging.Logger", ha_replicate: str, ha_role: str, version: str, dls_url: str, dls_port: int, site_key_xid: str, instance_ref: str, origins: list["Origin"], leases: list["Lease"]) -> bool: from datetime import datetime import httpx + if f'{dls_url}:{dls_port}' == ha_replicate: + logger.error(f'Failed to replicate this node ({ha_role}) to "{ha_replicate}": can\'t replicate to itself') + return False + data = { 'VERSION': str(version), 'HA_REPLICATE': f'{dls_url}:{dls_port}', @@ -45,6 +49,6 @@ def ha_replicate(logger: "logging.Logger", ha_replicate: str, ha_role: str, vers r = httpx.put(f'https://{ha_replicate}/-/ha/replicate', json=data, verify=False) if r.status_code == 202: logger.info(f'Successfully replicated this node ({ha_role}) to "{ha_replicate}".') - else: - logger.error(f'Failed to replicate this node ({ha_role}) to "{ha_replicate}": {r.status_code} - {r.content}') - + return True + logger.error(f'Failed to replicate this node ({ha_role}) to "{ha_replicate}": {r.status_code} - {r.content}') + return False