in mozetl/taar/taar_utils.py [0:0]
def load_amo_external_whitelist():
"""Download and parse the AMO add-on whitelist.
:raises RuntimeError: the AMO whitelist file cannot be downloaded or contains
no valid add-ons.
"""
final_whitelist = []
amo_dump = {}
try:
# Load the most current AMO dump JSON resource.
s3 = boto3.client("s3")
s3_contents = s3.get_object(Bucket=AMO_DUMP_BUCKET, Key=AMO_WHITELIST_KEY)
amo_dump = json.loads(s3_contents["Body"].read().decode("utf-8"))
except ClientError:
logger.exception(
"Failed to download from S3",
extra={"bucket": AMO_DUMP_BUCKET, "key": AMO_DUMP_KEY},
)
# If the load fails, we will have an empty whitelist, this may be problematic.
for key, value in list(amo_dump.items()):
addon_files = value.get("current_version", {}).get("files", {})
# If any of the addon files are web_extensions compatible, it can be recommended.
if any([f.get("is_webextension", False) for f in addon_files]):
final_whitelist.append(value["guid"])
if len(final_whitelist) == 0:
raise RuntimeError("Empty AMO whitelist detected")
return final_whitelist