Skip to content
Snippets Groups Projects
Commit 9d4c9c1d authored by Robert Latta's avatar Robert Latta
Browse files

corrected encoding after enabling ignore-cache route param

parent cafd7df7
No related branches found
No related tags found
No related merge requests found
import itertools
import json
from flask import Blueprint, jsonify, Response, request
from flask import Blueprint, Response, request
from inventory_provider.routes import common
from inventory_provider.routes.common import _ignore_cache_or_retrieve
......@@ -110,16 +110,18 @@ def access_services():
if not result:
result = list(_services())
# cache this data for the next call
redis.set(cache_key, json.dumps(result).encode('utf-8'))
if not result:
return Response(
response='no access services found',
status=404,
mimetype="text/html")
if not result:
return Response(
response='no access services found',
status=404,
mimetype="text/html")
# cache this data for the next call
result = json.dumps(result)
redis.set(cache_key, result.encode('utf-8'))
return jsonify(result)
return Response(result, mimetype="application/json")
def _handle_peering_group_request(name, cache_key, group_key_base):
......@@ -163,21 +165,21 @@ def _handle_peering_group_request(name, cache_key, group_key_base):
if not items:
if name:
items = _load_list_items(f'{group_key_base}:{name}')
items = list(_load_list_items(f'{group_key_base}:{name}'))
else:
gen_list = list(map(_load_list_items, _get_all_subkeys()))
items = itertools.chain(*gen_list)
items = list(itertools.chain(*gen_list))
items = list(items)
if not items:
return Response(
response='no peerings found',
status=404,
mimetype="text/html")
items = json.dumps(items)
r.set(cache_key, json.dumps(items).encode('utf-8'))
r.set(cache_key, items.encode('utf-8'))
return jsonify(items)
return Response(items, mimetype="application/json")
@routes.route("/bgp/logical-system-peerings", methods=['GET', 'POST'])
......@@ -272,11 +274,11 @@ def _handle_peering_group_list_request(cache_key, group_key_base):
response='no groups found',
status=404,
mimetype="text/html")
names = sorted(names)
names = json.dumps(sorted(names))
r.set(cache_key, json.dumps(names).encode('utf-8'))
r.set(cache_key, names.encode('utf-8'))
return jsonify(names)
return Response(names, mimetype="application/json")
@routes.route("/bgp/logical-systems", methods=['GET', 'POST'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment