Author: tomaz
Date: Thu Apr 12 23:31:07 2012
New Revision: 1325571

URL: http://svn.apache.org/viewvc?rev=1325571&view=rev
Log:
Store auth token expire times on the connection class in the attribute
called 'auth_token_expires'. This patch has been contributed by Chris Gilmer and
Brad Morgan and is part of LIBCLOUD-178.

Modified:
    libcloud/trunk/CHANGES
    libcloud/trunk/libcloud/common/openstack.py
    libcloud/trunk/test/compute/test_openstack.py

Modified: libcloud/trunk/CHANGES
URL: 
http://svn.apache.org/viewvc/libcloud/trunk/CHANGES?rev=1325571&r1=1325570&r2=1325571&view=diff
==============================================================================
--- libcloud/trunk/CHANGES (original)
+++ libcloud/trunk/CHANGES Thu Apr 12 23:31:07 2012
@@ -24,6 +24,10 @@ Changes with Apache Libcloud in developm
     - Add Joyent driver.
       [Tomaz Muraus]
 
+    - Store auth token expire times on the connection class in the attribute
+      called 'auth_token_expires'.
+      [Chris Gilmer, Brad Morgan]
+
   *) Storage
 
     - Large object upload support for CloudFiles driver

Modified: libcloud/trunk/libcloud/common/openstack.py
URL: 
http://svn.apache.org/viewvc/libcloud/trunk/libcloud/common/openstack.py?rev=1325571&r1=1325570&r2=1325571&view=diff
==============================================================================
--- libcloud/trunk/libcloud/common/openstack.py (original)
+++ libcloud/trunk/libcloud/common/openstack.py Thu Apr 12 23:31:07 2012
@@ -168,6 +168,7 @@ class OpenStackAuthConnection(Connection
                 raise MalformedResponseError('Failed to parse JSON', e)
             try:
                 self.auth_token = body['auth']['token']['id']
+                self.auth_token_expires = body['auth']['token']['expires']
                 self.urls = body['auth']['serviceCatalog']
             except KeyError:
                 e = sys.exc_info()[1]
@@ -218,8 +219,8 @@ class OpenStackAuthConnection(Connection
 
             try:
                 access = body['access']
-                token = access['token']
-                self.auth_token = token['id']
+                self.auth_token = access['token']['id']
+                self.auth_token_expires = access['token']['expires']
                 self.urls = access['serviceCatalog']
             except KeyError:
                 e = sys.exc_info()[1]
@@ -356,6 +357,7 @@ class OpenStackBaseConnection(Connection
 
     auth_url = None
     auth_token = None
+    auth_token_expires = None
     service_catalog = None
     service_type = None
     service_name = None
@@ -454,6 +456,7 @@ class OpenStackBaseConnection(Connection
             osa.authenticate()
 
             self.auth_token = osa.auth_token
+            self.auth_token_expires = osa.auth_token_expires
 
             # pull out and parse the service catalog
             self.service_catalog = OpenStackServiceCatalog(osa.urls, 
ex_force_auth_version=self._auth_version)

Modified: libcloud/trunk/test/compute/test_openstack.py
URL: 
http://svn.apache.org/viewvc/libcloud/trunk/test/compute/test_openstack.py?rev=1325571&r1=1325570&r2=1325571&view=diff
==============================================================================
--- libcloud/trunk/test/compute/test_openstack.py (original)
+++ libcloud/trunk/test/compute/test_openstack.py Thu Apr 12 23:31:07 2012
@@ -97,6 +97,14 @@ class OpenStack_1_0_Tests(unittest.TestC
         self.driver.connection._populate_hosts_and_request_paths()
         clear_pricing_data()
 
+    def test_auth_token_is_set(self):
+        self.driver.connection._populate_hosts_and_request_paths()
+        self.assertEquals(self.driver.connection.auth_token, 
"603d2bd9-f45c-4583-b91c-2c8eac0b5654")
+
+    def test_auth_token_expires_is_set(self):
+        self.driver.connection._populate_hosts_and_request_paths()
+        self.assertEquals(self.driver.connection.auth_token_expires, 
"2011-09-18T02:44:17.000-05:00")
+
     def test_auth(self):
         OpenStackMockHttp.type = 'UNAUTHORIZED'
         try:
@@ -541,6 +549,24 @@ class OpenStack_1_1_Tests(unittest.TestC
         clear_pricing_data()
         self.node = self.driver.list_nodes()[1]
 
+    def test_auth_token_is_set(self):
+        # change base url and trash the current auth token so we can 
re-authenticate
+        self.driver.connection._ex_force_base_url = 
'http://ex_force_base_url.com:666/forced_url'
+        self.driver.connection.auth_token = None
+        self.driver.connection.auth_token_expires = None
+        self.driver.connection._populate_hosts_and_request_paths()
+
+        self.assertEquals(self.driver.connection.auth_token, 
"aaaaaaaaaaaa-bbb-cccccccccccccc")
+
+    def test_auth_token_expires_is_set(self):
+        # change base url and trash the current auth token so we can 
re-authenticate
+        self.driver.connection._ex_force_base_url = 
'http://ex_force_base_url.com:666/forced_url'
+        self.driver.connection.auth_token = None
+        self.driver.connection.auth_token_expires = None
+        self.driver.connection._populate_hosts_and_request_paths()
+
+        self.assertEquals(self.driver.connection.auth_token_expires, 
"2011-11-23T21:00:14.000-06:00")
+
     def test_ex_force_base_url(self):
         # change base url and trash the current auth token so we can 
re-authenticate
         self.driver.connection._ex_force_base_url = 
'http://ex_force_base_url.com:666/forced_url'


Reply via email to