Skip to content

Commit 5431276

Browse files
committed
fix(connection): require cluster_identifier when IAM is enabled
1 parent 9d488fe commit 5431276

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

redshift_connector/iam_helper.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ def set_iam_properties(
105105
"AWS credentials, or AWS profile"
106106
)
107107
elif info.iam is True:
108+
if cluster_identifier is None:
109+
raise InterfaceError(
110+
"Invalid connection property setting. cluster_identifier must be provided when IAM is enabled"
111+
)
108112
if not any((credentials_provider, access_key_id, secret_access_key, session_token, profile)):
109113
raise InterfaceError(
110114
"Invalid connection property setting. Credentials provider, AWS credentials, or AWS profile must be"
@@ -153,16 +157,10 @@ def set_iam_properties(
153157
"session_token is provided"
154158
)
155159

156-
if user is None:
157-
raise InterfaceError("Invalid connection property setting. user must be specified")
158-
if host is None:
159-
raise InterfaceError("Invalid connection property setting. host must be specified")
160-
if database is None:
161-
raise InterfaceError("Invalid connection property setting. database must be specified")
162-
if port is None:
163-
raise InterfaceError("Invalid connection property setting. port must be specified")
164-
if password is None:
165-
raise InterfaceError("Invalid connection property setting. password must be specified")
160+
if not all((user, host, database, port, password)):
161+
raise InterfaceError(
162+
"Invalid connection property setting. " "user, password, host, database, port, and password are required."
163+
)
166164

167165
if client_protocol_version not in ClientProtocolVersion.list():
168166
raise InterfaceError(

test/unit/test_iam_helper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_set_iam_properties_fails_when_info_is_none(missing_param):
100100
keywords: typing.Dict = {missing_param: None}
101101
with pytest.raises(InterfaceError) as excinfo:
102102
set_iam_properties(**get_set_iam_properties_args(**keywords))
103-
assert "Invalid connection property setting. {} must be specified".format(missing_param) in str(excinfo.value)
103+
assert "Invalid connection property setting" in str(excinfo.value)
104104

105105

106106
ssl_mode_descriptions: typing.List[typing.Tuple[typing.Optional[str], str]] = [
@@ -291,6 +291,7 @@ def test_set_iam_properties_via_aws_credentials(mocker, test_input):
291291
info_obj: typing.Dict[str, typing.Any] = get_set_iam_properties_args(**test_input)
292292
info_obj["ssl"] = True
293293
info_obj["iam"] = True
294+
info_obj["cluster_identifier"] = "blah"
294295

295296
mocker.patch("redshift_connector.iam_helper.set_iam_credentials", return_value=None)
296297
set_iam_properties(**info_obj)

0 commit comments

Comments
 (0)