Skip to content

redact API keys from TTY output #9

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 11 additions & 4 deletions src/planet_auth_utils/commands/cli/jwt_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,26 @@ def __init__(self, data):
self._data = data

def __json_pretty_dumps__(self):
def _human_timestamp_iso(d):
def _human_readable_jwt_claim(d):
for key, value in list(d.items()):
if key in ["iat", "exp", "nbf"] and isinstance(value, int):
# UNIX Timestamps in ISO format, with annotations.
fmt_time = time.strftime("%Y-%m-%dT%H:%M:%S%z", time.localtime(value))
if (key == "exp") and (d[key] < time.time()):
now = time.time()
if (key == "exp") and (d[key] < now):
fmt_time += " (Expired)"
if (key == "nbf") and (d[key] > now):
fmt_time += " (Future)"
d[key] = fmt_time
elif key in ["api_key"]:
# Redact sensitive values
d[key] = "REDACTED"
elif isinstance(value, dict):
_human_timestamp_iso(value)
_human_readable_jwt_claim(value)
return d

json_dumps = self._data.copy()
_human_timestamp_iso(json_dumps)
_human_readable_jwt_claim(json_dumps)
return json_dumps


Expand Down