From: Roland Häder Date: Tue, 13 Jun 2023 09:19:23 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e443c5e1dabc88949a2599d16534b112952b8d8a;p=fba.git Continued: - added 'software' as optional parameter to instances.add() - also prevent bad invocations when a link to a user profile has provided --- diff --git a/fba/federation.py b/fba/federation.py index 118c45d..941b192 100644 --- a/fba/federation.py +++ b/fba/federation.py @@ -69,7 +69,9 @@ def fetch_instances(domain: str, origin: str, software: str, command: str, path: elif domain.endswith(".arpa"): print(f"WARNING: domain='{domain}' is a reversed .arpa domain and should not be used generally.") return - elif not instances.is_registered(domain): + elif not validators.domain(domain): + raise ValueError(f"domain='{domain}' is not a valid domain") + elif not instances.is_registered(domain.split("/")[0]): # DEBUG: print("DEBUG: Adding new domain:", domain, origin) instances.add(domain, origin, command, path) @@ -114,6 +116,9 @@ def fetch_instances(domain: str, origin: str, software: str, command: str, path: if instance.endswith(".arpa"): print(f"WARNING: instance='{instance}' is a reversed .arpa domain and should not be used generally.") continue + elif instance.find("/profile/") > 0 or instance.find("/users/") > 0: + print(f"DEBUG: instance='{instance}' is a link to a single user profile - SKIPPED!") + continue elif not instances.is_registered(instance): # DEBUG: print("DEBUG: Adding new instance:", instance, domain) instances.add(instance, domain, command) diff --git a/fba/models/instances.py b/fba/models/instances.py index 91c4722..154dbfa 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -146,8 +146,8 @@ def update_data(domain: str): # DEBUG: print("DEBUG: EXIT!") -def add(domain: str, origin: str, command: str, path: str = None): - # DEBUG: print(f"DEBUG: domain='{domain}',origin='{origin}',command='{command}',path='{path}' - CALLED!") +def add(domain: str, origin: str, command: str, path: str = None, software: str = None): + # DEBUG: print(f"DEBUG: domain='{domain}',origin='{origin}',command='{command}',path='{path}',software='{software}' - CALLED!") if not isinstance(domain, str): raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'") elif domain == "": @@ -162,21 +162,29 @@ def add(domain: str, origin: str, command: str, path: str = None): raise ValueError("Parameter 'command' is empty") elif not validators.domain(domain.split("/")[0]): raise ValueError(f"Bad domain name='{domain}'") + elif not isinstance(path, str) and path is not None: + raise ValueError(f"path[]='{type(path)}' is not 'str'") + elif path == "": + raise ValueError("Parameter 'path' is empty") + elif not isinstance(software, str) and software is not None: + raise ValueError(f"software[]='{type(software)}' is not 'str'") + elif software == "": + raise ValueError("Parameter 'software' is empty") elif domain.endswith(".arpa"): raise ValueError(f"Please don't crawl .arpa domains: domain='{domain}'") elif origin is not None and not validators.domain(origin.split("/")[0]): raise ValueError(f"Bad origin name='{origin}'") elif blacklist.is_blacklisted(domain): raise Exception(f"domain='{domain}' is blacklisted, but method invoked") - elif domain.find("/profile/") > 0 or domain.find("/users/") > 0: + elif domain.find("/profile/") > 0 or domain.find("/users/") > 0 or (software == "lemmy" and domain.find("/c/") > 0): raise Exception(f"domain='{domain}' is a single user") - software = None - try: - # DEBUG: print("DEBUG: domain,origin,command,path:", domain, origin, command, path) - software = federation.determine_software(domain, path) - except network.exceptions as exception: - print(f"WARNING Exception '{type(exception)}' during determining software type") + if isinstance(software, str): + try: + # DEBUG: print("DEBUG: domain,origin,command,path:", domain, origin, command, path) + software = federation.determine_software(domain, path) + except network.exceptions as exception: + print(f"WARNING Exception '{type(exception)}' during determining software type") # DEBUG: print("DEBUG: Determined software:", software) if software == "lemmy" and domain.find("/c/") > 0: