MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeWiki / mask_api_key

Function mask_api_key

codewiki/cli/utils/validation.py:232–250  ·  view source on GitHub ↗

Mask API key for display, showing only first and last few characters. Args: api_key: API key to mask visible_chars: Number of visible characters at start and end Returns: Masked API key (e.g., "sk-1234...5678")

(api_key: str, visible_chars: int = 4)

Source from the content-addressed store, hash-verified

230
231
232def mask_api_key(api_key: str, visible_chars: int = 4) -> str:
233 """
234 Mask API key for display, showing only first and last few characters.
235
236 Args:
237 api_key: API key to mask
238 visible_chars: Number of visible characters at start and end
239
240 Returns:
241 Masked API key (e.g., "sk-1234...5678")
242 """
243 if not api_key:
244 return "Not set"
245
246 if len(api_key) <= visible_chars * 2:
247 # Key too short, mask everything except edges
248 return f"{api_key[:2]}...{api_key[-2:]}"
249
250 return f"{api_key[:visible_chars]}...{api_key[-visible_chars:]}"
251

Callers 1

config_showFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected