Skip to content

Commit

Permalink
Merge branch 'master' into cron-creator-to-user
Browse files Browse the repository at this point in the history
  • Loading branch information
Cisphyx authored Dec 26, 2024
2 parents 80db56b + d37450a commit a69a7fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion synapse/tests/test_utils_getrefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def getVcr(self):
cm = myvcr.use_cassette(fp)
return cm

async def test_basics(self):
def test_basics(self):

args = s_getrefs.parse_args([
s_data.path('attack-flow', 'attack-flow-schema-2.0.0.json')
Expand Down
17 changes: 14 additions & 3 deletions synapse/utils/getrefs.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import sys
import json
import urllib
import asyncio
import logging
import pathlib
import argparse

import requests
import aiohttp

import synapse.exc as s_exc
import synapse.data as s_data
Expand All @@ -20,7 +21,13 @@ def download_refs_handler(uri):
This function downloads the JSON schema at the given URI, parses the given
URI to get the path component, and then saves the referenced schema to the
'jsonschemas' directory of synapse.data.
This function runs its own asyncio loop for each URI being requested.
'''
ret = asyncio.run(_download_refs_handler(uri))
return ret

async def _download_refs_handler(uri):

try:
parts = urllib.parse.urlparse(uri)
Expand All @@ -45,8 +52,12 @@ def download_refs_handler(uri):

# Get the data from the interwebs
logger.info(f'Downloading schema from {uri}.')
resp = requests.get(uri)
data = resp.json()
async with aiohttp.ClientSession() as session:
async with session.get(uri) as resp:
resp.raise_for_status()
buf = await resp.read()

data = json.loads(buf.decode())

# Save the json schema to disk
with filepath.open('w') as fp:
Expand Down

0 comments on commit a69a7fa

Please sign in to comment.