Skip to content

Commit

Permalink
censor GitHub token
Browse files Browse the repository at this point in the history
  • Loading branch information
mxmehl committed Jul 12, 2024
1 parent 2a368c3 commit d65dea9
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 @@ -59,6 +59,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 d65dea9

Please sign in to comment.