bug 73: Add url validator in http_post_images 04/604/1
authorLeonardo <leonardo.mirabal@altran.com>
Mon, 7 Nov 2016 13:28:35 +0000 (14:28 +0100)
committerLeonardo <leonardo.mirabal@altran.com>
Mon, 7 Nov 2016 13:31:08 +0000 (14:31 +0100)
Signed-off-by: Leonardo <leonardo.mirabal@altran.com>
httpserver.py

index 88b1f0a..870d680 100644 (file)
@@ -30,6 +30,7 @@ __author__="Alfonso Tierno"
 __date__ ="$10-jul-2014 12:07:15$"
 
 import bottle
+import urlparse
 import yaml
 import json
 import threading
@@ -451,6 +452,18 @@ def check_valid_uuid(uuid):
     except js_e.ValidationError:
         return False
 
+
+def is_url(url):
+    '''
+    Check if string value is a well-wormed url
+    :param url: string url
+    :return: True if is a valid url, False if is not well-formed
+    '''
+
+    parsed_url = urlparse.urlparse(url)
+    return parsed_url
+
+
 @bottle.error(400)
 @bottle.error(401) 
 @bottle.error(404) 
@@ -1091,6 +1104,8 @@ def http_post_images(tenant_id):
         image_file = http_content['image'].get('path',None)
         if os.path.exists(image_file):
             http_content['image']['checksum'] = md5(image_file)
+        elif is_url(image_file):
+            pass
         else:
             if not host_test_mode:
                 content = "Image file not found"