Skip to content

Commit 6471245

Browse files
Implemented scrub_keys function (#85)
* Implemented scrub_keys function * bumped version
1 parent 546c839 commit 6471245

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

polyapi/poly_tables.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66
from polyapi.typedefs import TableSpecDto
77
from polyapi.constants import JSONSCHEMA_TO_PYTHON_TYPE_MAP
88

9+
def scrub(data) -> Dict[str, Any]:
10+
if (not data or not isinstance(data, (Dict, List))): return data
11+
if isinstance(data, List):
12+
return [scrub(item) for item in data]
13+
else:
14+
temp = {}
15+
secrets = ["x_api_key", "x-api-key", "access_token", "access-token", "authorization", "api_key", "api-key", "apikey", "accesstoken", "token", "password", "key"]
16+
for key, value in data.items():
17+
if isinstance(value, (Dict, List)):
18+
temp[key] = scrub(data[key])
19+
elif key.lower() in secrets:
20+
temp[key] = '********'
21+
else:
22+
temp[key] = data[key]
23+
return temp
924

1025
def scrub_keys(e: Exception) -> Dict[str, Any]:
1126
"""
@@ -16,7 +31,7 @@ def scrub_keys(e: Exception) -> Dict[str, Any]:
1631
"error": str(e),
1732
"type": type(e).__name__,
1833
"message": str(e),
19-
"args": getattr(e, 'args', None)
34+
"args": scrub(getattr(e, 'args', None))
2035
}
2136

2237

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"]
33

44
[project]
55
name = "polyapi-python"
6-
version = "0.3.10.dev4"
6+
version = "0.3.10.dev5"
77
description = "The Python Client for PolyAPI, the IPaaS by Developers for Developers"
88
authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }]
99
dependencies = [

0 commit comments

Comments
 (0)