Repository navigation
redact developer API key from request URL logs #2838
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
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 |
|---|---|---|
|
|
@@ -62,7 +62,11 @@ | |
|
|
||
| # Local imports | ||
| from googleapiclient import _auth, mimeparse | ||
| from googleapiclient._helpers import _add_query_parameter, positional | ||
| from googleapiclient._helpers import ( | ||
| _add_query_parameter, | ||
| _redact_sensitive_url, | ||
| positional, | ||
| ) | ||
| from googleapiclient.errors import ( | ||
| HttpError, | ||
| InvalidJsonError, | ||
|
|
@@ -432,7 +436,7 @@ def _retrieve_discovery_doc( | |
| actual_url = _add_query_parameter(url, "userIp", os.environ["REMOTE_ADDR"]) | ||
| if developerKey: | ||
| actual_url = _add_query_parameter(url, "key", developerKey) | ||
| logger.debug("URL being requested: GET %s", actual_url) | ||
| logger.debug("URL being requested: GET %s", _redact_sensitive_url(actual_url)) | ||
|
|
||
| # Execute this request with retries build into HttpRequest | ||
| # Note that it will already raise an error if we don't get a 2xx response | ||
|
|
@@ -1263,7 +1267,9 @@ def method(self, **kwargs): | |
| ) % multipart_boundary | ||
| url = _add_query_parameter(url, "uploadType", "multipart") | ||
|
|
||
| logger.debug("URL being requested: %s %s" % (httpMethod, url)) | ||
| logger.debug( | ||
| "URL being requested: %s %s" % (httpMethod, _redact_sensitive_url(url)) | ||
| ) | ||
|
Comment on lines
+1270
to
+1272
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. Calling if logger.isEnabledFor(logging.DEBUG):
logger.debug(f"URL being requested: {httpMethod} {_redact_sensitive_url(url)}")References
|
||
| return self._requestBuilder( | ||
| self._http, | ||
| model.response, | ||
|
|
@@ -1383,7 +1389,10 @@ def methodNext(self, previous_request, previous_response): | |
| request.uri = _add_query_parameter( | ||
| request.uri, pageTokenName, nextPageToken | ||
| ) | ||
| logger.debug("Next page request URL: %s %s" % (methodName, request.uri)) | ||
| logger.debug( | ||
| "Next page request URL: %s %s" | ||
| % (methodName, _redact_sensitive_url(request.uri)) | ||
| ) | ||
|
Comment on lines
+1392
to
+1395
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. Calling if logger.isEnabledFor(logging.DEBUG):
logger.debug(f"Next page request URL: {methodName} {_redact_sensitive_url(request.uri)}")References
|
||
| else: | ||
| # Replace pageToken value in request body | ||
| model = self._model | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling
_redact_sensitive_urland performing string interpolation on every discovery document retrieval even whenDEBUGlogging is disabled introduces unnecessary CPU overhead. Wrapping the log statement in anif logger.isEnabledFor(logging.DEBUG):block avoids this overhead entirely. Additionally, per the general rules, we should prefer using f-strings for string interpolation.References