Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 4d43d79

Browse files
committed
Prints configuration during debug, but with passwords redacted, including in URLs
1 parent c9ab57f commit 4d43d79

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

data_diff/__main__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import logging
66
from itertools import islice
77

8+
from .utils import remove_password_from_url
9+
810
from .diff_tables import (
911
TableSegment,
1012
TableDiffer,
@@ -33,6 +35,8 @@ def _remove_passwords_in_dict(d: dict):
3335
d[k] = "*" * len(v)
3436
elif isinstance(v, dict):
3537
_remove_passwords_in_dict(v)
38+
elif k.startswith("database"):
39+
d[k] = remove_password_from_url(v)
3640

3741

3842
@click.command()
@@ -120,11 +124,10 @@ def _main(
120124

121125
if debug:
122126
logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT, datefmt=DATE_FORMAT)
123-
# XXX Temporarily commented out, until we remove the passwords from URIs as well. See issue #150.
124-
# if __conf__:
125-
# __conf__ = deepcopy(__conf__)
126-
# _remove_passwords_in_dict(__conf__)
127-
# logging.debug(f"Applied run configuration: {__conf__}")
127+
if __conf__:
128+
__conf__ = deepcopy(__conf__)
129+
_remove_passwords_in_dict(__conf__)
130+
logging.debug(f"Applied run configuration: {__conf__}")
128131
elif verbose:
129132
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT, datefmt=DATE_FORMAT)
130133

data_diff/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import math
2+
from urllib.parse import urlparse
23

3-
from typing import Sequence, Optional, Tuple, Union, Dict, Any
4+
from typing import Union
45
from uuid import UUID
56

67

@@ -51,3 +52,9 @@ def number_to_human(n):
5152
)
5253

5354
return "{:.0f}{}".format(n / 10 ** (3 * millidx), millnames[millidx])
55+
56+
57+
def remove_password_from_url(url, replace_with="***"):
58+
parsed = urlparse(url)
59+
replaced = parsed._replace(netloc="{}:{}@{}".format(parsed.username, replace_with, parsed.hostname or ""))
60+
return replaced.geturl()

0 commit comments

Comments
 (0)