Skip to content

Commit

Permalink
Place _is_aad_token_valid() together with other internal functions
Browse files Browse the repository at this point in the history
  • Loading branch information
eskarimov committed Dec 5, 2021
1 parent 6234779 commit 9d08a12
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions airflow/providers/databricks/hooks/databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,20 @@ def _get_aad_headers(self) -> dict:
headers['X-Databricks-Azure-SP-Management-Token'] = mgmt_token
return headers

@staticmethod
def _is_aad_token_valid(aad_token: dict) -> bool:
"""
Utility function to check AAD token hasn't expired yet
:param aad_token: dict with properties of AAD token
:type aad_token: dict
:return: true if token is valid, false otherwise
:rtype: bool
"""
now = int(time.time())
if aad_token['expires_on'] > (now + TOKEN_REFRESH_LEAD_TIME):
return True
return False

@staticmethod
def _check_azure_metadata_service() -> None:
"""
Expand Down Expand Up @@ -520,20 +534,6 @@ def uninstall(self, json: dict) -> None:
"""
self._do_api_call(UNINSTALL_LIBS_ENDPOINT, json)

@staticmethod
def _is_aad_token_valid(aad_token: dict) -> bool:
"""
Utility function to check AAD token hasn't expired yet
:param aad_token: dict with properties of AAD token
:type aad_token: dict
:return: true if token is valid, false otherwise
:rtype: bool
"""
now = int(time.time())
if aad_token['expires_on'] > (now + TOKEN_REFRESH_LEAD_TIME):
return True
return False


def _retryable_error(exception) -> bool:
return (
Expand Down

0 comments on commit 9d08a12

Please sign in to comment.