misc: sign api/formdefs/ requests to wcs

This commit is contained in:
Frédéric Péters 2015-11-12 18:05:34 +01:00
parent 820cc8eedf
commit 0f3abdf5db
1 changed files with 5 additions and 4 deletions

View File

@ -60,13 +60,14 @@ def sign_string(s, key, algo='sha256', timedelta=30):
def get_wcs_services():
return settings.KNOWN_SERVICES.get('wcs')
def get_wcs_json(wcs_url, path):
def get_wcs_json(wcs_url, path, wcs_site):
if not wcs_url.endswith('/'):
wcs_url += '/'
url = wcs_url + path
response_json = cache.get(url)
if response_json is None:
response_json = requests.get(url, headers={'accept': 'application/json'},
signed_url = sign_url(url + '?orig=%s' % wcs_site.get('orig'), wcs_site.get('secret'))
response_json = requests.get(signed_url, headers={'accept': 'application/json'},
timeout=2).json()
cache.set(url, response_json)
return response_json
@ -76,7 +77,7 @@ def get_wcs_options(url, condition=None):
categories = {}
for wcs_key, wcs_site in get_wcs_services().iteritems():
site_title = wcs_site.get('title')
response_json = get_wcs_json(wcs_site.get('url'), url)
response_json = get_wcs_json(wcs_site.get('url'), url, wcs_site)
if type(response_json) is dict:
response_json = response_json.get('data')
for element in response_json:
@ -102,7 +103,7 @@ def get_wcs_options(url, condition=None):
def get_wcs_formdef_details(formdef_reference):
wcs_key, form_slug = formdef_reference.split(':')
wcs_site = get_wcs_services()[wcs_key]
forms_response_json = get_wcs_json(wcs_site.get('url'), 'json')
forms_response_json = get_wcs_json(wcs_site.get('url'), 'json', wcs_site)
for form in forms_response_json:
slug = form.get('slug')
if slug == form_slug: