From 65ee940b8a4d304af6953cd1c016ff4ec7d1d822 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 7 Dec 2024 06:24:02 +0100 Subject: [PATCH] Continued: - full-stop (dot) no longer at end of exception messages - added column last_requested_path to 'instances' table --- blocks_empty.db | Bin 57344 -> 57344 bytes fba/helpers/blacklist.py | 1 + fba/http/csrf.py | 2 +- fba/http/federation.py | 2 +- fba/http/network.py | 7 +++++-- fba/models/instances.py | 19 ++++++++++++++++++- fba/networks/friendica.py | 4 ++-- fba/networks/lemmy.py | 10 +++++----- fba/networks/mastodon.py | 8 ++++---- fba/networks/misskey.py | 8 ++++---- fba/networks/peertube.py | 4 ++-- fba/networks/pleroma.py | 8 ++++---- templates/views/infos.html | 5 +++++ 13 files changed, 52 insertions(+), 26 deletions(-) diff --git a/blocks_empty.db b/blocks_empty.db index d36e78c6ff3fbe6ae1adbc06c57b9d8fcc2895cd..716df9923b70e41700066e566a0d6922a9c412ed 100644 GIT binary patch delta 146 zcmZoTz}#?vd4jYcKLY~;9}sf`F%uBSPt-A%*ZJE?dFSO z@!eQ)m6@xph>cxbUY@bnc=KIOeP$VjoW$ai_@dOp($wOT)Rg#w#F7k!5Kq6z5Z8#w vR(uMZ53&0(vT$Bz=$SaNWAYqMa~A#p=Aexe{g{~yIVQ*O$!vD!-FpcDWBMj) delta 119 zcmZoTz}#?vd4jYc4+8@O9}sf`F%uBSOw=)! dict: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not isinstance(headers, dict): raise ValueError(f"Parameter headers[]='{type(headers)}' is not of type 'dict'") diff --git a/fba/http/federation.py b/fba/http/federation.py index 66145a3..9cddbc2 100644 --- a/fba/http/federation.py +++ b/fba/http/federation.py @@ -621,7 +621,7 @@ def fetch_blocks(domain: str) -> list: if blacklist.is_blacklisted(domain): raise Exception(f"domain='{domain}' is blacklisted but function was invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") # Init block list blocklist = list() diff --git a/fba/http/network.py b/fba/http/network.py index ec020c3..227e76f 100644 --- a/fba/http/network.py +++ b/fba/http/network.py @@ -99,6 +99,7 @@ def post_json_api(domain: str, path: str, data: str = "", headers: dict = dict() response_time = time.perf_counter() - start logger.debug("response_time=%s", response_time) + instances.set_last_requested_path(domain, path) instances.set_last_response_time(domain, response_time) logger.debug("response.ok='%s',response.status_code=%d,response.reason='%s',response_time=%s", response.ok, response.status_code, response.reason, response_time) @@ -306,7 +307,8 @@ def fetch_response(domain: str, path: str, headers: dict, timeout: tuple, allow_ allow_redirects=allow_redirects ) response_time = time.perf_counter() - start - logger.debug("Setting response_time=%s for domain='%s' ...", response_time, domain) + logger.debug("Setting response_time=%s,path='%s' for domain='%s' ...", response_time, path, domain) + instances.set_last_requested_path(domain, path) instances.set_last_response_time(domain, response_time) logger.debug("response.ok='%s',response.status_code=%d,response.reason='%s',response_time=%s", response.ok, response.status_code, response.reason, response_time) @@ -315,7 +317,8 @@ def fetch_response(domain: str, path: str, headers: dict, timeout: tuple, allow_ instances.set_last_error(domain, exception) response_time = time.perf_counter() - start - logger.debug("Setting response_time=%s for domain='%s' ...", response_time, domain) + logger.debug("Setting response_time=%s,path='%s' for domain='%s' ...", response_time, path, domain) + instances.set_last_requested_path(domain, path) instances.set_last_response_time(domain, response_time) raise exception diff --git a/fba/models/instances.py b/fba/models/instances.py index 7de40c6..9c0c1ba 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -64,6 +64,8 @@ _pending = { "last_nodeinfo" : {}, # Last response time "last_response_time" : {}, + # Last requested path + "last_requested_path": {}, # Last status code "last_status_code" : {}, # Last error details @@ -101,7 +103,7 @@ def has_pending(domain: str) -> bool: domain_helper.raise_on(domain) if not is_registered(domain): - raise ValueError(f"domain='{domain}' is not registered but function was invoked.") + raise ValueError(f"domain='{domain}' is not registered but function was invoked") elif blacklist.is_blacklisted(domain): raise Exception(f"domain='{domain}' is blacklisted but function has been invoked") @@ -442,6 +444,21 @@ def set_last_response_time(domain: str, response_time: float) -> None: _set_data("last_response_time", domain, response_time) logger.debug("EXIT!") +def set_last_requested_path(domain: str, path: float) -> None: + logger.debug("domain='%s',path=%d - CALLED!", domain, path) + domain_helper.raise_on(domain) + + if not isinstance(path, str): + raise ValueError(f"path[]='{type(path)}' is not of type 'str'") + elif path == "": + raise ValueError(f"path='{path}' is an empty string") + elif not path.startswith("/"): + raise ValueError(f"path='{path}' does not start with '/'") + + # Set timestamp + _set_data("last_requested_path", domain, path) + logger.debug("EXIT!") + def set_total_peers(domain: str, peers: list) -> None: logger.debug("domain='%s',peers()=%d - CALLED!", domain, len(peers)) domain_helper.raise_on(domain) diff --git a/fba/networks/friendica.py b/fba/networks/friendica.py index 47a2475..abcda4c 100644 --- a/fba/networks/friendica.py +++ b/fba/networks/friendica.py @@ -36,9 +36,9 @@ def fetch_blocks(domain: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") blocklist = list() block_tag = None diff --git a/fba/networks/lemmy.py b/fba/networks/lemmy.py index c97932f..785e5b7 100644 --- a/fba/networks/lemmy.py +++ b/fba/networks/lemmy.py @@ -73,9 +73,9 @@ def fetch_peers(domain: str, origin: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") peers = list() @@ -131,9 +131,9 @@ def fetch_blocks(domain: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") blocklist = list() @@ -244,7 +244,7 @@ def fetch_instances(domain: str, origin: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") peers = list() diff --git a/fba/networks/mastodon.py b/fba/networks/mastodon.py index 4f2af7b..dddc7dd 100644 --- a/fba/networks/mastodon.py +++ b/fba/networks/mastodon.py @@ -65,9 +65,9 @@ def fetch_blocks_from_about(domain: str) -> dict: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") # Init variables doc = None @@ -162,9 +162,9 @@ def fetch_blocks(domain: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") # Init variables blocklist = list() diff --git a/fba/networks/misskey.py b/fba/networks/misskey.py index cf8849d..dcaf1d5 100644 --- a/fba/networks/misskey.py +++ b/fba/networks/misskey.py @@ -36,9 +36,9 @@ def fetch_peers(domain: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") logger.debug("domain='%s' is misskey, sending API POST request ...", domain) peers = list() @@ -135,9 +135,9 @@ def fetch_blocks(domain: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") # No CSRF by default, you don't have to add network.api_headers by yourself here headers = tuple() diff --git a/fba/networks/peertube.py b/fba/networks/peertube.py index 80437a1..63123b3 100644 --- a/fba/networks/peertube.py +++ b/fba/networks/peertube.py @@ -33,9 +33,9 @@ def fetch_peers(domain: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") # Init variables peers = list() diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index c3d6322..ba6f5e4 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -57,9 +57,9 @@ def fetch_blocks(domain: str) -> list: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") # Init variables blockdict = list() @@ -288,9 +288,9 @@ def fetch_blocks_from_about(domain: str) -> dict: domain_helper.raise_on(domain) if blacklist.is_blacklisted(domain): - raise Exception(f"domain='{domain}' is blacklisted but function is invoked.") + raise Exception(f"domain='{domain}' is blacklisted but function is invoked") elif not instances.is_registered(domain): - raise Exception(f"domain='{domain}' is not registered but function is invoked.") + raise Exception(f"domain='{domain}' is not registered but function is invoked") # Init variables doc = None diff --git a/templates/views/infos.html b/templates/views/infos.html index 776c6f5..91c7d16 100644 --- a/templates/views/infos.html +++ b/templates/views/infos.html @@ -96,6 +96,11 @@ {{'%0.2f'|format(instance['last_response_time']|float)}} + + Last requested path: + {% if instance['last_requested_path']%}{{instance['last_requested_path']}}{%else%}-{%endif%} + + Obfuscated blocks: {{instance['obfuscated_blocks']}} -- 2.39.5