Skip to content

Commit 34e415d

Browse files
committed
Sync with master
2 parents 2641a9a + 0adf4dd commit 34e415d

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

HISTORY.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
Release History
44
===============
55

6+
0.0.37 (2018-11-02)
7+
+++++++++++++++++++
8+
* Reverted some changes introduced in 0.0.35 that didn't work with other tokens
9+
10+
0.0.36 (2018-10-31)
11+
+++++++++++++++++++
12+
* Fixed typo in refresh_token call
13+
614
0.0.35 (2018-10-29)
715
+++++++++++++++++++
816
* Added retry for getting tokens

azure/datalake/store/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
# license information.
77
# --------------------------------------------------------------------------
88

9-
__version__ = "0.0.35"
9+
__version__ = "0.0.37"
10+
1011

1112

1213
from .core import AzureDLFileSystem

azure/datalake/store/lib.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ def get_token_internal():
155155

156156
return DataLakeCredential(out)
157157

158+
158159
class DataLakeCredential:
160+
# Be careful modifying this. DataLakeCredential is a general class in azure, and we have to maintain parity.
159161
def __init__(self, token):
160162
self.token = token
161163

@@ -191,21 +193,15 @@ def refresh_token(self, authority=None, retry_policy=None):
191193
context = adal.AuthenticationContext(authority +
192194
self.token['tenant'])
193195

194-
@retry_decorator_for_auth(retry_policy=retry_policy)
195-
def get_token_internal():
196-
# Internal function used so as to use retry decorator
197-
if self.token.get('secret') and self.token.get('client'):
198-
out = context.acquire_token_with_client_credentials(self.token['resource'],
199-
self.token['client'],
200-
self.token['secret'])
201-
out.update({'secret': self.token['secret']})
202-
else:
203-
out = context.acquire_token_with_refresh_token(self.token['refresh'],
204-
client_id=self.token['client'],
205-
resource=self.token['resource'])
206-
return out
207-
208-
out = get_token_internal()
196+
if self.token.get('secret') and self.token.get('client'):
197+
out = context.acquire_token_with_client_credentials(self.token['resource'],
198+
self.token['client'],
199+
self.token['secret'])
200+
out.update({'secret': self.token['secret']})
201+
else:
202+
out = context.acquire_token_with_refresh_token(self.token['refresh'],
203+
client_id=self.token['client'],
204+
resource=self.token['resource'])
209205
# common items to update
210206
out.update({'access': out['accessToken'],
211207
'time': time.time(), 'tenant': self.token['tenant'],
@@ -271,7 +267,9 @@ def __init__(self, store_name=default_store, token=None,
271267
# There is a case where the user can opt to exclude an API version, in which case
272268
# the service itself decides on the API version to use (it's default).
273269
self.api_version = api_version or None
274-
self.head = {'Authorization': token.signed_session(retry_policy=None).headers['Authorization']}
270+
self.head = None
271+
self._check_token() # Retryable method. Will ensure that signed_session token is current when we set it on next line
272+
self.head = {'Authorization': token.signed_session().headers['Authorization']}
275273
self.url = 'https://%s.%s/' % (store_name, url_suffix)
276274
self.webhdfs = 'webhdfs/v1/'
277275
self.extended_operations = 'webhdfsext/'
@@ -296,11 +294,15 @@ def session(self):
296294
self.local.session = s
297295
return s
298296

299-
def _check_token(self, retry_policy=None):
300-
cur_session = self.token.signed_session(retry_policy=retry_policy)
301-
if not self.head or self.head.get('Authorization') != cur_session.headers['Authorization']:
302-
self.head = {'Authorization': cur_session.headers['Authorization']}
303-
self.local.session = None
297+
298+
def _check_token(self, retry_policy= None):
299+
@retry_decorator_for_auth(retry_policy=retry_policy)
300+
def check_token_internal():
301+
cur_session = self.token.signed_session()
302+
if not self.head or self.head.get('Authorization') != cur_session.headers['Authorization']:
303+
self.head = {'Authorization': cur_session.headers['Authorization']}
304+
self.local.session = None
305+
check_token_internal()
304306

305307
def _log_request(self, method, url, op, path, params, headers, retry_count):
306308
msg = "HTTP Request\n{} {}\n".format(method.upper(), url)

azure/datalake/store/retry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ def deco_retry(func):
8686
@wraps(func)
8787
def f_retry(*args, **kwargs):
8888
retry_count = -1
89-
last_exception = None
90-
out = None
89+
9190
while True:
91+
last_exception = None
9292
retry_count += 1
9393
try:
9494
out = func(*args, **kwargs)
@@ -105,7 +105,7 @@ def f_retry(*args, **kwargs):
105105
request_successful = last_exception is None or response.status_code == 401 # 401 = Invalid credentials
106106
if request_successful or not retry_policy.should_retry(response, last_exception, retry_count):
107107
break
108-
if out is None:
108+
if last_exception is not None:
109109
raise last_exception
110110
return out
111111

0 commit comments

Comments
 (0)