Skip to content

Commit

Permalink
Merge pull request #30 from OpenRailAssociation/censor-gh-token
Browse files Browse the repository at this point in the history
Censor GitHub token from debug output
  • Loading branch information
mxmehl authored Jul 12, 2024
2 parents 37f6278 + d65dea9 commit 7b96838
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gh_org_mgr/_gh_org.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ def df2json(self) -> str:
"""Convert the dataclass to a JSON string"""
d = asdict(self)

# Censor sensible fields
def censor_half_string(string: str) -> str:
"""Censor 50% of a string (rounded up)"""
half1 = int(len(string) / 2)
half2 = len(string) - half1
return string[:half1] + "*" * (half2)

sensible_keys = ["gh_token"]
for key in sensible_keys:
d[key] = censor_half_string(d.get(key, ""))

# Print dict nicely
def pretty(d, indent=0):
string = ""
for key, value in d.items():
Expand Down

0 comments on commit 7b96838

Please sign in to comment.