# DEBUG: print("DEBUG: EXIT!")
-def fetch_instances(args: argparse.Namespace):
+def fetch_instances(args: argparse.Namespace) -> int:
# DEBUG: print(f"DEBUG: args[]='{type(args)}' - CALLED!")
locking.acquire()
except network.exceptions as exception:
print(f"WARNING: Exception '{type(exception)}' during fetching instances from args.domain='{args.domain}'")
instances.update_last_error(args.domain, exception)
- return
+ return 100
if args.single:
# DEBUG: print("DEBUG: Not fetching more instances - EXIT!")
- return
+ return 0
# Loop through some instances
fba.cursor.execute(
instances.update_last_error(row[0], exception)
# DEBUG: print("DEBUG: EXIT!")
+ return 0
def fetch_federater(args: argparse.Namespace):
# DEBUG: print(f"DEBUG: args[]='{type(args)}' - CALLED!")
headers = csrf.determine(domain, dict())
except network.exceptions as exception:
print(f"WARNING: Exception '{type(exception)}' during checking CSRF (nodeinfo,{__name__}) - EXIT!")
- return dict()
+ return {
+ "status_code" : 500,
+ "error_message": f"exception[{type(exception)}]='{str(exception)}'",
+ "exception" : exception,
+ }
request_paths = [
"/nodeinfo/2.1.json",
print(f"WARNING: Exception '{type(exception)}' during checking CSRF (fetch_wellknown,{__name__}) - EXIT!")
return {
"status_code" : 500,
- "error_message": type(exception)
+ "error_message": type(exception),
+ "exception" : exception,
}
# DEBUG: print("DEBUG: Fetching .well-known info for domain:", domain)
# DEBUG: print(f"DEBUG: data[{type(data)}]='{data}'")
if "error_message" in data:
- # DEBUG: print("DEBUG: Could not determine software type:", domain)
- return fetch_generator_from_path(domain)
+ # DEBUG: print(f"DEBUG: Could not determine software type, domain='{domain}'")
+ if "exception" in data:
+ raise Exception(f"Cannot fetch nodeinfo from domain='{domain}': '{data['error_message']}'") from data["exception"]
+ else:
+ raise Exception(f"Cannot fetch nodeinfo from domain='{domain}': '{data['error_message']}'")
# DEBUG: print("DEBUG: data():", len(data), data)
if "status" in data["json"] and data["json"]["status"] == "error" and "message" in data["json"]:
return
print(f"INFO: Adding instance domain='{domain}' (origin='{origin}',software='{software}')")
- try:
- fba.cursor.execute(
- "INSERT INTO instances (domain, origin, command, hash, software, first_seen) VALUES (?, ?, ?, ?, ?, ?)",
- (
- domain,
- origin,
- command,
- fba.get_hash(domain),
- software,
- time.time()
- ),
- )
-
- cache.set_sub_key("is_registered", domain, True)
-
- if has_pending_instance_data(domain):
- # DEBUG: print(f"DEBUG: domain='{domain}' has pending nodeinfo being updated ...")
- set_data("last_status_code" , domain, None)
- set_data("last_error_details", domain, None)
- update_data(domain)
-
- except BaseException as exception:
- update_last_error(domain, exception)
- raise Exception(f"ERROR: failed SQL query: domain='{domain}',exception[{type(exception)}]:'{str(exception)}'") from exception
- else:
- # DEBUG: print("DEBUG: Updating nodeinfo for domain:", domain)
- update_last_nodeinfo(domain)
+ fba.cursor.execute(
+ "INSERT INTO instances (domain, origin, command, hash, software, first_seen) VALUES (?, ?, ?, ?, ?, ?)",
+ (
+ domain,
+ origin,
+ command,
+ fba.get_hash(domain),
+ software,
+ time.time()
+ ),
+ )
+
+ cache.set_sub_key("is_registered", domain, True)
+
+ if has_pending_instance_data(domain):
+ # DEBUG: print(f"DEBUG: domain='{domain}' has pending nodeinfo being updated ...")
+ set_data("last_status_code" , domain, None)
+ set_data("last_error_details", domain, None)
+ update_data(domain)
+
+ # DEBUG: print(f"DEBUG: Updating nodeinfo for domain='{domain}'")
+ update_last_nodeinfo(domain)
# DEBUG: print("DEBUG: EXIT!")
# DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
if not cache.key_exists("is_registered"):
# DEBUG: print("DEBUG: Cache for 'is_registered' not initialized, fetching all rows ...")
- try:
- fba.cursor.execute("SELECT domain FROM instances")
-
- # Check Set all
- cache.set_all("is_registered", fba.cursor.fetchall(), True)
- except BaseException as exception:
- update_last_error(domain, exception)
- raise Exception(f"ERROR: failed SQL query: domain='{domain}',exception[{type(exception)}]:'{str(exception)}'") from exception
+ fba.cursor.execute("SELECT domain FROM instances")
+
+ # Check Set all
+ cache.set_all("is_registered", fba.cursor.fetchall(), True)
# Is cache found?
registered = cache.sub_key_exists("is_registered", domain)
# DEBUG: print(f"DEBUG: Fetching '{path}' from '{domain}' failed. exception[{type(exception)}]='{str(exception)}'")
json_reply["status_code"] = 999
json_reply["error_message"] = f"exception['{type(exception)}']='{str(exception)}'"
+ json_reply["exception"] = exception
instances.update_last_error(domain, exception)
raise exception
# DEBUG: print(f"DEBUG: Fetching '{url}' failed. exception[{type(exception)}]='{str(exception)}'")
json_reply["status_code"] = 999
json_reply["error_message"] = f"exception['{type(exception)}']='{str(exception)}'"
+ json_reply["exception"] = exception
raise exception
# DEBUG: print(f"DEBUG: Returning json_reply({len(json_reply)})=[]:{type(json_reply)}")
# DEBUG: print(f"DEBUG: Fetching '{path}' from '{domain}' failed. exception[{type(exception)}]='{str(exception)}'")
json_reply["status_code"] = 999
json_reply["error_message"] = f"exception['{type(exception)}']='{str(exception)}'"
+ json_reply["exception"] = exception
instances.update_last_error(domain, exception)
raise exception