-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
22 lines (18 loc) · 784 Bytes
/
utils.py
File metadata and controls
22 lines (18 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class UnstractUtils:
@staticmethod
def redact_key(api_key: str, reveal_length=4) -> str:
"""Hides sensitive information partially. Useful for logging keys.
Args:
api_key (str): API key to redact
reveal_length (int): Number of characters to reveal from the start
Returns:
str: Redacted API key
"""
if not isinstance(api_key, str):
raise ValueError("API key must be a string")
if reveal_length < 0:
raise ValueError("Reveal length must be a non-negative integer")
redacted_length = max(len(api_key) - reveal_length, 0)
revealed_part = api_key[:reveal_length]
redacted_part = "x" * redacted_length
return revealed_part + redacted_part