From 70af0c908976368fe79c6454a1829660170f7b01 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Jun 2023 15:06:26 +0200 Subject: [PATCH] Continued: - introduced cookies.clear() to clear cookies for given domain --- fba/commands.py | 27 +++++++++++++++++++++++++++ fba/fba.py | 3 +++ fba/helpers/cookies.py | 13 +++++++++++++ 3 files changed, 43 insertions(+) diff --git a/fba/commands.py b/fba/commands.py index fb83824..f10fb56 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -121,6 +121,9 @@ def fetch_bkali(args: argparse.Namespace) -> int: try: print(f"INFO: Fetching instances from domain='{domain}' ...") federation.fetch_instances(domain, None, None, inspect.currentframe().f_code.co_name) + + # DEBUG: print(f"DEBUG: Invoking cookies.clear({domain}) ...") + cookies.clear(domain) except network.exceptions as exception: print(f"WARNING: Exception '{type(exception)}' during fetching instances (fetch_bkali) from domain='{domain}'") instances.set_last_error(domain, exception) @@ -271,6 +274,9 @@ def fetch_blocks(args: argparse.Namespace): blocks.update_last_seen(blocker, blocked, block_level) blocks.update_reason(reason, blocker, blocked, block_level) + # DEBUG: print(f"DEBUG: Invoking cookies.clear({blocked}) ...") + cookies.clear(blocked) + # DEBUG: print("DEBUG: Committing changes ...") fba.connection.commit() else: @@ -283,6 +289,9 @@ def fetch_blocks(args: argparse.Namespace): if config.get("bot_enabled") and len(blockdict) > 0: network.send_bot_post(blocker, blockdict) + # DEBUG: print(f"DEBUG: Invoking cookies.clear({blocker}) ...") + cookies.clear(blocker) + # DEBUG: print("DEBUG: EXIT!") def fetch_observer(args: argparse.Namespace): @@ -357,6 +366,9 @@ def fetch_observer(args: argparse.Namespace): print(f"INFO: Fetching instances for domain='{domain}',software='{software}'") federation.fetch_instances(domain, None, None, inspect.currentframe().f_code.co_name) + # DEBUG: print(f"DEBUG: Invoking cookies.clear({domain}) ...") + cookies.clear(domain) + # DEBUG: print("DEBUG: EXIT!") def fetch_cs(args: argparse.Namespace): @@ -418,6 +430,9 @@ def fetch_cs(args: argparse.Namespace): try: print(f"INFO: Fetching instances from domain='{row['domain']}' ...") federation.fetch_instances(row["domain"], 'chaos.social', None, inspect.currentframe().f_code.co_name) + + # DEBUG: print(f"DEBUG: Invoking cookies.clear({row['domain']}) ...") + cookies.clear(row["domain"]) except network.exceptions as exception: print(f"WARNING: Exception '{type(exception)}' during fetching instances (fetch_cs) from domain='{row['domain']}'") instances.set_last_error(row["domain"], exception) @@ -466,6 +481,9 @@ def fetch_fba_rss(args: argparse.Namespace): try: print(f"INFO: Fetching instances from domain='{domain}' ...") federation.fetch_instances(domain, None, None, inspect.currentframe().f_code.co_name) + + # DEBUG: print(f"DEBUG: Invoking cookies.clear({domain}) ...") + cookies.clear(domain) except network.exceptions as exception: print(f"WARNING: Exception '{type(exception)}' during fetching instances (fetch_fba_rss) from domain='{domain}'") instances.set_last_error(domain, exception) @@ -519,6 +537,9 @@ def fetch_fbabot_atom(args: argparse.Namespace): try: print(f"INFO: Fetching instances from domain='{domain}' ...") federation.fetch_instances(domain, None, None, inspect.currentframe().f_code.co_name) + + # DEBUG: print(f"DEBUG: Invoking cookies.clear({domain}) ...") + cookies.clear(domain) except network.exceptions as exception: print(f"WARNING: Exception '{type(exception)}' during fetching instances (fetch_fbabot_atom) from domain='{domain}'") instances.set_last_error(domain, exception) @@ -533,6 +554,9 @@ def fetch_instances(args: argparse.Namespace) -> int: try: print(f"INFO: Fetching instances from args.domain='{args.domain}' ...") federation.fetch_instances(args.domain, None, None, inspect.currentframe().f_code.co_name) + + # DEBUG: print(f"DEBUG: Invoking cookies.clear({args.domain}) ...") + cookies.clear(args.domain) except network.exceptions as exception: print(f"WARNING: Exception '{type(exception)}' during fetching instances (fetch_instances) from args.domain='{args.domain}'") instances.set_last_error(args.domain, exception) @@ -559,6 +583,9 @@ def fetch_instances(args: argparse.Namespace) -> int: try: print(f"INFO: Fetching instances for instance '{row[0]}' ('{row[2]}') of origin='{row[1]}',nodeinfo_url='{row[3]}'") federation.fetch_instances(row[0], row[1], row[2], inspect.currentframe().f_code.co_name, row[3]) + + # DEBUG: print(f"DEBUG: Invoking cookies.clear({row[0]}) ...") + cookies.clear(row[0]) except network.exceptions as exception: print(f"WARNING: Exception '{type(exception)}' during fetching instances (fetch_instances) from domain='{row[0]}'") instances.set_last_error(row[0], exception) diff --git a/fba/fba.py b/fba/fba.py index 8e3c0c0..335028c 100644 --- a/fba/fba.py +++ b/fba/fba.py @@ -126,6 +126,9 @@ def process_domain(domain: str, blocker: str, command: str) -> bool: print(f"INFO: Fetching instances for instane='{domain}',blocker='{blocker}',command='{command}' ...") federation.fetch_instances(domain, blocker, None, command) processed = True + + # DEBUG: print(f"DEBUG: Invoking cookies.clear({domain}) ...") + cookies.clear(domain) except network.exceptions as exception: print(f"WARNING: Exception '{type(exception)}' during fetching instances (fetch_oliphant) from domain='{domain}'") instances.set_last_error(domain, exception) diff --git a/fba/helpers/cookies.py b/fba/helpers/cookies.py index 5a35602..2ed3f1d 100644 --- a/fba/helpers/cookies.py +++ b/fba/helpers/cookies.py @@ -53,3 +53,16 @@ def has (domain: str) -> bool: # DEBUG: print(f"DEBUG: has_cookies='{has_cookies}' - EXIT!") return has_cookies + +def clear (domain: str): + # DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!") + if not isinstance(domain, str): + raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'") + elif domain == "": + raise ValueError("Parameter 'domain' is empty") + + if has(domain): + # DEBUG: print(f"DEBUG: Removing cookies for domain='{domain}' ...") + del _cookies[domain] + + # DEBUG: print(f"DEBUG: EXIT!") -- 2.39.5