Proper deprecation for Session.get_token()
Session.get_token() wasn't properly deprecated since the deprecation was only mentioned in the docstring. Proper deprecation requires use of warnings/debtcollector and documentation. Also, changed a test to use the non-deprecated function instead where the test wasn't checking that the deprecated function worked. bp deprecations Change-Id: I3d421b35554d58476281e037f90ab9b48e82730a
This commit is contained in:
@@ -19,6 +19,7 @@ import socket
|
|||||||
import time
|
import time
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
from debtcollector import removals
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
@@ -611,6 +612,8 @@ class Session(object):
|
|||||||
auth = self._auth_required(auth, msg)
|
auth = self._auth_required(auth, msg)
|
||||||
return auth.get_headers(self, **kwargs)
|
return auth.get_headers(self, **kwargs)
|
||||||
|
|
||||||
|
@removals.remove(message='Use get_auth_headers instead.', version='1.7.0',
|
||||||
|
removal_version='2.0.0')
|
||||||
def get_token(self, auth=None):
|
def get_token(self, auth=None):
|
||||||
"""Return a token as provided by the auth plugin.
|
"""Return a token as provided by the auth plugin.
|
||||||
|
|
||||||
@@ -623,9 +626,12 @@ class Session(object):
|
|||||||
:raises keystoneclient.exceptions.MissingAuthPlugin: if a plugin is not
|
:raises keystoneclient.exceptions.MissingAuthPlugin: if a plugin is not
|
||||||
available.
|
available.
|
||||||
|
|
||||||
*DEPRECATED*: This assumes that the only header that is used to
|
.. warning::
|
||||||
authenticate a message is 'X-Auth-Token'. This may not be
|
|
||||||
correct. Use get_auth_headers instead.
|
This method is deprecated as of the 1.7.0 release in favor of
|
||||||
|
:meth:`get_auth_headers` and may be removed in the 2.0.0 release.
|
||||||
|
This method assumes that the only header that is used to
|
||||||
|
authenticate a message is 'X-Auth-Token' which may not be correct.
|
||||||
|
|
||||||
:returns: A valid token.
|
:returns: A valid token.
|
||||||
:rtype: string
|
:rtype: string
|
||||||
|
@@ -454,7 +454,8 @@ class GenericAuthPluginTests(utils.TestCase):
|
|||||||
for k, v in six.iteritems(self.auth.headers):
|
for k, v in six.iteritems(self.auth.headers):
|
||||||
self.assertRequestHeaderEqual(k, v)
|
self.assertRequestHeaderEqual(k, v)
|
||||||
|
|
||||||
self.assertIsNone(self.session.get_token())
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
self.assertIsNone(self.session.get_token())
|
||||||
self.assertEqual(self.auth.headers,
|
self.assertEqual(self.auth.headers,
|
||||||
self.session.get_auth_headers())
|
self.session.get_auth_headers())
|
||||||
self.assertNotIn('X-Auth-Token',
|
self.assertNotIn('X-Auth-Token',
|
||||||
|
@@ -275,11 +275,13 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
password=self.TEST_PASS)
|
password=self.TEST_PASS)
|
||||||
s = session.Session(auth=a)
|
s = session.Session(auth=a)
|
||||||
|
|
||||||
self.assertEqual('token1', s.get_token())
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
self.assertEqual('token1', s.get_token())
|
||||||
self.assertEqual({'X-Auth-Token': 'token1'}, s.get_auth_headers())
|
self.assertEqual({'X-Auth-Token': 'token1'}, s.get_auth_headers())
|
||||||
|
|
||||||
a.invalidate()
|
a.invalidate()
|
||||||
self.assertEqual('token2', s.get_token())
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
self.assertEqual('token2', s.get_token())
|
||||||
self.assertEqual({'X-Auth-Token': 'token2'}, s.get_auth_headers())
|
self.assertEqual({'X-Auth-Token': 'token2'}, s.get_auth_headers())
|
||||||
|
|
||||||
def test_doesnt_log_password(self):
|
def test_doesnt_log_password(self):
|
||||||
@@ -289,7 +291,8 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
password=password)
|
password=password)
|
||||||
s = session.Session(auth=a)
|
s = session.Session(auth=a)
|
||||||
self.assertEqual(self.TEST_TOKEN, s.get_token())
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
self.assertEqual(self.TEST_TOKEN, s.get_token())
|
||||||
self.assertEqual({'X-Auth-Token': self.TEST_TOKEN},
|
self.assertEqual({'X-Auth-Token': self.TEST_TOKEN},
|
||||||
s.get_auth_headers())
|
s.get_auth_headers())
|
||||||
self.assertNotIn(password, self.logger.output)
|
self.assertNotIn(password, self.logger.output)
|
||||||
|
@@ -458,10 +458,12 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
password=self.TEST_PASS)
|
password=self.TEST_PASS)
|
||||||
s = session.Session(auth=a)
|
s = session.Session(auth=a)
|
||||||
|
|
||||||
self.assertEqual('token1', s.get_token())
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
self.assertEqual('token1', s.get_token())
|
||||||
self.assertEqual({'X-Auth-Token': 'token1'}, s.get_auth_headers())
|
self.assertEqual({'X-Auth-Token': 'token1'}, s.get_auth_headers())
|
||||||
a.invalidate()
|
a.invalidate()
|
||||||
self.assertEqual('token2', s.get_token())
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
self.assertEqual('token2', s.get_token())
|
||||||
self.assertEqual({'X-Auth-Token': 'token2'}, s.get_auth_headers())
|
self.assertEqual({'X-Auth-Token': 'token2'}, s.get_auth_headers())
|
||||||
|
|
||||||
def test_doesnt_log_password(self):
|
def test_doesnt_log_password(self):
|
||||||
@@ -471,7 +473,8 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
password=password)
|
password=password)
|
||||||
s = session.Session(a)
|
s = session.Session(a)
|
||||||
self.assertEqual(self.TEST_TOKEN, s.get_token())
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
self.assertEqual(self.TEST_TOKEN, s.get_token())
|
||||||
self.assertEqual({'X-Auth-Token': self.TEST_TOKEN},
|
self.assertEqual({'X-Auth-Token': self.TEST_TOKEN},
|
||||||
s.get_auth_headers())
|
s.get_auth_headers())
|
||||||
|
|
||||||
@@ -487,7 +490,7 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
include_catalog=False)
|
include_catalog=False)
|
||||||
s = session.Session(auth=a)
|
s = session.Session(auth=a)
|
||||||
|
|
||||||
s.get_token()
|
s.get_auth_headers()
|
||||||
|
|
||||||
auth_url = self.TEST_URL + '/auth/tokens'
|
auth_url = self.TEST_URL + '/auth/tokens'
|
||||||
self.assertEqual(auth_url, a.token_url)
|
self.assertEqual(auth_url, a.token_url)
|
||||||
|
@@ -76,7 +76,8 @@ class V3FederatedPlugin(utils.TestCase):
|
|||||||
|
|
||||||
def test_unscoped_behaviour(self):
|
def test_unscoped_behaviour(self):
|
||||||
sess = session.Session(auth=self.get_plugin())
|
sess = session.Session(auth=self.get_plugin())
|
||||||
self.assertEqual(self.unscoped_token_id, sess.get_token())
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
self.assertEqual(self.unscoped_token_id, sess.get_token())
|
||||||
|
|
||||||
self.assertTrue(self.unscoped_mock.called)
|
self.assertTrue(self.unscoped_mock.called)
|
||||||
self.assertFalse(self.scoped_mock.called)
|
self.assertFalse(self.scoped_mock.called)
|
||||||
@@ -84,7 +85,8 @@ class V3FederatedPlugin(utils.TestCase):
|
|||||||
def test_scoped_behaviour(self):
|
def test_scoped_behaviour(self):
|
||||||
auth = self.get_plugin(project_id=self.scoped_token.project_id)
|
auth = self.get_plugin(project_id=self.scoped_token.project_id)
|
||||||
sess = session.Session(auth=auth)
|
sess = session.Session(auth=auth)
|
||||||
self.assertEqual(self.scoped_token_id, sess.get_token())
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
self.assertEqual(self.scoped_token_id, sess.get_token())
|
||||||
|
|
||||||
self.assertTrue(self.unscoped_mock.called)
|
self.assertTrue(self.unscoped_mock.called)
|
||||||
self.assertTrue(self.scoped_mock.called)
|
self.assertTrue(self.scoped_mock.called)
|
||||||
|
@@ -802,7 +802,8 @@ class AdapterTest(utils.TestCase):
|
|||||||
sess = client_session.Session()
|
sess = client_session.Session()
|
||||||
adpt = adapter.Adapter(sess, auth=auth)
|
adpt = adapter.Adapter(sess, auth=auth)
|
||||||
|
|
||||||
self.assertEqual(self.TEST_TOKEN, adpt.get_token())
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
self.assertEqual(self.TEST_TOKEN, adpt.get_token())
|
||||||
self.assertTrue(auth.get_token_called)
|
self.assertTrue(auth.get_token_called)
|
||||||
|
|
||||||
def test_adapter_connect_retries(self):
|
def test_adapter_connect_retries(self):
|
||||||
|
@@ -248,7 +248,8 @@ class AuthenticateWithOAuthTests(TokenTests):
|
|||||||
access_key=access_key,
|
access_key=access_key,
|
||||||
access_secret=access_secret)
|
access_secret=access_secret)
|
||||||
s = session.Session(auth=a)
|
s = session.Session(auth=a)
|
||||||
t = s.get_token()
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
t = s.get_token()
|
||||||
self.assertEqual(self.TEST_TOKEN, t)
|
self.assertEqual(self.TEST_TOKEN, t)
|
||||||
|
|
||||||
OAUTH_REQUEST_BODY = {
|
OAUTH_REQUEST_BODY = {
|
||||||
|
Reference in New Issue
Block a user