Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpha10 #152

Merged
merged 3 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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