Skip to content

Commit e115be7

Browse files
committed
Adds backwards compat for old style auth objects
1 parent c047089 commit e115be7

4 files changed

Lines changed: 59 additions & 4 deletions

File tree

SoftLayer/API.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
:license: MIT, see LICENSE for more details.
77
"""
88
import time
9+
import warnings
910

1011
from SoftLayer import auth as slauth
1112
from SoftLayer import config
@@ -183,7 +184,14 @@ def call(self, service, method, *args, **kwargs):
183184
}
184185

185186
if self.auth:
186-
options = self.auth.get_options(options)
187+
if getattr(self.auth, "get_headers", None):
188+
warnings.warn("auth.get_headers() is deprecation and will be "
189+
"removed in the next major version",
190+
DeprecationWarning)
191+
headers.update(self.auth.get_headers())
192+
193+
if getattr(self.auth, "get_options", None):
194+
options = self.auth.get_options(options)
187195

188196
return transports.make_xml_rpc_api_call(uri, method, args,
189197
**options)

SoftLayer/auth.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,22 @@
1010

1111
class AuthenticationBase(object):
1212
"""A base authentication class intended to be overridden."""
13+
1314
def get_options(self, options):
14-
"""Receives request options and returns request options."""
15-
raise NotImplementedError
15+
"""Receives request options and returns request options.
16+
17+
:param options dict: dictionary of request options
18+
19+
"""
20+
return options
21+
22+
def get_headers(self):
23+
"""Return a dictionary of headers to be inserted for authentication.
24+
25+
.. deprecated:: 3.3.0
26+
Use :func:`get_options` instead.
27+
"""
28+
return {}
1629

1730

1831
class TokenAuthentication(AuthenticationBase):

SoftLayer/tests/auth_tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
class TestAuthenticationBase(testing.TestCase):
1212
def test_get_options(self):
1313
auth_base = auth.AuthenticationBase()
14-
self.assertRaises(NotImplementedError, auth_base.get_options, {})
14+
self.assertEqual(auth_base.get_options({}), {})
15+
self.assertEqual(auth_base.get_headers(), {})
1516

1617

1718
class TestBasicAuthentication(testing.TestCase):
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
SoftLayer.tests.depecated_tests
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4+
5+
:license: MIT, see LICENSE for more details.
6+
"""
7+
import mock
8+
9+
import SoftLayer
10+
import SoftLayer.API
11+
from SoftLayer import testing
12+
13+
14+
class DeprecatedAuth(SoftLayer.AuthenticationBase):
15+
"""Auth that only implements get_headers()."""
16+
17+
def get_headers(self):
18+
return {'deprecated': 'header'}
19+
20+
21+
class APIClient(testing.TestCase):
22+
def set_up(self):
23+
self.client = SoftLayer.Client(auth=DeprecatedAuth())
24+
25+
@mock.patch('SoftLayer.transports.make_xml_rpc_api_call')
26+
def test_simple_call(self, make_xml_rpc_api_call):
27+
self.client['SERVICE'].METHOD()
28+
make_xml_rpc_api_call.assert_called_with(
29+
mock.ANY, mock.ANY, mock.ANY,
30+
headers={'deprecated': 'header'},
31+
proxy=mock.ANY,
32+
timeout=mock.ANY,
33+
http_headers=mock.ANY)

0 commit comments

Comments
 (0)