libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [2/5] git commit: When a request is made to a CDN endpoint there is no internalURL to use, we have to fall back to the publicURL
Date Thu, 30 Jan 2014 16:29:46 GMT
When a request is made to a CDN endpoint there is no internalURL to use, we have to fall back
to the publicURL

Closes #231

Signed-off-by: Tomaz Muraus <tomaz@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/34c3df43
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/34c3df43
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/34c3df43

Branch: refs/heads/trunk
Commit: 34c3df43ddb37d077cfb40049753d6ff487a2e91
Parents: 5a5e5bc
Author: John Obelenus <jobelenus@gmail.com>
Authored: Wed Jan 29 18:31:45 2014 -0500
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Thu Jan 30 17:22:20 2014 +0100

----------------------------------------------------------------------
 libcloud/storage/drivers/cloudfiles.py   | 15 ++++++++++++---
 libcloud/test/storage/test_cloudfiles.py |  6 ++++--
 2 files changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/34c3df43/libcloud/storage/drivers/cloudfiles.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/cloudfiles.py b/libcloud/storage/drivers/cloudfiles.py
index 8d52c00..8abaa1f 100644
--- a/libcloud/storage/drivers/cloudfiles.py
+++ b/libcloud/storage/drivers/cloudfiles.py
@@ -52,6 +52,8 @@ from libcloud.common.rackspace import AUTH_URL
 
 CDN_HOST = 'cdn.clouddrive.com'
 API_VERSION = 'v1.0'
+INTERNAL_ENDPOINT_KEY = 'internalURL'
+PUBLIC_ENDPOINT_KEY = 'publicURL'
 
 
 class CloudFilesResponse(Response):
@@ -113,7 +115,13 @@ class CloudFilesConnection(OpenStackBaseConnection):
         self.api_version = API_VERSION
         self.accept_format = 'application/json'
         self.cdn_request = False
-        self.endpoint_url = 'internalURL' if use_internal_url else 'publicURL'
+        self.use_internal_url = use_internal_url
+
+    def _get_endpoint_key(self):
+        endpoint_key = INTERNAL_ENDPOINT_KEY if self.use_internal_url else PUBLIC_ENDPOINT_KEY
+        if self.cdn_request:
+            endpoint_key = PUBLIC_ENDPOINT_KEY  # cdn endpoints don't have internal urls
+        return endpoint_key
 
     def get_endpoint(self):
         region = self._ex_force_service_region.upper()
@@ -134,12 +142,13 @@ class CloudFilesConnection(OpenStackBaseConnection):
         # if this is a CDN request, return the cdn url instead
         if self.cdn_request:
             ep = cdn_ep
+        endpoint_url = self._get_endpoint_key()
 
         if not ep:
             raise LibcloudError('Could not find specified endpoint')
 
-        if self.endpoint_url in ep:
-            return ep[self.endpoint_url]
+        if endpoint_url in ep:
+            return ep[endpoint_url]
         else:
             raise LibcloudError('Could not find specified endpoint')
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/34c3df43/libcloud/test/storage/test_cloudfiles.py
----------------------------------------------------------------------
diff --git a/libcloud/test/storage/test_cloudfiles.py b/libcloud/test/storage/test_cloudfiles.py
index 5f683fb..2878c1e 100644
--- a/libcloud/test/storage/test_cloudfiles.py
+++ b/libcloud/test/storage/test_cloudfiles.py
@@ -141,10 +141,12 @@ class CloudFilesTests(unittest.TestCase):
     def test_endpoint_pointer(self):
         kwargs = {'use_internal_url': False}
         driver = CloudFilesStorageDriver('driver', 'dummy', **kwargs)
-        self.assertEquals(driver.connection.endpoint_url, 'publicURL')
+        self.assertEquals(driver.connection._get_endpoint_key(), libcloud.storage.drivers.cloudfiles.PUBLIC_ENDPOINT_KEY)
         kwargs = {'use_internal_url': True}
         driver = CloudFilesStorageDriver('driver', 'dummy', **kwargs)
-        self.assertEquals(driver.connection.endpoint_url, 'internalURL')
+        self.assertEquals(driver.connection._get_endpoint_key(), libcloud.storage.drivers.cloudfiles.INTERNAL_ENDPOINT_KEY)
+        driver.connection.cdn_request = True
+        self.assertEquals(driver.connection._get_endpoint_key(), libcloud.storage.drivers.cloudfiles.PUBLIC_ENDPOINT_KEY)
 
     def test_list_containers(self):
         CloudFilesMockHttp.type = 'EMPTY'


Mime
View raw message