-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: sanitize username password mongodb
- Loading branch information
Showing
3 changed files
with
26 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from urllib.parse import unquote, urlparse | ||
|
||
|
||
def _extract_username_password(url: str) -> tuple[str, str, str]: | ||
url_components = urlparse(url) | ||
username, password = url_components.username, url_components.password | ||
if username and password: | ||
url_components = url_components._replace( | ||
netloc=url_components.hostname, | ||
) | ||
|
||
return username, unquote(password), url_components.geturl() | ||
|
||
|
||
def sanitize_client_opts(client_opts): | ||
# Sanitize client options. | ||
if "host" in client_opts: | ||
username, password, host = _extract_username_password(client_opts["host"]) | ||
client_opts["username"] = username | ||
client_opts["password"] = password | ||
client_opts["host"] = host | ||
return client_opts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters