summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Lee <rblee88@gmail.com>2014-03-06 17:30:28 -0600
committerAnderson Mesquita <andersonvom@gmail.com>2014-03-07 10:59:24 -0600
commit3f120f6ba241c5bfb5da4676744204ac0ba4d1cc (patch)
treecd08a7775a5e0b9b42d435dc38f70b5021484be5
parentecc4f2eb7b8a930d1059cdd5ae2c99e4d4d4df5e (diff)
downloadpython-barbicanclient-3f120f6ba241c5bfb5da4676744204ac0ba4d1cc.tar.gz
Conditionally validate KeystoneAuthV2 credentials
Don't validate the presence of KeystoneAuthV2 credential info if a keystone client is given. Co-Authored-By: Anderson Mesquita <andersonvom@gmail.com> Change-Id: I5d928efda843d8a6310103bf07c375d716908031
-rw-r--r--barbicanclient/common/auth.py19
-rw-r--r--barbicanclient/test/common/test_auth.py6
2 files changed, 17 insertions, 8 deletions
diff --git a/barbicanclient/common/auth.py b/barbicanclient/common/auth.py
index ff26ddb..9711ac2 100644
--- a/barbicanclient/common/auth.py
+++ b/barbicanclient/common/auth.py
@@ -51,20 +51,23 @@ class AuthPluginBase(object):
class KeystoneAuthV2(AuthPluginBase):
def __init__(self, auth_url='', username='', password='',
tenant_name='', tenant_id='', insecure=False, keystone=None):
- if not all([auth_url, username, password, tenant_name or tenant_id]):
- raise ValueError('Please provide auth_url, username, password,'
- ' and tenant_id or tenant_name.')
+ if not keystone:
+ tenant_info = tenant_name or tenant_id
+ if not all([auth_url, username, password, tenant_info]):
+ raise ValueError('Please provide auth_url, username, password,'
+ ' and tenant_id or tenant_name.')
+
+ self._barbican_url = None
+ #TODO(dmend): make these configurable
+ self._service_type = 'keystore'
+ self._endpoint_type = 'publicURL'
+
self._keystone = keystone or ksclient.Client(username=username,
password=password,
tenant_name=tenant_name,
tenant_id=tenant_id,
auth_url=auth_url,
insecure=insecure)
- self._barbican_url = None
- #TODO(dmend): make these configurable
- self._service_type = 'keystore'
- self._endpoint_type = 'publicURL'
-
self.tenant_name = self._keystone.tenant_name
self.tenant_id = self._keystone.tenant_id
diff --git a/barbicanclient/test/common/test_auth.py b/barbicanclient/test/common/test_auth.py
index c2ef0ff..eb7eb25 100644
--- a/barbicanclient/test/common/test_auth.py
+++ b/barbicanclient/test/common/test_auth.py
@@ -44,6 +44,12 @@ class WhenTestingKeystoneAuthentication(unittest.TestCase):
with self.assertRaises(ValueError):
keystone = auth.KeystoneAuthV2()
+ def test_nothing_is_required_if_keystone_is_present(self):
+ fake_keystone = mock.Mock(tenant_name='foo', tenant_id='bar')
+ keystone_auth = auth.KeystoneAuthV2(keystone=fake_keystone)
+ self.assertEqual('foo', keystone_auth.tenant_name)
+ self.assertEqual('bar', keystone_auth.tenant_id)
+
def test_get_barbican_url(self):
barbican_url = 'https://www.barbican.com'
self.keystone_auth._barbican_url = barbican_url