-
Notifications
You must be signed in to change notification settings - Fork 90
URL encode username and password values for DB connections #7486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| from typing import Dict, Union | ||
| from urllib.parse import quote_plus | ||
| from urllib.parse import quote | ||
|
|
||
| from loguru import logger | ||
| from sqlalchemy import text | ||
|
|
@@ -22,25 +22,32 @@ class RedshiftConnector(SQLConnector): | |
| secrets_schema = RedshiftSchema | ||
|
|
||
| def build_ssh_uri(self, local_address: tuple) -> str: | ||
| """Build SSH URI of format redshift+psycopg2://[user[:password]@][ssh_host][:ssh_port][/dbname]""" | ||
| """Build SSH URI of format redshift+psycopg2://[user[:password]@][ssh_host][:ssh_port][/dbname]. | ||
| Username and password are URL-encoded so that reserved characters (e.g. @, :) do not | ||
| break URI parsing.""" | ||
| local_host, local_port = local_address | ||
|
|
||
| config = self.secrets_schema(**self.configuration.secrets or {}) | ||
|
|
||
| port = f":{local_port}" if local_port else "" | ||
| database = f"/{config.database}" if config.database else "" | ||
| url = f"redshift+psycopg2://{config.user}:{config.password}@{local_host}{port}{database}" | ||
| user = quote(str(config.user), safe="") | ||
| password = quote(str(config.password), safe="") | ||
| url = f"redshift+psycopg2://{user}:{password}@{local_host}{port}{database}" | ||
| return url | ||
|
|
||
| # Overrides BaseConnector.build_uri | ||
| def build_uri(self) -> str: | ||
| """Build URI of format redshift+psycopg2://user:password@[host][:port][/database]""" | ||
| """Build URI of format redshift+psycopg2://user:password@[host][:port][/database]. | ||
| Username and password are URL-encoded so that reserved characters (e.g. @, :) do not | ||
| break URI parsing.""" | ||
| config = self.secrets_schema(**self.configuration.secrets or {}) | ||
|
|
||
| url_encoded_password = quote_plus(config.password) | ||
| user = quote(str(config.user), safe="") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed this changed from Not raising this as a change request, just something to keep in mind in case we see any related behavior changes down the line |
||
| password = quote(str(config.password), safe="") | ||
| port = f":{config.port}" if config.port else "" | ||
| database = f"/{config.database}" if config.database else "" | ||
| url = f"redshift+psycopg2://{config.user}:{url_encoded_password}@{config.host}{port}{database}" | ||
| url = f"redshift+psycopg2://{user}:{password}@{config.host}{port}{database}" | ||
| return url | ||
|
|
||
| # Overrides SQLConnector.create_client | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about adding a check to ensure the credential exists before applying
str?If
config.passwordisNone,str(None)converts this to the literal string "None", resulting in URLs like:redshift+psycopg2://user:None@...This differs from the MySQL/Postgres implementation, which conditionally includes credentials only when they exist