Skip to content

Commit

Permalink
Merge pull request #125 from TicketSwap/124-user-and-password-are-req…
Browse files Browse the repository at this point in the history
…uired-even-with-sqlalchemy_url-configured

refactor: 🔥 remove sqlalchemy parameters
  • Loading branch information
tobiascadee authored Aug 27, 2024
2 parents 94ba8d5 + 9a0750a commit 360c379
Showing 1 changed file with 17 additions and 55 deletions.
72 changes: 17 additions & 55 deletions target_redshift/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,10 @@ def __init__(
parse_env_config=parse_env_config,
validate_config=validate_config,
)
# There's a few ways to do this in JSON Schema but it is schema draft dependent.
# https://stackoverflow.com/questions/38717933/jsonschema-attribute-conditionally-required # noqa: E501
assert (
(self.config.get("sqlalchemy_url") is not None)
or (
self.config.get("host") is not None
and self.config.get("port") is not None
and self.config.get("user") is not None
and self.config.get("password") is not None
)
or (
self.config.get("host") is not None
and self.config.get("port") is not None
and self.config.get("user") is not None
and self.config.get("enable_iam_authentication") is not None
and self.config.get("cluster_identifier") is not None
)
), ("Need either the sqlalchemy_url to be set or host, port, user," + "password, and dialect+driver to be set")

# If sqlalchemy_url is not being used and ssl_enable is on, ssl_mode must have
# one of six allowable values. If ssl_mode is verify-ca or verify-full, a
# certificate authority must be provided to verify against.
assert (
(self.config.get("sqlalchemy_url") is not None)
or (self.config.get("ssl_enable") is False)
or (self.config.get("ssl_mode") in {"disable", "allow", "prefer", "require"})
)

assert self.config.get("add_record_metadata") or not self.config.get("activate_version"), (
assert self.config.get("add_record_metadata") or not self.config.get(
"activate_version"
), (
"Activate version messages can't be processed unless add_record_metadata "
"is set to true. To ignore Activate version messages instead, Set the "
"`activate_version` configuration to False."
Expand All @@ -79,7 +54,9 @@ def __init__(
th.Property(
"host",
th.StringType,
description=("Hostname for redshift instance. Note if sqlalchemy_url is set this will be ignored."),
description=(
"Hostname for redshift instance. Note if sqlalchemy_url is set this will be ignored."
),
),
th.Property(
"port",
Expand Down Expand Up @@ -107,38 +84,22 @@ def __init__(
th.Property(
"user",
th.StringType,
description=("User name used to authenticate. Note if sqlalchemy_url is set this will be ignored."),
description=(
"User name used to authenticate. Note if sqlalchemy_url is set this will be ignored."
),
),
th.Property(
"password",
th.StringType,
description=("Password used to authenticate. Note if sqlalchemy_url is set this will be ignored."),
),
th.Property(
"dbname",
th.StringType,
description=("Database name. Note if sqlalchemy_url is set this will be ignored."),
),
th.Property(
"sqlalchemy_url",
th.StringType,
description=(
"SQLAlchemy connection string. "
+ "This will override using host, user, password, port, "
+ "dialect, and all ssl settings. Note that you must escape password "
+ "special characters properly. See "
+ "https://docs.sqlalchemy.org/en/20/core/engines.html#escaping-special-characters-such-as-signs-in-passwords"
"Password used to authenticate. Note if sqlalchemy_url is set this will be ignored."
),
),
th.Property(
"dialect+driver",
"dbname",
th.StringType,
default="redshift+redshift_connector",
description=(
"Dialect+driver see "
+ "https://aws.amazon.com/blogs/big-data/use-the-amazon-redshift-sqlalchemy-dialect-to-interact-with-amazon-redshift. "
+ "Generally just leave this alone. "
+ "Note if sqlalchemy_url is set this will be ignored."
"Database name. Note if sqlalchemy_url is set this will be ignored."
),
),
th.Property(
Expand Down Expand Up @@ -175,7 +136,10 @@ def __init__(
description="If you want to remove staging files in S3",
),
th.Property(
"temp_dir", th.StringType, default="temp", description="Where you want to store your temp data files."
"temp_dir",
th.StringType,
default="temp",
description="Where you want to store your temp data files.",
),
th.Property(
"default_target_schema",
Expand Down Expand Up @@ -222,18 +186,16 @@ def __init__(
+ " ssl_certificate_authority and ssl_mode for further customization."
+ " To use a client certificate to authenticate yourself to the server,"
+ " use ssl_client_certificate_enable instead."
+ " Note if sqlalchemy_url is set this will be ignored."
),
),
th.Property(
"ssl_mode",
th.StringType,
default="verify-full",
description=(
"SSL Protection method, see [postgres documentation](https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-PROTECTION)"
"SSL Protection method, see [redshift documentation](https://docs.aws.amazon.com/redshift/latest/mgmt/connecting-ssl-support.html"
+ " for more information. Must be one of disable, allow, prefer,"
+ " require, verify-ca, or verify-full."
+ " Note if sqlalchemy_url is set this will be ignored."
),
),
).to_dict()
Expand Down

0 comments on commit 360c379

Please sign in to comment.