Repository: libcloud Updated Branches: refs/heads/trunk f6227ddd1 -> 90f967c64
added iam temp creds token support to ElasticLBDriver Closes #843 Signed-off-by: Tomaz Muraus <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/2163e759 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/2163e759 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/2163e759 Branch: refs/heads/trunk Commit: 2163e759053762e25d3b59f20f560ff07da50447 Parents: f6227dd Author: Anton Kozyrev <[email protected]> Authored: Fri Jul 22 16:59:50 2016 +0300 Committer: Tomaz Muraus <[email protected]> Committed: Sat Jul 30 13:22:49 2016 +0200 ---------------------------------------------------------------------- libcloud/loadbalancer/drivers/elb.py | 12 +++++++++--- libcloud/test/loadbalancer/test_elb.py | 13 +++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/2163e759/libcloud/loadbalancer/drivers/elb.py ---------------------------------------------------------------------- diff --git a/libcloud/loadbalancer/drivers/elb.py b/libcloud/loadbalancer/drivers/elb.py index ed88fac..68a94cb 100644 --- a/libcloud/loadbalancer/drivers/elb.py +++ b/libcloud/loadbalancer/drivers/elb.py @@ -53,8 +53,9 @@ class ElasticLBDriver(Driver): connectionCls = ELBConnection signature_version = '4' - def __init__(self, access_id, secret, region): - super(ElasticLBDriver, self).__init__(access_id, secret) + def __init__(self, access_id, secret, region, token=None): + self.token = token + super(ElasticLBDriver, self).__init__(access_id, secret, token=token) self.region = region self.region_name = region self.connection.host = HOST % (region) @@ -354,5 +355,10 @@ class ElasticLBDriver(Driver): def _ex_connection_class_kwargs(self): kwargs = super(ElasticLBDriver, self)._ex_connection_class_kwargs() - kwargs['signature_version'] = self.signature_version + if hasattr(self, 'token') and self.token is not None: + kwargs['token'] = self.token + kwargs['signature_version'] = '4' + else: + kwargs['signature_version'] = self.signature_version + return kwargs http://git-wip-us.apache.org/repos/asf/libcloud/blob/2163e759/libcloud/test/loadbalancer/test_elb.py ---------------------------------------------------------------------- diff --git a/libcloud/test/loadbalancer/test_elb.py b/libcloud/test/loadbalancer/test_elb.py index 88f5555..fc42e77 100644 --- a/libcloud/test/loadbalancer/test_elb.py +++ b/libcloud/test/loadbalancer/test_elb.py @@ -36,6 +36,19 @@ class ElasticLBTests(unittest.TestCase): self.driver = ElasticLBDriver(*LB_ELB_PARAMS) + def test_instantiate_driver_with_token(self): + token = 'temporary_credentials_token' + driver = ElasticLBDriver(*LB_ELB_PARAMS, **{'token': token}) + self.assertTrue(hasattr(driver, 'token'), 'Driver has no attribute token') + self.assertEquals(token, driver.token, "Driver token does not match with provided token") + + def test_driver_with_token_signature_version(self): + token = 'temporary_credentials_token' + driver = ElasticLBDriver(*LB_ELB_PARAMS, **{'token': token}) + kwargs = driver._ex_connection_class_kwargs() + self.assertIn('signature_version', kwargs) + self.assertEquals('4', kwargs['signature_version'], 'Signature version is not 4 with temporary credentials') + def test_list_protocols(self): protocols = self.driver.list_protocols()
