Skip to content

Commit

Permalink
Refactor how credentials are applied, fixes PaloAltoNetworks#151
Browse files Browse the repository at this point in the history
  • Loading branch information
sserrata committed Apr 9, 2020
1 parent 0a7385d commit 60703fa
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions pan_cortex_data_lake/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@ def __init__(self, **kwargs):
if len(kwargs) > 0: # Handle invalid kwargs
raise UnexpectedKwargsError(kwargs)

if self.credentials:
logger.debug("Applying session-level credentials")
self._apply_credentials(
auto_refresh=self.auto_refresh,
credentials=self.credentials,
headers=self.session.headers,
)
self.stats = ApiStats({"transactions": 0})

def __repr__(self):
Expand Down Expand Up @@ -139,7 +132,7 @@ def _apply_credentials(auto_refresh=True, credentials=None, headers=None):
if token is None:
token = credentials.refresh(access_token=None, timeout=10)
logger.debug("Token refreshed due to 'None' condition")
elif credentials.jwt_is_expired():
elif credentials.jwt_is_expired(token):
token = credentials.refresh(timeout=10)
logger.debug("Token refreshed due to 'expired' condition")
headers.update({"Authorization": "Bearer {}".format(token)})
Expand Down Expand Up @@ -220,7 +213,7 @@ def request(self, **kwargs):

# Non-Requests key-word arguments
auto_refresh = kwargs.pop("auto_refresh", self.auto_refresh)
credentials = kwargs.pop("credentials", None)
credentials = kwargs.pop("credentials", self.credentials)
endpoint = kwargs.pop("endpoint", "") # default to empty endpoint
enforce_json = kwargs.pop("enforce_json", self.enforce_json)
raise_for_status = kwargs.pop("raise_for_status", self.raise_for_status)
Expand Down

0 comments on commit 60703fa

Please sign in to comment.