Browse Source

Merged in aznashwan/coriolis (pull request #65)

Added json.loads() call to 'env' query param in API for Endpoint network listing.
Nashwan Azhari 8 years ago
parent
commit
eec371c43d
2 changed files with 7 additions and 4 deletions
  1. 1 1
      coriolis/api/v1/endpoint_networks.py
  2. 6 3
      coriolis/utils.py

+ 1 - 1
coriolis/api/v1/endpoint_networks.py

@@ -19,7 +19,7 @@ class EndpointNetworkController(api_wsgi.Controller):
     def index(self, req, endpoint_id):
     def index(self, req, endpoint_id):
         env = req.GET.get("env")
         env = req.GET.get("env")
         if env is not None:
         if env is not None:
-            env = utils.decode_base64_param(env)
+            env = utils.decode_base64_param(env, is_json=True)
 
 
         return endpoint_network_view.collection(
         return endpoint_network_view.collection(
             req, self._network_api.get_endpoint_networks(
             req, self._network_api.get_endpoint_networks(

+ 6 - 3
coriolis/utils.py

@@ -385,8 +385,11 @@ def parse_int_value(value):
         raise exception.InvalidInput("Invalid integer: %s" % value)
         raise exception.InvalidInput("Invalid integer: %s" % value)
 
 
 
 
-def decode_base64_param(value):
+def decode_base64_param(value, is_json=False):
     try:
     try:
-        return base64.b64decode(value).decode()
-    except (binascii.Error, TypeError) as ex:
+        decoded = base64.b64decode(value).decode()
+        if is_json:
+            decoded = json.loads(decoded)
+        return decoded
+    except (binascii.Error, TypeError, json.decoder.JSONDecodeError) as ex:
         raise exception.InvalidInput(reason=str(ex))
         raise exception.InvalidInput(reason=str(ex))