-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_utils.py
More file actions
56 lines (44 loc) · 1.35 KB
/
Copy pathapi_utils.py
File metadata and controls
56 lines (44 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
Helper module for validating API keys and checking if they are placeholders
"""
def is_valid_api_key(key: str) -> bool:
"""
Check if an API key is valid (not None, not empty, not a placeholder)
Args:
key: The API key to validate
Returns:
bool: True if the key appears to be valid, False otherwise
"""
if not key:
return False
key_upper = key.upper()
# Check for common placeholder patterns
placeholder_patterns = [
"YOUR_",
"PLACEHOLDER",
"REPLACE",
"INSERT",
"ADD_YOUR",
"ENTER_YOUR",
"PUT_YOUR",
"_HERE",
"XXXX",
"****"
]
for pattern in placeholder_patterns:
if pattern in key_upper:
return False
# Check if key is too short (most API keys are at least 20 characters)
if len(key.strip()) < 10:
return False
return True
def should_suppress_error(status_code: int) -> bool:
"""
Determine if an HTTP error should be suppressed (not shown to user)
Args:
status_code: HTTP status code
Returns:
bool: True if error should be suppressed, False otherwise
"""
# Suppress authentication/authorization errors (expected when API key is invalid/missing)
return status_code in [400, 401, 403, 404]