Deprecate create HTTPClient without session
The comments indicated that creating a HTTPClient without a session is deprecated, but there was no warning generated. bp deprecations Change-Id: I44796cbff95a7bbdd6e7a58e5cfb8360bdae5477
This commit is contained in:
@@ -148,6 +148,12 @@ class _KeystoneAdapter(adapter.LegacyJsonAdapter):
|
|||||||
class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
|
class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
|
||||||
"""HTTP client
|
"""HTTP client
|
||||||
|
|
||||||
|
.. warning::
|
||||||
|
|
||||||
|
Creating an instance of this class without using the session argument
|
||||||
|
is deprecated as of the 1.7.0 release and may be removed in the 2.0.0
|
||||||
|
release.
|
||||||
|
|
||||||
:param string user_id: User ID for authentication. (optional)
|
:param string user_id: User ID for authentication. (optional)
|
||||||
:param string username: Username for authentication. (optional)
|
:param string username: Username for authentication. (optional)
|
||||||
:param string user_domain_id: User's domain ID for authentication.
|
:param string user_domain_id: User's domain ID for authentication.
|
||||||
@@ -166,18 +172,32 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
|
|||||||
:param string auth_url: Identity service endpoint for authorization.
|
:param string auth_url: Identity service endpoint for authorization.
|
||||||
:param string region_name: Name of a region to select when choosing an
|
:param string region_name: Name of a region to select when choosing an
|
||||||
endpoint from the service catalog.
|
endpoint from the service catalog.
|
||||||
:param integer timeout: DEPRECATED: use session. (optional)
|
:param integer timeout: This argument is deprecated as of the 1.7.0 release
|
||||||
|
in favor of session and may be removed in the 2.0.0
|
||||||
|
release. (optional)
|
||||||
:param string endpoint: A user-supplied endpoint URL for the identity
|
:param string endpoint: A user-supplied endpoint URL for the identity
|
||||||
service. Lazy-authentication is possible for API
|
service. Lazy-authentication is possible for API
|
||||||
service calls if endpoint is set at instantiation.
|
service calls if endpoint is set at instantiation.
|
||||||
(optional)
|
(optional)
|
||||||
:param string token: Token for authentication. (optional)
|
:param string token: Token for authentication. (optional)
|
||||||
:param string cacert: DEPRECATED: use session. (optional)
|
:param string cacert: This argument is deprecated as of the 1.7.0 release
|
||||||
:param string key: DEPRECATED: use session. (optional)
|
in favor of session and may be removed in the 2.0.0
|
||||||
:param string cert: DEPRECATED: use session. (optional)
|
release. (optional)
|
||||||
:param boolean insecure: DEPRECATED: use session. (optional)
|
:param string key: This argument is deprecated as of the 1.7.0 release
|
||||||
:param string original_ip: DEPRECATED: use session. (optional)
|
in favor of session and may be removed in the 2.0.0
|
||||||
:param boolean debug: DEPRECATED: use logging configuration. (optional)
|
release. (optional)
|
||||||
|
:param string cert: This argument is deprecated as of the 1.7.0 release
|
||||||
|
in favor of session and may be removed in the 2.0.0
|
||||||
|
release. (optional)
|
||||||
|
:param boolean insecure: This argument is deprecated as of the 1.7.0
|
||||||
|
release in favor of session and may be removed in
|
||||||
|
the 2.0.0 release. (optional)
|
||||||
|
:param string original_ip: This argument is deprecated as of the 1.7.0
|
||||||
|
release in favor of session and may be removed
|
||||||
|
in the 2.0.0 release. (optional)
|
||||||
|
:param boolean debug: This argument is deprecated as of the 1.7.0 release
|
||||||
|
in favor of logging configuration and may be removed
|
||||||
|
in the 2.0.0 release. (optional)
|
||||||
:param dict auth_ref: To allow for consumers of the client to manage their
|
:param dict auth_ref: To allow for consumers of the client to manage their
|
||||||
own caching strategy, you may initialize a client
|
own caching strategy, you may initialize a client
|
||||||
with a previously captured auth_reference (token). If
|
with a previously captured auth_reference (token). If
|
||||||
@@ -345,6 +365,12 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
|
|||||||
self._auth_token = None
|
self._auth_token = None
|
||||||
|
|
||||||
if not session:
|
if not session:
|
||||||
|
|
||||||
|
warnings.warn(
|
||||||
|
'Constructing an HTTPClient instance without using a session '
|
||||||
|
'is deprecated as of the 1.7.0 release and may be removed in '
|
||||||
|
'the 2.0.0 release.', DeprecationWarning)
|
||||||
|
|
||||||
kwargs['session'] = _FakeRequestSession()
|
kwargs['session'] = _FakeRequestSession()
|
||||||
session = client_session.Session._construct(kwargs)
|
session = client_session.Session._construct(kwargs)
|
||||||
session.auth = self
|
session.auth = self
|
||||||
|
@@ -57,7 +57,9 @@ class ClientDiscoveryTests(utils.TestCase):
|
|||||||
|
|
||||||
def test_discover_extensions_v2(self):
|
def test_discover_extensions_v2(self):
|
||||||
self.requests_mock.get("%s/extensions" % V2_URL, text=EXTENSION_LIST)
|
self.requests_mock.get("%s/extensions" % V2_URL, text=EXTENSION_LIST)
|
||||||
extensions = client.Client().discover_extensions(url=V2_URL)
|
# Creating a HTTPClient not using session is deprecated.
|
||||||
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
extensions = client.Client().discover_extensions(url=V2_URL)
|
||||||
self.assertIn(EXTENSION_ALIAS_FOO, extensions)
|
self.assertIn(EXTENSION_ALIAS_FOO, extensions)
|
||||||
self.assertEqual(extensions[EXTENSION_ALIAS_FOO], EXTENSION_NAME_FOO)
|
self.assertEqual(extensions[EXTENSION_ALIAS_FOO], EXTENSION_NAME_FOO)
|
||||||
self.assertIn(EXTENSION_ALIAS_BAR, extensions)
|
self.assertIn(EXTENSION_ALIAS_BAR, extensions)
|
||||||
|
@@ -56,14 +56,18 @@ class ClientTest(utils.TestCase):
|
|||||||
TEST_URL = 'http://127.0.0.1:5000/hi'
|
TEST_URL = 'http://127.0.0.1:5000/hi'
|
||||||
|
|
||||||
def test_unauthorized_client_requests(self):
|
def test_unauthorized_client_requests(self):
|
||||||
cl = get_client()
|
# Creating a HTTPClient not using session is deprecated.
|
||||||
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
cl = get_client()
|
||||||
self.assertRaises(exceptions.AuthorizationFailure, cl.get, '/hi')
|
self.assertRaises(exceptions.AuthorizationFailure, cl.get, '/hi')
|
||||||
self.assertRaises(exceptions.AuthorizationFailure, cl.post, '/hi')
|
self.assertRaises(exceptions.AuthorizationFailure, cl.post, '/hi')
|
||||||
self.assertRaises(exceptions.AuthorizationFailure, cl.put, '/hi')
|
self.assertRaises(exceptions.AuthorizationFailure, cl.put, '/hi')
|
||||||
self.assertRaises(exceptions.AuthorizationFailure, cl.delete, '/hi')
|
self.assertRaises(exceptions.AuthorizationFailure, cl.delete, '/hi')
|
||||||
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
cl = get_authed_client()
|
# Creating a HTTPClient not using session is deprecated.
|
||||||
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
cl = get_authed_client()
|
||||||
|
|
||||||
self.stub_url('GET', text=RESPONSE_BODY)
|
self.stub_url('GET', text=RESPONSE_BODY)
|
||||||
|
|
||||||
@@ -79,14 +83,18 @@ class ClientTest(utils.TestCase):
|
|||||||
self.assertEqual(body, {"hi": "there"})
|
self.assertEqual(body, {"hi": "there"})
|
||||||
|
|
||||||
def test_get_error_with_plaintext_resp(self):
|
def test_get_error_with_plaintext_resp(self):
|
||||||
cl = get_authed_client()
|
# Creating a HTTPClient not using session is deprecated.
|
||||||
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
cl = get_authed_client()
|
||||||
self.stub_url('GET', status_code=400,
|
self.stub_url('GET', status_code=400,
|
||||||
text='Some evil plaintext string')
|
text='Some evil plaintext string')
|
||||||
|
|
||||||
self.assertRaises(exceptions.BadRequest, cl.get, '/hi')
|
self.assertRaises(exceptions.BadRequest, cl.get, '/hi')
|
||||||
|
|
||||||
def test_get_error_with_json_resp(self):
|
def test_get_error_with_json_resp(self):
|
||||||
cl = get_authed_client()
|
# Creating a HTTPClient not using session is deprecated.
|
||||||
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
cl = get_authed_client()
|
||||||
err_response = {
|
err_response = {
|
||||||
"error": {
|
"error": {
|
||||||
"code": 400,
|
"code": 400,
|
||||||
@@ -105,7 +113,9 @@ class ClientTest(utils.TestCase):
|
|||||||
self.assertTrue(exc_raised, 'Exception not raised.')
|
self.assertTrue(exc_raised, 'Exception not raised.')
|
||||||
|
|
||||||
def test_post(self):
|
def test_post(self):
|
||||||
cl = get_authed_client()
|
# Creating a HTTPClient not using session is deprecated.
|
||||||
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
cl = get_authed_client()
|
||||||
|
|
||||||
self.stub_url('POST')
|
self.stub_url('POST')
|
||||||
with self.deprecations.expect_deprecations_here():
|
with self.deprecations.expect_deprecations_here():
|
||||||
@@ -120,9 +130,13 @@ class ClientTest(utils.TestCase):
|
|||||||
|
|
||||||
def test_forwarded_for(self):
|
def test_forwarded_for(self):
|
||||||
ORIGINAL_IP = "10.100.100.1"
|
ORIGINAL_IP = "10.100.100.1"
|
||||||
cl = httpclient.HTTPClient(username="username", password="password",
|
# Creating a HTTPClient not using session is deprecated.
|
||||||
project_id="tenant", auth_url="auth_test",
|
with self.deprecations.expect_deprecations_here():
|
||||||
original_ip=ORIGINAL_IP)
|
cl = httpclient.HTTPClient(username="username",
|
||||||
|
password="password",
|
||||||
|
project_id="tenant",
|
||||||
|
auth_url="auth_test",
|
||||||
|
original_ip=ORIGINAL_IP)
|
||||||
|
|
||||||
self.stub_url('GET')
|
self.stub_url('GET')
|
||||||
|
|
||||||
|
@@ -45,7 +45,9 @@ class ClientTest(utils.TestCase):
|
|||||||
@mock.patch.object(requests, 'request')
|
@mock.patch.object(requests, 'request')
|
||||||
def test_get(self, MOCK_REQUEST):
|
def test_get(self, MOCK_REQUEST):
|
||||||
MOCK_REQUEST.return_value = FAKE_RESPONSE
|
MOCK_REQUEST.return_value = FAKE_RESPONSE
|
||||||
cl = get_authed_client()
|
# Creating a HTTPClient not using session is deprecated.
|
||||||
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
cl = get_authed_client()
|
||||||
|
|
||||||
with self.deprecations.expect_deprecations_here():
|
with self.deprecations.expect_deprecations_here():
|
||||||
resp, body = cl.get("/hi")
|
resp, body = cl.get("/hi")
|
||||||
@@ -65,7 +67,9 @@ class ClientTest(utils.TestCase):
|
|||||||
@mock.patch.object(requests, 'request')
|
@mock.patch.object(requests, 'request')
|
||||||
def test_post(self, MOCK_REQUEST):
|
def test_post(self, MOCK_REQUEST):
|
||||||
MOCK_REQUEST.return_value = FAKE_RESPONSE
|
MOCK_REQUEST.return_value = FAKE_RESPONSE
|
||||||
cl = get_authed_client()
|
# Creating a HTTPClient not using session is deprecated.
|
||||||
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
cl = get_authed_client()
|
||||||
|
|
||||||
with self.deprecations.expect_deprecations_here():
|
with self.deprecations.expect_deprecations_here():
|
||||||
cl.post("/hi", body=[1, 2, 3])
|
cl.post("/hi", body=[1, 2, 3])
|
||||||
@@ -83,10 +87,12 @@ class ClientTest(utils.TestCase):
|
|||||||
@mock.patch.object(requests, 'request')
|
@mock.patch.object(requests, 'request')
|
||||||
def test_post_auth(self, MOCK_REQUEST):
|
def test_post_auth(self, MOCK_REQUEST):
|
||||||
MOCK_REQUEST.return_value = FAKE_RESPONSE
|
MOCK_REQUEST.return_value = FAKE_RESPONSE
|
||||||
cl = httpclient.HTTPClient(
|
# Creating a HTTPClient not using session is deprecated.
|
||||||
username="username", password="password", project_id="tenant",
|
with self.deprecations.expect_deprecations_here():
|
||||||
auth_url="auth_test", cacert="ca.pem", cert=('cert.pem', 'key.pem')
|
cl = httpclient.HTTPClient(
|
||||||
)
|
username="username", password="password", project_id="tenant",
|
||||||
|
auth_url="auth_test", cacert="ca.pem",
|
||||||
|
cert=('cert.pem', 'key.pem'))
|
||||||
cl.management_url = "https://127.0.0.1:5000"
|
cl.management_url = "https://127.0.0.1:5000"
|
||||||
cl.auth_token = "token"
|
cl.auth_token = "token"
|
||||||
with self.deprecations.expect_deprecations_here():
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
@@ -87,8 +87,10 @@ class KeyringTest(utils.TestCase):
|
|||||||
"""Ensure that if we don't have use_keyring set in the client that
|
"""Ensure that if we don't have use_keyring set in the client that
|
||||||
the keyring is never accessed.
|
the keyring is never accessed.
|
||||||
"""
|
"""
|
||||||
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
|
# Creating a HTTPClient not using session is deprecated.
|
||||||
project_id=TENANT_ID, auth_url=AUTH_URL)
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
|
||||||
|
project_id=TENANT_ID, auth_url=AUTH_URL)
|
||||||
|
|
||||||
# stub and check that a new token is received
|
# stub and check that a new token is received
|
||||||
method = 'get_raw_token_from_identity_service'
|
method = 'get_raw_token_from_identity_service'
|
||||||
@@ -104,8 +106,10 @@ class KeyringTest(utils.TestCase):
|
|||||||
self.assertFalse(self.memory_keyring.set_password_called)
|
self.assertFalse(self.memory_keyring.set_password_called)
|
||||||
|
|
||||||
def test_build_keyring_key(self):
|
def test_build_keyring_key(self):
|
||||||
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
|
# Creating a HTTPClient not using session is deprecated.
|
||||||
project_id=TENANT_ID, auth_url=AUTH_URL)
|
with self.deprecations.expect_deprecations_here():
|
||||||
|
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
|
||||||
|
project_id=TENANT_ID, auth_url=AUTH_URL)
|
||||||
|
|
||||||
keyring_key = cl._build_keyring_key(auth_url=AUTH_URL,
|
keyring_key = cl._build_keyring_key(auth_url=AUTH_URL,
|
||||||
username=USERNAME,
|
username=USERNAME,
|
||||||
@@ -118,9 +122,11 @@ class KeyringTest(utils.TestCase):
|
|||||||
(AUTH_URL, TENANT_ID, TENANT, TOKEN, USERNAME))
|
(AUTH_URL, TENANT_ID, TENANT, TOKEN, USERNAME))
|
||||||
|
|
||||||
def test_set_and_get_keyring_expired(self):
|
def test_set_and_get_keyring_expired(self):
|
||||||
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
|
# Creating a HTTPClient not using session is deprecated.
|
||||||
project_id=TENANT_ID, auth_url=AUTH_URL,
|
with self.deprecations.expect_deprecations_here():
|
||||||
use_keyring=True)
|
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
|
||||||
|
project_id=TENANT_ID, auth_url=AUTH_URL,
|
||||||
|
use_keyring=True)
|
||||||
|
|
||||||
# set an expired token into the keyring
|
# set an expired token into the keyring
|
||||||
auth_ref = access.AccessInfo.factory(body=PROJECT_SCOPED_TOKEN)
|
auth_ref = access.AccessInfo.factory(body=PROJECT_SCOPED_TOKEN)
|
||||||
@@ -146,9 +152,11 @@ class KeyringTest(utils.TestCase):
|
|||||||
PROJECT_SCOPED_TOKEN['access']['token']['expires'])
|
PROJECT_SCOPED_TOKEN['access']['token']['expires'])
|
||||||
|
|
||||||
def test_get_keyring(self):
|
def test_get_keyring(self):
|
||||||
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
|
# Creating a HTTPClient not using session is deprecated.
|
||||||
project_id=TENANT_ID, auth_url=AUTH_URL,
|
with self.deprecations.expect_deprecations_here():
|
||||||
use_keyring=True)
|
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
|
||||||
|
project_id=TENANT_ID, auth_url=AUTH_URL,
|
||||||
|
use_keyring=True)
|
||||||
|
|
||||||
# set an token into the keyring
|
# set an token into the keyring
|
||||||
auth_ref = access.AccessInfo.factory(body=PROJECT_SCOPED_TOKEN)
|
auth_ref = access.AccessInfo.factory(body=PROJECT_SCOPED_TOKEN)
|
||||||
@@ -162,9 +170,11 @@ class KeyringTest(utils.TestCase):
|
|||||||
self.assertTrue(self.memory_keyring.fetched)
|
self.assertTrue(self.memory_keyring.fetched)
|
||||||
|
|
||||||
def test_set_keyring(self):
|
def test_set_keyring(self):
|
||||||
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
|
# Creating a HTTPClient not using session is deprecated.
|
||||||
project_id=TENANT_ID, auth_url=AUTH_URL,
|
with self.deprecations.expect_deprecations_here():
|
||||||
use_keyring=True)
|
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
|
||||||
|
project_id=TENANT_ID, auth_url=AUTH_URL,
|
||||||
|
use_keyring=True)
|
||||||
|
|
||||||
# stub and check that a new token is received
|
# stub and check that a new token is received
|
||||||
method = 'get_raw_token_from_identity_service'
|
method = 'get_raw_token_from_identity_service'
|
||||||
|
Reference in New Issue
Block a user