Skip to content

Commit

Permalink
Alpha10 (#152)
Browse files Browse the repository at this point in the history
* Update docstring for  behavior

* Refactor how credentials are applied, fixes #151

* Bump version
  • Loading branch information
sserrata committed Apr 13, 2020
1 parent 49a207d commit 24056a7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# History

## 2.0.0-alpha10 (2020-04-09)

- Refactor how and where credentials are applied to request headers (#151)

## 2.0.0-alpha9 (2020-04-04)

- Now checking if static `access_token` exists before attempting a developer token refresh (#147)
Expand Down
2 changes: 1 addition & 1 deletion pan_cortex_data_lake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""Main package for cortex."""

__author__ = "Palo Alto Networks"
__version__ = "2.0.0-a9"
__version__ = "2.0.0-a10"

from .exceptions import ( # noqa: F401
CortexError,
Expand Down
13 changes: 3 additions & 10 deletions pan_cortex_data_lake/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, **kwargs):
granular performance and reliability tuning.
Parameters:
auto_refresh (bool): Perform token refresh following HTTP 401 response from server. Defaults to ``True``.
auto_refresh (bool): Perform token refresh prior to request if ``access_token`` is ``None`` or expired. Defaults to ``True``.
auto_retry (bool): Retry last failed HTTP request following a token refresh. Defaults to ``True``.
credentials (Credentials): :class:`~pan_cortex_data_lake.credentials.Credentials` object. Defaults to ``None``.
enforce_json (bool): Require properly-formatted JSON or raise :exc:`~pan_cortex_data_lake.exceptions.CortecError`. Defaults to ``False``.
Expand Down 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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.0.0a9
current_version = 2.0.0a10
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

setup(
name="pan-cortex-data-lake",
version="2.0.0-a9",
version="2.0.0-a10",
description="Python idiomatic SDK for Cortex™ Data Lake.",
long_description=readme + "\n\n" + history,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 24056a7

Please sign in to comment.