From a10524a35d50c21688b062f8ce8fc0bfba938f77 Mon Sep 17 00:00:00 2001 From: db0 Date: Sat, 24 Jun 2023 14:56:09 +0200 Subject: [PATCH] fix: mastodon admin pull --- fediseer/apis/v1/base.py | 4 ++-- fediseer/apis/v1/endorsements.py | 2 +- fediseer/apis/v1/guarantees.py | 2 +- fediseer/apis/v1/whitelist.py | 4 ++-- fediseer/fediverse.py | 5 ++--- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/fediseer/apis/v1/base.py b/fediseer/apis/v1/base.py index 33ac7fd..3c338ec 100644 --- a/fediseer/apis/v1/base.py +++ b/fediseer/apis/v1/base.py @@ -88,7 +88,7 @@ def ensure_instance_registered(domain): admin_usernames = get_admin_for_software(software, domain) instance = database.find_instance_by_domain(domain) if instance: - return instance, nodeinfo, site, admin_usernames + return instance, nodeinfo, admin_usernames new_instance = Instance( domain=domain, open_registrations=open_registrations, @@ -96,4 +96,4 @@ def ensure_instance_registered(domain): software=software, ) new_instance.create() - return new_instance, nodeinfo, site, admin_usernames + return new_instance, nodeinfo, admin_usernames diff --git a/fediseer/apis/v1/endorsements.py b/fediseer/apis/v1/endorsements.py index 96ee153..7f5f600 100644 --- a/fediseer/apis/v1/endorsements.py +++ b/fediseer/apis/v1/endorsements.py @@ -81,7 +81,7 @@ class Endorsements(Resource): unbroken_chain, chainbreaker = database.has_unbroken_chain(instance.id) if not unbroken_chain: raise e.Forbidden(f"Guarantee chain for this instance has been broken. Chain ends at {chainbreaker.domain}!") - target_instance, nodeinfo, site, admin_usernames = ensure_instance_registered(domain) + target_instance, nodeinfo, admin_usernames = ensure_instance_registered(domain) if not target_instance: raise e.NotFound(f"Something went wrong trying to register this instance.") if len(target_instance.guarantors) == 0: diff --git a/fediseer/apis/v1/guarantees.py b/fediseer/apis/v1/guarantees.py index 1b85afc..9f4d6d8 100644 --- a/fediseer/apis/v1/guarantees.py +++ b/fediseer/apis/v1/guarantees.py @@ -84,7 +84,7 @@ class Guarantees(Resource): unbroken_chain, chainbreaker = database.has_unbroken_chain(instance.id) if not unbroken_chain: raise e.Forbidden(f"Guarantee chain for this instance has been broken. Chain ends at {chainbreaker.domain}!") - target_instance, nodeinfo, site, admin_usernames = ensure_instance_registered(domain) + target_instance, nodeinfo, admin_usernames = ensure_instance_registered(domain) if not target_instance: raise e.NotFound(f"Something went wrong trying to register this instance.") if database.get_guarantee(target_instance.id,instance.id): diff --git a/fediseer/apis/v1/whitelist.py b/fediseer/apis/v1/whitelist.py index 37b60ac..faea374 100644 --- a/fediseer/apis/v1/whitelist.py +++ b/fediseer/apis/v1/whitelist.py @@ -39,7 +39,7 @@ class WhitelistDomain(Resource): '''Display info about a specific instance ''' self.args = self.get_parser.parse_args() - instance, nodeinfo, site, admin_usernames = ensure_instance_registered(domain) + instance, nodeinfo, admin_usernames = ensure_instance_registered(domain) if not instance: raise e.NotFound(f"Something went wrong trying to register this instance.") return instance.get_details(),200 @@ -62,7 +62,7 @@ class WhitelistDomain(Resource): self.args = self.put_parser.parse_args() if '@' in self.args.admin: raise e.BadRequest("Please send the username without any @ signs or domains") - instance, nodeinfo, site, admin_usernames = ensure_instance_registered(domain) + instance, nodeinfo, admin_usernames = ensure_instance_registered(domain) guarantor_instance = None if self.args.guarantor: guarantor_instance = database.find_instance_by_domain(self.args.guarantor) diff --git a/fediseer/fediverse.py b/fediseer/fediverse.py index 49f6435..1ada2b0 100644 --- a/fediseer/fediverse.py +++ b/fediseer/fediverse.py @@ -13,10 +13,10 @@ def get_lemmy_admins(domain): def get_mastodon_admins(domain): try: - site = requests(f"https://{domain}/api/v2/instance").json() + site = requests.get(f"https://{domain}/api/v2/instance").json() return [site["contact"]["account"]["username"]] except Exception as err: - logger.warning(f"Error retrieving mastodon site info for {domain}") + logger.warning(f"Error retrieving mastodon site info for {domain}: {err}") return None def get_admin_for_software(software: str, domain: str): @@ -44,5 +44,4 @@ def get_nodeinfo(domain): nodeinfo = requests.get(wellknown['links'][0]['href'], headers=headers, timeout=3).json() return nodeinfo except Exception as err: - logger.debug(err) return None \ No newline at end of file