import json
import logging
+from fba.helpers import blacklist
from fba.helpers import config
from fba.helpers import dicts as dict_helper
from fba.helpers import domain as domain_helper
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
+ if blacklist.is_blacklisted(domain):
+ 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.")
+
logger.debug("domain='%s' is misskey, sending API POST request ...", domain)
peers = list()
offset = 0
instances.set_last_error(domain, fetched)
break
elif isinstance(fetched["json"], dict) and "error" in fetched["json"] and "message" in fetched["json"]["error"]:
- logger.warning("post_json_api() returned error: '%s'", fetched['error']['message'])
+ logger.warning("post_json_api() returned error: '%s'", fetched["json"]["error"]["message"])
instances.set_last_error(domain, fetched["json"]["error"]["message"])
break
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
- if not instances.is_registered(domain):
+ if blacklist.is_blacklisted(domain):
+ 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.")
# No CSRF by default, you don't have to add network.api_headers by yourself here
headers = tuple()
try:
- logger.debug("Checking CSRF for domain='%s'", domain)
+ logger.debug("Checking CSRF for domain='%s' ...", domain)
headers = csrf.determine(domain, dict())
except network.exceptions as exception:
logger.warning("Exception '%s' during checking CSRF (fetch_blocks,%s)", type(exception), __name__)
# instances page-by-page since it doesn't support sending them all at once
logger.debug("Fetching misskey blocks from domain='%s'", domain)
while True:
+ logger.debug("offset=%d", offset)
try:
logger.debug("Fetching offset=%d from domain='%s' ...", offset, domain)
if offset == 0:
instances.set_last_error(domain, fetched)
break
elif isinstance(fetched["json"], dict) and "error" in fetched["json"] and "message" in fetched["json"]["error"]:
- logger.warning("post_json_api() returned error: '%s'", fetched['error']['message'])
+ logger.warning("post_json_api() returned error: '%s'", fetched["json"]["error"]["message"])
instances.set_last_error(domain, fetched["json"]["error"]["message"])
break
offset = offset + step
count = 0
+ logger.debug("Checking %d row(s) of instances ...", len(rows))
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"] == "":
+ elif instance["host"] in [None, ""]:
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"])
-
logger.debug("blocked[%s]='%s' - AFTER!", type(blocked), blocked)
- if blocked is None or blocked == "":
+
+ if blocked in [None, ""]:
logger.warning("instance[host]='%s' is None or empty after tidyup.domain() - SKIPPED!", instance["host"])
continue
elif not domain_helper.is_wanted(blocked):
while True:
# Fetch blocked (full suspended) instances
+ logger.debug("offset=%d", offset)
try:
if offset == 0:
logger.debug("Sending JSON API request to domain='%s',step=%d,offset=%d", domain, step, offset)
instances.set_last_error(domain, fetched)
break
elif isinstance(fetched["json"], dict) and "error" in fetched["json"] and "message" in fetched["json"]["error"]:
- logger.warning("post_json_api() returned error: '%s'", fetched['error']['message'])
+ logger.warning("post_json_api() returned error: '%s'", fetched["json"]["error"]["message"])
instances.set_last_error(domain, fetched["json"]["error"]["message"])
break
offset = offset + step
count = 0
+ logger.debug("Checking %d row(s) of instances ...", len(rows))
for instance in rows:
# Is it there?
logger.debug("instance[]='%s'", type(instance))
- blocked = tidyup.domain(instance["host"])
+ blocked = tidyup.domain(instance["host"]) if instance["host"] != "" else None
+ logger.debug("blocked='%s' - AFTER!", blocked)
- logger.debug("blocked='%s'", blocked)
- if blocked is None or blocked == "":
+ if blocked in [None, ""]:
logger.warning("instance[host]='%s' is None or empty after tidyup.domain() - SKIPPED!", instance["host"])
continue
elif not domain_helper.is_wanted(blocked):