-
Notifications
You must be signed in to change notification settings - Fork 24
fix: properly set token_expiry_is_time_of_expiration and mask access token when logging #637
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
base: main
Are you sure you want to change the base?
Changes from all commits
0764b63
4e6b9f2
b1d5d05
bf1eaf2
10a27b1
ab062f8
b24db1b
503dac6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,10 +217,26 @@ def _make_handled_request(self) -> Any: | |
data=self.build_refresh_request_body(), | ||
headers=self.build_refresh_request_headers(), | ||
) | ||
# log the response even if the request failed for troubleshooting purposes | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: but wonder if there is a more straightforward way to write this logic. Something like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, are we sure it makes sense to ignore the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed this over zoom and came to a simpler implementation that we both liked |
||
if not response.ok: | ||
# log the response even if the request failed for troubleshooting purposes | ||
self._log_response(response) | ||
response.raise_for_status() | ||
|
||
response_json = response.json() | ||
|
||
try: | ||
# extract the access token and add to secrets to avoid logging the raw value | ||
access_key = self._extract_access_token(response_json) | ||
if access_key: | ||
add_to_secrets(access_key) | ||
except ResponseKeysMaxRecurtionReached as e: | ||
# could not find the access token in the response, so do nothing | ||
pass | ||
|
||
self._log_response(response) | ||
response.raise_for_status() | ||
return response.json() | ||
|
||
return response_json | ||
except requests.exceptions.RequestException as e: | ||
if e.response is not None: | ||
if e.response.status_code == 429 or e.response.status_code >= 500: | ||
|
@@ -240,9 +256,7 @@ def _ensure_access_token_in_response(self, response_data: Mapping[str, Any]) -> | |
|
||
This method attempts to extract the access token from the provided response data. | ||
If the access token is not found, it raises an exception indicating that the token | ||
refresh API response was missing the access token. If the access token is found, | ||
it adds the token to the list of secrets to ensure it is replaced before logging | ||
the response. | ||
refresh API response was missing the access token. | ||
|
||
Args: | ||
response_data (Mapping[str, Any]): The response data from which to extract the access token. | ||
|
@@ -257,9 +271,6 @@ def _ensure_access_token_in_response(self, response_data: Mapping[str, Any]) -> | |
raise Exception( | ||
f"Token refresh API response was missing access token {self.get_access_token_name()}" | ||
) | ||
# Add the access token to the list of secrets so it is replaced before logging the response | ||
# An argument could be made to remove the prevous access key from the list of secrets, but unmasking values seems like a security incident waiting to happen... | ||
add_to_secrets(access_key) | ||
except ResponseKeysMaxRecurtionReached as e: | ||
raise e | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.