]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Mon, 3 Jul 2023 21:30:15 +0000 (23:30 +0200)
committerRoland Häder <roland@mxchange.org>
Mon, 3 Jul 2023 21:30:15 +0000 (23:30 +0200)
- rewrote a bit to get lesser nested blocks
- "href" might not be set while "rel" is set ... to much broken
  /.well-known/nodeinfo replies!

fba/http/federation.py

index 07cbe0ab547bbd961d5351330d0f8aee652ec42b..4508bf77b196820abd05b41d7aff602105cbd2e7 100644 (file)
@@ -334,45 +334,52 @@ def fetch_wellknown_nodeinfo(domain: str) -> dict:
                 for link in nodeinfo["links"]:
                     logger.debug("link[%s]='%s'", type(link), link)
                     if not isinstance(link, dict) or not "rel" in link:
                 for link in nodeinfo["links"]:
                     logger.debug("link[%s]='%s'", type(link), link)
                     if not isinstance(link, dict) or not "rel" in link:
-                        logger.warning("link[]='%s' is not 'dict' or no element 'rel' found", type(link))
-                    elif link["rel"] == niid:
-                        # Default is that 'href' has a complete URL, but some hosts don't send that
-                        logger.debug("link[href]='%s' matches niid='%s'", link["href"], niid)
-                        url = link["href"]
-                        components = urlparse(link["href"])
-
-                        logger.debug("components[%s]='%s'", type(components), components)
-                        if components.scheme == "" and components.netloc == "":
-                            logger.warning("link[href]='%s' has no scheme and host name in it, prepending from domain='%s'", link['href'], domain)
-                            url = f"https://{domain}{url}"
-                            components = urlparse(url)
-                        elif components.netloc == "":
-                            logger.warning("link[href]='%s' has no netloc set, setting domain='%s'", link["href"], domain)
-                            url = f"{components.scheme}://{domain}{components.path}"
-                            components = urlparse(url)
-
-                        if not utils.is_domain_wanted(components.netloc):
-                            logger.debug("components.netloc='%s' is not wanted - SKIPPED!", components.netloc)
-                            continue
-
-                        logger.debug("Fetching nodeinfo from url='%s' ...", url)
-                        data = network.fetch_api_url(
-                            url,
-                            (config.get("connection_timeout"), config.get("read_timeout"))
-                         )
-
-                        logger.debug("link[href]='%s',data[]='%s'", link["href"], type(data))
-                        if "error_message" not in data and "json" in data:
-                            logger.debug("Found JSON data()=%d,link[href]='%s' - Setting detection_mode=AUTO_DISCOVERY ...", len(data), link["href"])
-                            instances.set_detection_mode(domain, "AUTO_DISCOVERY")
-                            instances.set_nodeinfo_url(domain, link["href"])
-
-                            logger.debug("Marking domain='%s' as successfully handled ...", domain)
-                            instances.set_success(domain)
-                            break
-                        else:
-                            logger.debug("Setting last error for domain='%s',data[]='%s'", domain, type(data))
-                            instances.set_last_error(domain, data)
+                        logger.debug("link[]='%s' is not 'dict' or no element 'rel' found - SKIPPED!", type(link))
+                        continue
+                    elif link["rel"] != niid:
+                        logger.debug("link[re]='%s' does not matched niid='%s' - SKIPPED!", link["rel"], niid)
+                        continue
+                    elif "href" not in link:
+                        logger.warning("link[rel]='%s' has no element 'href' - SKIPPED!", link["rel"])
+                        continue
+
+                    # Default is that 'href' has a complete URL, but some hosts don't send that
+                    logger.debug("link[rel]='%s' matches niid='%s'", link["rel"], niid)
+                    url = link["href"]
+                    components = urlparse(link["href"])
+
+                    logger.debug("components[%s]='%s'", type(components), components)
+                    if components.scheme == "" and components.netloc == "":
+                        logger.warning("link[href]='%s' has no scheme and host name in it, prepending from domain='%s'", link['href'], domain)
+                        url = f"https://{domain}{url}"
+                        components = urlparse(url)
+                    elif components.netloc == "":
+                        logger.warning("link[href]='%s' has no netloc set, setting domain='%s'", link["href"], domain)
+                        url = f"{components.scheme}://{domain}{components.path}"
+                        components = urlparse(url)
+
+                    if not utils.is_domain_wanted(components.netloc):
+                        logger.debug("components.netloc='%s' is not wanted - SKIPPED!", components.netloc)
+                        continue
+
+                    logger.debug("Fetching nodeinfo from url='%s' ...", url)
+                    data = network.fetch_api_url(
+                        url,
+                        (config.get("connection_timeout"), config.get("read_timeout"))
+                     )
+
+                    logger.debug("link[href]='%s',data[]='%s'", link["href"], type(data))
+                    if "error_message" not in data and "json" in data:
+                        logger.debug("Found JSON data()=%d,link[href]='%s' - Setting detection_mode=AUTO_DISCOVERY ...", len(data), link["href"])
+                        instances.set_detection_mode(domain, "AUTO_DISCOVERY")
+                        instances.set_nodeinfo_url(domain, link["href"])
+
+                        logger.debug("Marking domain='%s' as successfully handled ...", domain)
+                        instances.set_success(domain)
+                        break
+                    else:
+                        logger.debug("Setting last error for domain='%s',data[]='%s'", domain, type(data))
+                        instances.set_last_error(domain, data)
 
                 logger.debug("data()=%d", len(data))
                 if "error_message" not in data and "json" in data:
 
                 logger.debug("data()=%d", len(data))
                 if "error_message" not in data and "json" in data: