import json
import logging
-from fba import csrf
-from fba import utils
-
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
rows = fetched["json"]
- logger.debug("rows(%d)[]='%s'", len(rows), type(rows))
+ logger.debug("rows(%d)[]='%s',step=%d", len(rows), type(rows), step)
if len(rows) == 0:
logger.debug("Returned zero bytes, domain='%s' - BREAK!", domain)
break
logger.debug("Raising offset by step=%d", step)
offset = offset + step
- already = 0
+ added = 0
logger.debug("rows(%d))[]='%s'", len(rows), type(rows))
for row in rows:
logger.debug("row()=%d", len(row))
elif not isinstance(row["host"], str):
logger.warning("row[host][]='%s' is not of type 'str' - SKIPPED!", type(row['host']))
continue
- elif not utils.is_domain_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'])
- already = already + 1
+ 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
peers.append(row["host"])
- if already == len(rows):
- logger.debug("Host returned same set of %d instance(s) - BREAK!", already)
+ logger.debug("added=%d,rows()=%d", added, len(rows))
+ if added == 0:
+ logger.debug("Host returned already added (%d) peers - BREAK!", len(rows))
break
logger.debug("peers()=%d - EXIT!", len(peers))
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()
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({
# 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({