]> git.mxchange.org Git - fba.git/blobdiff - fba/networks/misskey.py
Continued:
[fba.git] / fba / networks / misskey.py
index 4227b2c9729e89478c9aa43e57b83cad2965f0a8..045b5061c807fa4547802e26edcef8243e4b31b5 100644 (file)
 import json
 import logging
 
-from fba import csrf
-
 from fba.helpers import config
 from fba.helpers import dicts as dict_helper
 from fba.helpers import domain as domain_helper
 from fba.helpers import tidyup
 
+from fba.http import csrf
 from fba.http import network
 
 from fba.models import instances
@@ -106,12 +105,12 @@ def fetch_peers(domain: str) -> list:
             elif not isinstance(row["host"], str):
                 logger.warning("row[host][]='%s' is not of type 'str' - SKIPPED!", type(row['host']))
                 continue
-            elif not domain_helper.is_wanted(row["host"]):
-                logger.debug("row[host]='%s' is not wanted, domain='%s' - SKIPPED!", row['host'], domain)
-                continue
             elif row["host"] in peers:
                 logger.debug("Not adding row[host]='%s', already found - SKIPPED!", row['host'])
                 continue
+            elif not domain_helper.is_wanted(row["host"]):
+                logger.debug("row[host]='%s' is not wanted - SKIPPED!", row["host"])
+                continue
 
             logger.debug("Adding peer: row[host]='%s'", row['host'])
             added = added + 1
@@ -129,6 +128,9 @@ def fetch_blocks(domain: str) -> list:
     logger.debug("domain='%s' - CALLED!", domain)
     domain_helper.raise_on(domain)
 
+    if not instances.is_registered(domain):
+        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()
 
@@ -197,8 +199,24 @@ def fetch_blocks(domain: str) -> list:
             for instance in rows:
                 # Is it there?
                 logger.debug("instance[]='%s'", type(instance))
+                if "host" not in instance:
+                    logger.warning("instance(%d)='%s' has no key 'host' - SKIPPED!", len(instance), instance)
+                    continue
+                elif instance["host"] is None or instance["host"] == "":
+                    logger.debug("instance[host]='%s' is None or empty - SKIPPED!", instance["host"])
+                    continue
+
+                logger.debug("instance[host]='%s' - BEFORE!", instance["host"])
                 blocked = tidyup.domain(instance["host"])
-                if "isSuspended" in instance and instance["isSuspended"] and not dict_helper.has_key(blocklist, "blocked", blocked):
+
+                logger.debug("blocked[%s]='%s' - AFTER!", type(blocked), blocked)
+                if blocked is None or blocked == "":
+                    logger.warning("instance[host]='%s' is None or empty after tidyup.domain() - SKIPPED!", instance["host"])
+                    continue
+                elif not domain_helper.is_wanted(blocked):
+                    logger.debug("blocked='%s' is not wanted - SKIPPED!", blocked)
+                    continue
+                elif "isSuspended" in instance and instance["isSuspended"] and not dict_helper.has_key(blocklist, "blocked", blocked):
                     count = count + 1
                     logger.debug("Appending blocker='%s',blocked='%s',block_level='suspended'", domain, blocked)
                     blocklist.append({
@@ -268,7 +286,15 @@ def fetch_blocks(domain: str) -> list:
                 # Is it there?
                 logger.debug("instance[]='%s'", type(instance))
                 blocked = tidyup.domain(instance["host"])
-                if "isBlocked" in instance and instance["isBlocked"] and not dict_helper.has_key(blocklist, "blocked", blocked):
+
+                logger.debug("blocked='%s'", blocked)
+                if blocked is None or blocked == "":
+                    logger.warning("instance[host]='%s' is None or empty after tidyup.domain() - SKIPPED!", instance["host"])
+                    continue
+                elif not domain_helper.is_wanted(blocked):
+                    logger.debug("blocked='%s' is not wanted - SKIPPED!", blocked)
+                    continue
+                elif "isBlocked" in instance and instance["isBlocked"] and not dict_helper.has_key(blocklist, "blocked", blocked):
                     count = count + 1
                     logger.debug("Appending blocker='%s',blocked='%s',block_level='reject'", domain, blocked)
                     blocklist.append({