Skip to content

Commit

Permalink
Don't log AIMS tokens (#84)
Browse files Browse the repository at this point in the history
* Missing space in log message
* Debug logs: -aims tokens, +user ID
  • Loading branch information
sayler authored Oct 2, 2020
1 parent 71298fa commit 1f3a088
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion almdrlib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def __init__(self,

def load_service_spec(self, service_name, version=None, variables=None):
logger.debug(
f"Initializing client for '{self._name}'" +
f"Initializing client for '{self._name}' " +
f"Spec: '{service_name}' Variables: '{variables}'")
spec = alsdkdefs.load_service_spec(service_name, Config.get_api_dir(), version)
self.load_spec(spec, variables)
Expand Down
9 changes: 8 additions & 1 deletion almdrlib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def _authenticate(self):
auth_info = response.json()
account_info = auth_info["authentication"]["account"]
self._token = auth_info["authentication"]["token"]
logger.info(f'Authenticated user {auth_info["authentication"]["user"]["id"]}')

except requests.exceptions.HTTPError as e:
raise AuthenticationException(f"invalid http response {e}")
Expand Down Expand Up @@ -281,13 +282,19 @@ def request(
if self._token is None:
self._authenticate()

headers.update({'x-aims-auth-token': self._token})
# it's too easy to include the AIMS token when pasting debug logs, so redact it in
# the logging statement.
headers.update({'x-aims-auth-token': "REDACTED"})

logger.debug(f"Calling '{method}' method. " +
f"URL: '{url}'. " +
f"Params: '{params}' " +
f"Headers: '{headers}' " +
f"Cookies: '{cookies}' " +
f"Args: '{kwargs}'")

headers.update({'x-aims-auth-token': self._token})

response = self._session.request(
method, url,
params=params,
Expand Down

0 comments on commit 1f3a088

Please sign in to comment.